Class: NitroKit::Fieldset

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

Instance Attribute Summary

Attributes inherited from Component

#attrs

Instance Method Summary collapse

Methods inherited from Component

#builder, from_template

Constructor Details

#initialize(legend: nil, description: nil, **attrs) ⇒ Fieldset



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

def initialize(legend: nil, description: nil, **attrs)
  @legend = legend
  @description = description
  super(
    attrs,
    class: base_class
  )
end

Instance Method Details

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



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

def description(text = nil, **attrs, &block)
  builder do
    div(**mattr(attrs, class: description_class, data: { slot: "text" })) do
      text_or_block(text, &block)
    end
  end
end

#html_legendObject



23
# File 'app/components/nitro_kit/fieldset.rb', line 23

alias :html_legend :legend

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



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

def legend(text = nil, **attrs, &block)
  builder do
    html_legend(**mattr(attrs, class: legend_class)) do
      text_or_block(text, &block)
    end
  end
end

#view_templateObject



14
15
16
17
18
19
20
21
# File 'app/components/nitro_kit/fieldset.rb', line 14

def view_template
  fieldset(**attrs) do
    legend(@legend) if @legend
    description(@description) if @description

    yield
  end
end