Class: Shadcn::ToggleGroup::Item::Component
- Inherits:
-
ApplicationViewComponent
- Object
- ViewComponent::Base
- ApplicationViewComponent
- Shadcn::ToggleGroup::Item::Component
- Defined in:
- app/components/shadcn/toggle_group/item/component.rb
Overview
ToggleGroupItem — styled with the toggle's own variants, like the TSX
does via toggleVariants({ variant, size }).
Constant Summary collapse
- EXTRA_CLASSES =
"w-auto min-w-0 shrink-0 px-3 focus:z-10 focus-visible:z-10 " \ "data-[spacing=0]:rounded-none data-[spacing=0]:shadow-none " \ "data-[spacing=0]:first:rounded-l-md data-[spacing=0]:last:rounded-r-md " \ "data-[spacing=0]:data-[variant=outline]:border-l-0 " \ "data-[spacing=0]:data-[variant=outline]:first:border-l"
Constants inherited from ApplicationViewComponent
ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS
Instance Attribute Summary collapse
-
#disabled ⇒ Object
readonly
Returns the value of attribute disabled.
-
#pressed ⇒ Object
readonly
Returns the value of attribute pressed.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#spacing ⇒ Object
readonly
Returns the value of attribute spacing.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
-
#variant ⇒ Object
readonly
Returns the value of attribute variant.
Attributes inherited from ApplicationViewComponent
Instance Method Summary collapse
- #css_classes(extra = nil) ⇒ Object
- #element_attributes(**defaults) ⇒ Object
-
#initialize(value:, variant: :default, size: :default, spacing: 0, pressed: false, disabled: false, **attributes) ⇒ Component
constructor
A new instance of Component.
Methods inherited from ApplicationViewComponent
#call, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name
Constructor Details
#initialize(value:, variant: :default, size: :default, spacing: 0, pressed: false, disabled: false, **attributes) ⇒ Component
Returns a new instance of Component.
20 21 22 23 24 25 26 27 28 29 |
# File 'app/components/shadcn/toggle_group/item/component.rb', line 20 def initialize(value:, variant: :default, size: :default, spacing: 0, pressed: false, disabled: false, **attributes) @value = value.to_s @variant = variant&.to_sym || :default @size = size&.to_sym || :default @spacing = spacing @pressed = pressed @disabled = disabled super(**attributes) end |
Instance Attribute Details
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
18 19 20 |
# File 'app/components/shadcn/toggle_group/item/component.rb', line 18 def disabled @disabled end |
#pressed ⇒ Object (readonly)
Returns the value of attribute pressed.
18 19 20 |
# File 'app/components/shadcn/toggle_group/item/component.rb', line 18 def pressed @pressed end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
18 19 20 |
# File 'app/components/shadcn/toggle_group/item/component.rb', line 18 def size @size end |
#spacing ⇒ Object (readonly)
Returns the value of attribute spacing.
18 19 20 |
# File 'app/components/shadcn/toggle_group/item/component.rb', line 18 def spacing @spacing end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
18 19 20 |
# File 'app/components/shadcn/toggle_group/item/component.rb', line 18 def value @value end |
#variant ⇒ Object (readonly)
Returns the value of attribute variant.
18 19 20 |
# File 'app/components/shadcn/toggle_group/item/component.rb', line 18 def variant @variant end |
Instance Method Details
#css_classes(extra = nil) ⇒ Object
49 50 51 52 53 54 55 |
# File 'app/components/shadcn/toggle_group/item/component.rb', line 49 def css_classes(extra = nil) Toggle::Component.variant_classes( variant:, size:, class: ShadcnViewComponent.cn(EXTRA_CLASSES, extra) ) end |
#element_attributes(**defaults) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/components/shadcn/toggle_group/item/component.rb', line 31 def element_attributes(**defaults) super(**{ type: "button", disabled: (true if disabled), tabindex: "-1", "aria-pressed" => pressed.to_s, "data-state" => (pressed ? "on" : "off"), "data-value" => value, "data-variant" => variant, "data-size" => size, "data-spacing" => spacing, "data-disabled" => (true if disabled), "data-shadcn--toggle-group-target" => "item", "data-action" => "click->shadcn--toggle-group#toggle " \ "keydown->shadcn--toggle-group#keydown" }.merge(defaults)) end |