Class: Uchi::Flowbite::Input::RadioButton

Inherits:
Input
  • Object
show all
Defined in:
app/components/uchi/flowbite/input/radio_button.rb

Overview

The radio button component can be used to allow the user to choose a single option from one or more available options.

https://flowbite.com/docs/forms/radio/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute:, form:, value:, class: nil, disabled: false, options: {}) ⇒ RadioButton

Returns a new instance of RadioButton.



42
43
44
45
# File 'app/components/uchi/flowbite/input/radio_button.rb', line 42

def initialize(attribute:, form:, value:, class: nil, disabled: false, options: {})
  super(attribute: attribute, class: binding.local_variable_get(:class), disabled: disabled, form: form, options: options)
  @value = value
end

Class Method Details

.sizes ⇒ Object

Radio buttons only have their default size.



12
13
14
15
16
# File 'app/components/uchi/flowbite/input/radio_button.rb', line 12

def sizes
  {
    default: ["w-4", "h-4"]
  }
end

.styles ⇒ Object

rubocop:disable Layout/LineLength



19
20
21
22
23
24
25
26
27
28
29
# File 'app/components/uchi/flowbite/input/radio_button.rb', line 19

def styles
  Uchi::Flowbite::Styles.from_hash(
    {
      default: {
        default: ["text-brand", "bg-neutral-secondary-medium", "border-default-medium", "focus:ring-brand", "focus:ring-2"],
        disabled: ["text-brand", "bg-neutral-secondary-medium", "border-default-medium", "focus:ring-brand", "focus:ring-2", "cursor-not-allowed"],
        error: ["text-danger", "bg-danger-soft", "border-danger-subtle", "focus:ring-danger", "focus:ring-2"]
      }
    }.freeze
  )
end

Instance Method Details

#call ⇒ Object

Returns the HTML to use for the actual input field element.



33
34
35
36
37
38
39
40
# File 'app/components/uchi/flowbite/input/radio_button.rb', line 33

def call
  @form.send(
    input_field_type,
    @attribute,
    @value,
    **input_options
  )
end

#input_field_type ⇒ Object



47
48
49
# File 'app/components/uchi/flowbite/input/radio_button.rb', line 47

def input_field_type
  :radio_button
end