Class: Fluxbit::Form::CheckBoxComponent
- Inherits:
-
FieldComponent
- Object
- FieldComponent
- Fluxbit::Form::CheckBoxComponent
- Includes:
- Config::Form::CheckBoxComponent
- Defined in:
- app/components/fluxbit/form/check_box_component.rb
Overview
The ‘Fluxbit::Form::CheckBoxComponent` is a form input component for check boxes and radio buttons. It extends `Fluxbit::Form::FieldComponent` and provides a styled checkbox/radio with label, helper text, and support for different visual states and groupings. It automatically adds the correct styles for both checkbox and radio types and works with or without Rails form builders.
Constant Summary collapse
- TYPE_DEFAULT =
:check_box
- TYPE_OPTIONS =
%i[check_box checkbox radio_button].freeze
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(**props) ⇒ CheckBoxComponent
constructor
Initializes the check box component with the given properties.
- #input ⇒ Object
Constructor Details
#initialize(**props) ⇒ CheckBoxComponent
Initializes the check box component with the given properties.
28 29 30 31 32 33 |
# File 'app/components/fluxbit/form/check_box_component.rb', line 28 def initialize(**props) super(**props) @type = (@props.delete(:type), collection: TYPE_OPTIONS, default: TYPE_DEFAULT) add(class: styles[:checkbox], to: @props, first_element: true) if @props[:type] == "checkbox" add(class: styles[:base], to: @props, first_element: true) end |
Instance Method Details
#call ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/components/fluxbit/form/check_box_component.rb', line 43 def call if @help_text content_tag :div, { class: "flex" } do concat content_tag(:div, input, { class: styles[:input_div] }) concat content_tag(:div, safe_join([ label, help_text ]), { class: styles[:helper_div] }) end else content_tag :div, { class: styles[:no_helper_div] } do concat input concat label end end end |
#input ⇒ Object
35 36 37 38 39 40 41 |
# File 'app/components/fluxbit/form/check_box_component.rb', line 35 def input if @form.present? && @attribute.present? @form.public_send(@type, @attribute, @props) else public_send("#{@type}_tag", @name, @value, @props) end end |