Class: Shadcn::Collapsible::Component

Inherits:
ApplicationViewComponent show all
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

Attributes inherited from ApplicationViewComponent

#attributes

Instance Method Summary collapse

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

#disabledObject (readonly)

Returns the value of attribute disabled.



12
13
14
# File 'app/components/shadcn/collapsible/component.rb', line 12

def disabled
  @disabled
end

#openObject (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

#callObject



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