Class: Shadcn::ToggleGroup::Component
- Inherits:
-
ApplicationViewComponent
- Object
- ViewComponent::Base
- ApplicationViewComponent
- Shadcn::ToggleGroup::Component
- Includes:
- Concerns::SubmitsValue
- Defined in:
- app/components/shadcn/toggle_group/component.rb
Overview
Port of registry/new-york-v4/ui/toggle-group.tsx
React passes variant/size/spacing down through context; here the group exposes them to its items through the slot, which is the same idea.
Constant Summary
Constants inherited from ApplicationViewComponent
ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#spacing ⇒ Object
readonly
Returns the value of attribute spacing.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#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
- #call ⇒ Object
- #element_attributes(**defaults) ⇒ Object
-
#initialize(type: :single, variant: :default, size: :default, spacing: 0, value: nil, name: nil, **attributes) ⇒ Component
constructor
A new instance of Component.
Methods included from Concerns::SubmitsValue
Methods inherited from ApplicationViewComponent
#css_classes, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name
Constructor Details
#initialize(type: :single, variant: :default, size: :default, spacing: 0, value: nil, name: nil, **attributes) ⇒ Component
Returns a new instance of Component.
26 27 28 29 30 31 32 33 34 35 |
# File 'app/components/shadcn/toggle_group/component.rb', line 26 def initialize(type: :single, variant: :default, size: :default, spacing: 0, value: nil, name: nil, **attributes) @type = type&.to_sym || :single @variant = variant&.to_sym || :default @size = size&.to_sym || :default @spacing = spacing @value = Array(value).compact.join(",") @name = name super(**attributes) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
24 25 26 |
# File 'app/components/shadcn/toggle_group/component.rb', line 24 def name @name end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
24 25 26 |
# File 'app/components/shadcn/toggle_group/component.rb', line 24 def size @size end |
#spacing ⇒ Object (readonly)
Returns the value of attribute spacing.
24 25 26 |
# File 'app/components/shadcn/toggle_group/component.rb', line 24 def spacing @spacing end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
24 25 26 |
# File 'app/components/shadcn/toggle_group/component.rb', line 24 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
24 25 26 |
# File 'app/components/shadcn/toggle_group/component.rb', line 24 def value @value end |
#variant ⇒ Object (readonly)
Returns the value of attribute variant.
24 25 26 |
# File 'app/components/shadcn/toggle_group/component.rb', line 24 def variant @variant end |
Instance Method Details
#call ⇒ Object
49 50 51 |
# File 'app/components/shadcn/toggle_group/component.rb', line 49 def call render_element(body: safe_join([ items, content, hidden_input ].flatten.compact)) end |
#element_attributes(**defaults) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/components/shadcn/toggle_group/component.rb', line 37 def element_attributes(**defaults) super(**{ "data-variant" => variant, "data-size" => size, "data-spacing" => spacing, style: [ attributes[:style], "--gap: #{spacing}" ].compact.join(";"), "data-controller" => "shadcn--toggle-group", "data-shadcn--toggle-group-type-value" => type, "data-shadcn--toggle-group-value-value" => value }.merge(defaults)) end |