Class: Shadcn::Item::Component

Inherits:
ApplicationViewComponent show all
Defined in:
app/components/shadcn/item/component.rb

Overview

Port of registry/new-york-v4/ui/item.tsx

group/item is half a mechanism: ItemMedia's group-has-[[data-slot=item-description]]/item:… classes reach back into this named group to shift the media when a description is present. Both halves have to stay exactly as upstream wrote them — parity checks that each class exists, not that they still refer to each other.

Constant Summary

Constants inherited from ApplicationViewComponent

ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS

Instance Attribute Summary collapse

Attributes inherited from ApplicationViewComponent

#attributes

Instance Method Summary collapse

Methods inherited from ApplicationViewComponent

#call, #css_classes, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #tag_name

Constructor Details

#initialize(variant: :default, size: :default, **attributes) ⇒ Component

Returns a new instance of Component.



41
42
43
44
45
# File 'app/components/shadcn/item/component.rb', line 41

def initialize(variant: :default, size: :default, **attributes)
  @variant = variant&.to_sym || :default
  @size = size&.to_sym || :default
  super(**attributes)
end

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.



39
40
41
# File 'app/components/shadcn/item/component.rb', line 39

def size
  @size
end

#variantObject (readonly)

Returns the value of attribute variant.



39
40
41
# File 'app/components/shadcn/item/component.rb', line 39

def variant
  @variant
end

Instance Method Details

#element_attributes(**defaults) ⇒ Object



51
52
53
# File 'app/components/shadcn/item/component.rb', line 51

def element_attributes(**defaults)
  super(**{ "data-variant" => variant, "data-size" => size }.merge(defaults))
end

#style_variantsObject



47
48
49
# File 'app/components/shadcn/item/component.rb', line 47

def style_variants
  { variant:, size: }
end