Class: PhlexKit::CollapsibleContent

Inherits:
BaseComponent show all
Defined in:
app/components/phlex_kit/collapsible/collapsible_content.rb

Overview

Collapsed region of a Collapsible. Pass open: matching the parent Collapsible's so a closed region is hidden before JS (no flash-open, and no stuck-open region without JS); the controller toggles .pk-hidden from there. The default id lets the trigger's aria-controls point here.

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(open: false, id: nil, **attrs) ⇒ CollapsibleContent

Returns a new instance of CollapsibleContent.



7
8
9
10
11
# File 'app/components/phlex_kit/collapsible/collapsible_content.rb', line 7

def initialize(open: false, id: nil, **attrs)
  @open = open
  @id = id || "pk-collapsible-content-#{SecureRandom.hex(4)}"
  @attrs = attrs
end

Instance Method Details

#view_templateObject



13
14
15
16
17
18
19
# File 'app/components/phlex_kit/collapsible/collapsible_content.rb', line 13

def view_template(&)
  div(**mix({
    class: @open ? "pk-collapsible-content" : "pk-collapsible-content pk-hidden",
    id: @id,
    data: { phlex_kit__collapsible_target: "content" }
  }, @attrs), &)
end