Class: Shadcn::Collapsible::Component
- Inherits:
-
ApplicationViewComponent
- Object
- ViewComponent::Base
- ApplicationViewComponent
- Shadcn::Collapsible::Component
- Defined in:
- app/components/shadcn/collapsible/component.rb
Overview
Port of registry/new-york-v4/ui/collapsible.tsx
Constant Summary
Constants inherited from ApplicationViewComponent
ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS
Instance Attribute Summary collapse
-
#disabled ⇒ Object
readonly
Returns the value of attribute disabled.
-
#open ⇒ Object
readonly
Returns the value of attribute open.
Attributes inherited from ApplicationViewComponent
Instance Method Summary collapse
- #call ⇒ Object
- #element_attributes(**defaults) ⇒ Object
-
#initialize(open: false, disabled: false, **attributes) ⇒ Component
constructor
A new instance of Component.
Methods inherited from ApplicationViewComponent
#css_classes, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name
Constructor Details
#initialize(open: false, disabled: false, **attributes) ⇒ Component
Returns a new instance of Component.
14 15 16 17 18 |
# File 'app/components/shadcn/collapsible/component.rb', line 14 def initialize(open: false, disabled: false, **attributes) @open = open @disabled = disabled super(**attributes) end |
Instance Attribute Details
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
12 13 14 |
# File 'app/components/shadcn/collapsible/component.rb', line 12 def disabled @disabled end |
#open ⇒ Object (readonly)
Returns the value of attribute open.
12 13 14 |
# File 'app/components/shadcn/collapsible/component.rb', line 12 def open @open end |
Instance Method Details
#call ⇒ Object
30 31 32 |
# File 'app/components/shadcn/collapsible/component.rb', line 30 def call render_element(body: safe_join([ trigger, panel, content ].compact)) end |
#element_attributes(**defaults) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'app/components/shadcn/collapsible/component.rb', line 20 def element_attributes(**defaults) super(**{ "data-state" => open ? "open" : "closed", "data-disabled" => (true if disabled), "data-controller" => "shadcn--collapsible", "data-shadcn--collapsible-open-value" => open, "data-shadcn--collapsible-disabled-value" => disabled }.merge(defaults)) end |