Class: Shadcn::ItemComponent

Inherits:
BaseComponent show all
Defined in:
app/components/shadcn/item_component.rb

Overview

Item component - a flexible flex container for titles, descriptions, and actions Matches shadcn/ui Item component

Examples:

Basic item

<%= render Shadcn::ItemComponent.new do |item| %>
  <% item.with_media(variant: :icon) do %>
    <svg>...</svg>
  <% end %>
  <% item.with_content do |content| %>
    <% content.with_title { "Item Title" } %>
    <% content.with_description { "Item description" } %>
  <% end %>
  <% item.with_actions do %>
    <%= render Shadcn::ButtonComponent.new(size: :sm) { "Action" } %>
  <% end %>
<% end %>

With variants

<%= render Shadcn::ItemComponent.new(variant: :outline) do |item| %>
  ...
<% end %>

Constant Summary collapse

VARIANTS =
{
  default: "bg-transparent",
  outline: "border border-border rounded-lg",
  muted: "bg-muted/50 rounded-lg"
}.freeze
SIZES =
{
  default: "p-4 gap-4",
  sm: "p-3 gap-3"
}.freeze
BASE_CLASSES =
"flex items-start"

Instance Attribute Summary

Attributes inherited from BaseComponent

#class_name, #data, #html_options

Instance Method Summary collapse

Methods inherited from BaseComponent

#content

Methods included from Rails::Helpers::ClassNameHelper

#cn

Constructor Details

#initialize(variant: :default, size: :default, tag: :div, href: nil, **options) ⇒ ItemComponent

Returns a new instance of ItemComponent.

Parameters:

  • variant (Symbol) (defaults to: :default)

    :default, :outline, or :muted

  • size (Symbol) (defaults to: :default)

    :default or :sm

  • tag (Symbol) (defaults to: :div)

    HTML tag to use (:div, :li, :a, etc.)

  • href (String) (defaults to: nil)

    URL for link items (uses :a tag automatically)



72
73
74
75
76
77
78
# File 'app/components/shadcn/item_component.rb', line 72

def initialize(variant: :default, size: :default, tag: :div, href: nil, **options)
  super(**options)
  @variant = variant.to_sym
  @size = size.to_sym
  @tag = href ? :a : tag
  @href = href
end

Instance Method Details

#callObject



80
81
82
# File 'app/components/shadcn/item_component.rb', line 80

def call
  (@tag, item_content, **item_attributes)
end