Class: NitroKit::Accordion

Inherits:
Component
  • Object
show all
Defined in:
app/components/nitro_kit/accordion.rb

Instance Attribute Summary

Attributes inherited from Component

#attrs

Instance Method Summary collapse

Methods inherited from Component

#builder, from_template

Constructor Details

#initialize(**attrs) ⇒ Accordion

Returns a new instance of Accordion.



5
6
7
8
9
10
11
# File 'app/components/nitro_kit/accordion.rb', line 5

def initialize(**attrs)
  super(
    attrs,
    class: item_class,
    data: { controller: "nk--accordion" }
  )
end

Instance Method Details

#content(**attrs) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/components/nitro_kit/accordion.rb', line 47

def content(**attrs)
  builder do
    div(
      **mattr(
        attrs,
        class: content_class,
        data: {
          nk__accordion_target: "content"
        },
        aria: { hidden: "true" }
      )
    ) do
      div(class: "pb-4") { yield }
    end
  end
end

#item(**attrs) ⇒ Object



19
20
21
22
23
24
25
# File 'app/components/nitro_kit/accordion.rb', line 19

def item(**attrs)
  builder do
    div(**attrs) do
      yield
    end
  end
end

#trigger(text = nil, **attrs) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/components/nitro_kit/accordion.rb', line 27

def trigger(text = nil, **attrs)
  builder do
    button(
      **mattr(
        attrs,
        type: "button",
        class: trigger_class,
        data: {
          action: "nk--accordion#toggle",
          nk__accordion_target: "trigger"
        },
        aria: { expanded: "false" }
      )
    ) do
      block_given? ? yield : plain(text)
      chevron_icon
    end
  end
end

#view_templateObject



13
14
15
16
17
# File 'app/components/nitro_kit/accordion.rb', line 13

def view_template
  div(**attrs) do
    yield
  end
end