Class: BulmaPhlex::Rails::Checkbox
- Inherits:
-
Base
- Object
- Base
- BulmaPhlex::Rails::Checkbox
- Defined in:
- lib/bulma_phlex/rails/components/checkbox.rb
Overview
# Checkbox Component
This component renders a Bulma-styled checkbox within a form. It integrates with Rails’ form builder to ensure proper labeling and value handling.
The label can be generated automatically based on the attribute name or customized using a block.
Example usage:
“‘ruby form_with model: @user do |f|
f.checkbox :subscribe_newsletter
f.checkbox :terms_of_service do
span { "I agree to " }
a(href: "/terms") { "the terms and conditions" }
end
end “‘
Instance Method Summary collapse
-
#initialize(form_builder, method, options, delivered, label_block) ⇒ Checkbox
constructor
A new instance of Checkbox.
- #view_template ⇒ Object
Constructor Details
#initialize(form_builder, method, options, delivered, label_block) ⇒ Checkbox
Returns a new instance of Checkbox.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bulma_phlex/rails/components/checkbox.rb', line 24 def initialize(form_builder, method, , delivered, label_block) @form_builder = form_builder @method = method @options = .dup @delivered = delivered @label_block = label_block @options[:class] = Array.wrap(@options[:class]) << "mr-2" @form_field_options = @options.extract!(:column, :grid) .with_defaults(column: @form_builder.columns_flag, grid: @form_builder.grid_flag) end |
Instance Method Details
#view_template ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/bulma_phlex/rails/components/checkbox.rb', line 37 def view_template render FormField.new(**@form_field_options) do @form_builder.label(@method, nil, class: "checkbox", skip_label_class: true) do |label_builder| raw @delivered.call(@options) render_label(label_builder) end end end |