Class: NitroKit::RadioButton

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

Instance Attribute Summary collapse

Attributes inherited from Component

#attrs

Instance Method Summary collapse

Methods inherited from Component

#builder, from_template

Constructor Details

#initialize(label: nil, id: nil, wrapper: {}, size: :md, **attrs) ⇒ RadioButton

Returns a new instance of RadioButton.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/components/nitro_kit/radio_button.rb', line 5

def initialize(label: nil, id: nil, wrapper: {}, size: :md, **attrs)
  @label = label
  @id = id || "nk--" + SecureRandom.hex(4)
  @size = size
  @wrapper = wrapper

  super(
    attrs,
    id: @id,
    type: "radio",
    class: input_class
  )
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



21
22
23
# File 'app/components/nitro_kit/radio_button.rb', line 21

def id
  @id
end

#labelObject (readonly) Also known as: html_label

Returns the value of attribute label.



21
22
23
# File 'app/components/nitro_kit/radio_button.rb', line 21

def label
  @label
end

#sizeObject (readonly)

Returns the value of attribute size.



21
22
23
# File 'app/components/nitro_kit/radio_button.rb', line 21

def size
  @size
end

#wrapperObject (readonly)

Returns the value of attribute wrapper.



21
22
23
# File 'app/components/nitro_kit/radio_button.rb', line 21

def wrapper
  @wrapper
end

Instance Method Details

#view_templateObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/components/nitro_kit/radio_button.rb', line 23

def view_template
  div(**mattr(wrapper, class: wrapper_class)) do
    html_label(class: merge_class("inline-grid *:[grid-area:1/1] shrink-0 place-items-center", size_class)) do
      input(**attrs)
      dot
    end

    if label.present? || block_given?
      render(Label.new(for: id)) do
        label || (block_given? ? yield : nil)
      end
    end
  end
end