Class: AccordionComponent

Inherits:
Component show all
Includes:
Attachable
Defined in:
app/components/accordion_component.rb

Overview

Accordion — collapsible content panel using <details>/<summary>.

Usage:

Accordion(attached: true) { |a|
  a.title { text "Section" }
  text "Panel content"
}

Constant Summary

Constants inherited from Component

Component::HTML_OPTIONS

Instance Method Summary collapse

Methods inherited from Component

default, #initialize, #render_in, slot

Constructor Details

This class inherits a constructor from Component

Instance Method Details

#to_sObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/components/accordion_component.rb', line 24

def to_s
  classes = class_names(
    "ui",
    color,
    { "attached" => attached, "raised" => raised, "inverted" => inverted,
      "basic" => basic, "compact" => compact, "secondary" => secondary },
    "segment"
  )

  opts = merge_html_options(class: classes)
  opts[:open] = "" if open

  tag.details(**opts) {
    safe_join([
      tag.summary { @slots[:title] || "" },
      tag.div { @content }
    ])
  }
end