Class: NitroKit::CheckboxGroup

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

Instance Attribute Summary collapse

Attributes inherited from Component

#attrs

Instance Method Summary collapse

Methods inherited from Component

#builder, from_template

Constructor Details

#initialize(options = nil, **attrs) ⇒ CheckboxGroup

Returns a new instance of CheckboxGroup.



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

def initialize(options = nil, **attrs)
  @options = options

  super(
    attrs,
    class: "flex items-start flex-col gap-2"
  )
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



14
15
16
# File 'app/components/nitro_kit/checkbox_group.rb', line 14

def options
  @options
end

Instance Method Details

#item(text = nil, **attrs, &block) ⇒ Object



34
35
36
37
38
39
40
# File 'app/components/nitro_kit/checkbox_group.rb', line 34

def item(text = nil, **attrs, &block)
  builder do
    render(Checkbox.new(**attrs)) do
      text_or_block(text, &block)
    end
  end
end

#title(text = nil, **attrs, &block) ⇒ Object



26
27
28
29
30
31
32
# File 'app/components/nitro_kit/checkbox_group.rb', line 26

def title(text = nil, **attrs, &block)
  builder do
    render(Label.new(**attrs)) do
      text_or_block(text, &block)
    end
  end
end

#view_templateObject



16
17
18
19
20
21
22
23
24
# File 'app/components/nitro_kit/checkbox_group.rb', line 16

def view_template
  div(**attrs) do
    if block_given?
      yield
    else
      options.map { |option| item(*option) }
    end
  end
end