Class: Fluxbit::Form::RadioGroupButtonComponent

Inherits:
FieldComponent
  • Object
show all
Includes:
Config::Form::RadioGroupButtonComponent
Defined in:
app/components/fluxbit/form/radio_group_button_component.rb

Overview

The ‘Fluxbit::Form::RadioGroupButtonComponent` is a component for rendering radio buttons styled as a button group. It provides the visual appearance of grouped buttons while maintaining radio button behavior (only one option can be selected at a time).

This component is useful for creating segmented controls, view toggles, or any interface where users need to select one option from a group with a button-like appearance.

Instance Method Summary collapse

Constructor Details

#initialize(**props) ⇒ Fluxbit::Form::RadioGroupButtonComponent

Initializes the radio group button component with the given properties.

Parameters:

  • props (Hash)

    The properties to customize the radio group button.

Options Hash (**props):

  • :name (String) — default: nil

    The name attribute for the radio button group (required for proper radio functionality).

  • :color (Symbol, String) — default: :default

    The color style of the buttons.

  • :size (Symbol, String) — default: 1

    The size of the buttons (e.g., ‘0` to `4`).

  • :pill (Boolean) — default: false

    Determines if the buttons have pill-shaped edges.

  • **props (Hash)

    Remaining options declared as HTML attributes, applied to the group container.



28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/components/fluxbit/form/radio_group_button_component.rb', line 28

def initialize(**props)
  super
  @props = props
  @name = @props.delete(:name) || "radio_group_#{fx_id}"
  @color = options (@props.delete(:color) || "").to_sym, collection: button_styles[:colors].keys, default: @@color
  @size = @props.delete(:size) || @@size
  @pill = options @props.delete(:pill), default: false
  @outline = @color.to_s.end_with?("_outline")
  @options_group = []

  add class: Fluxbit::Config::Form::RadioGroupButtonComponent.styles[:group], to: @props, first_element: true
end

Instance Method Details

#callObject



41
42
43
44
45
46
47
48
# File 'app/components/fluxbit/form/radio_group_button_component.rb', line 41

def call
  radio_options
  tag.div(**@props) do
    @options_group.each_with_index do |option, index|
      concat render_radio_button(option, index)
    end
  end
end