Class: PhlexKit::Item

Inherits:
BaseComponent show all
Defined in:
app/components/phlex_kit/item/item.rb

Overview

List row, ported from shadcn/ui's Item: a flex row of ItemMedia + ItemContent(ItemTitle + ItemDescription) + ItemActions, optionally grouped in an ItemGroup (with ItemSeparator) or stacked under an ItemHeader. variant :outline draws a bordered card row; size: tightens (:sm/:xs); href: renders an (their asChild link item — hover fills apply). .pk-item* (item.css).

Constant Summary collapse

VARIANTS =
{ default: nil, outline: "outline", muted: "muted" }.freeze
SIZES =
{ md: nil, sm: "sm", xs: "xs" }.freeze

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(variant: :default, size: :md, href: nil, **attrs) ⇒ Item

Returns a new instance of Item.



12
13
14
15
16
17
# File 'app/components/phlex_kit/item/item.rb', line 12

def initialize(variant: :default, size: :md, href: nil, **attrs)
  @variant = variant.to_sym
  @size = size.to_sym
  @href = href
  @attrs = attrs
end

Instance Method Details

#view_templateObject



19
20
21
22
23
24
25
26
# File 'app/components/phlex_kit/item/item.rb', line 19

def view_template(&)
  classes = [ "pk-item", fetch_option(VARIANTS, @variant, :variant), fetch_option(SIZES, @size, :size) ].compact.join(" ")
  if @href
    a(**mix({ class: classes, href: @href }, @attrs), &)
  else
    div(**mix({ class: classes }, @attrs), &)
  end
end