Class: Shadcn::InputGroup::Button::Component
- Inherits:
-
Button::Component
- Object
- ViewComponent::Base
- ApplicationViewComponent
- Button::Component
- Shadcn::InputGroup::Button::Component
- Defined in:
- app/components/shadcn/input_group/button/component.rb
Overview
InputGroupButton renders a Button with its own size scale layered on top, and forces three of the button's props.
Those three are defaults, not overrides: they go through super, so
a caller asking for variant: :destructive still gets it. Ranking them
above the caller would make the button un-restylable.
Direct Known Subclasses
Constant Summary collapse
- SIZES =
{ xs: "h-6 gap-1 rounded-[calc(var(--radius)-5px)] px-2 has-[>svg]:px-2 " \ "[&>svg:not([class*='size-'])]:size-3.5", sm: "h-8 gap-1.5 rounded-md px-2.5 has-[>svg]:px-2.5", "icon-xs": "size-6 rounded-[calc(var(--radius)-5px)] p-0 has-[>svg]:p-0", "icon-sm": "size-8 p-0 has-[>svg]:p-0" }.freeze
Constants inherited from ApplicationViewComponent
ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS
Instance Attribute Summary collapse
-
#group_size ⇒ Object
readonly
Returns the value of attribute group_size.
Attributes inherited from Button::Component
Attributes inherited from ApplicationViewComponent
Instance Method Summary collapse
- #css_classes(extra = nil) ⇒ Object
- #element_attributes(**defaults) ⇒ Object
-
#initialize(variant: :ghost, size: :xs, **attributes) ⇒ Component
constructor
A new instance of Component.
Methods inherited from Button::Component
#style_variants, variant_classes
Methods inherited from ApplicationViewComponent
#call, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name
Constructor Details
#initialize(variant: :ghost, size: :xs, **attributes) ⇒ Component
Returns a new instance of Component.
23 24 25 26 27 28 |
# File 'app/components/shadcn/input_group/button/component.rb', line 23 def initialize(variant: :ghost, size: :xs, **attributes) @group_size = size&.to_sym || :xs # The button's own size scale is not this one, so it keeps its # default; the group's scale is applied as classes instead. super(variant:, **attributes) end |
Instance Attribute Details
#group_size ⇒ Object (readonly)
Returns the value of attribute group_size.
21 22 23 |
# File 'app/components/shadcn/input_group/button/component.rb', line 21 def group_size @group_size end |
Instance Method Details
#css_classes(extra = nil) ⇒ Object
34 35 36 |
# File 'app/components/shadcn/input_group/button/component.rb', line 34 def css_classes(extra = nil) super([ SIZES.fetch(group_size), extra ].compact.join(" ")) end |
#element_attributes(**defaults) ⇒ Object
30 31 32 |
# File 'app/components/shadcn/input_group/button/component.rb', line 30 def element_attributes(**defaults) super(**{ type: "button", "data-size" => group_size }.merge(defaults)) end |