Class: PhlexKit::AccordionTrigger
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- PhlexKit::AccordionTrigger
- Defined in:
- app/components/phlex_kit/accordion/accordion_trigger.rb
Instance Method Summary collapse
-
#initialize(open: false, disabled: false, heading_level: 3, **attrs) ⇒ AccordionTrigger
constructor
A new instance of AccordionTrigger.
- #view_template ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(open: false, disabled: false, heading_level: 3, **attrs) ⇒ AccordionTrigger
Returns a new instance of AccordionTrigger.
3 4 5 6 7 8 9 |
# File 'app/components/phlex_kit/accordion/accordion_trigger.rb', line 3 def initialize(open: false, disabled: false, heading_level: 3, **attrs) raise ArgumentError, "heading_level must be 1..6" unless (1..6).cover?(heading_level) @open = open @disabled = disabled @heading_level = heading_level @attrs = attrs end |
Instance Method Details
#view_template ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/components/phlex_kit/accordion/accordion_trigger.rb', line 10 def view_template(&) # APG accordion: each trigger is a button wrapped in a heading. # aria-expanded reflects the render-time open state; the controller keeps # it in sync and wires aria-controls to the content's id in connect(). base = { type: "button", class: "pk-accordion-trigger", aria_expanded: @open ? "true" : "false", disabled: @disabled, data: { phlex_kit__accordion_target: "trigger", action: "click->phlex-kit--accordion#toggle" } } send(:"h#{@heading_level}", class: "pk-accordion-heading") do (**mix(base, @attrs), &) end end |