Class: Flowbite::Input::Checkbox
- Defined in:
- app/components/flowbite/input/checkbox.rb
Overview
The checkbox component can be used to receive one or more selected options from the user in the form of a square box available in multiple styles, sizes, colors, and variants coded with the utility classes from Tailwind CSS and with support for dark mode.
Constant Summary collapse
- DEFAULT_CHECKED_VALUE =
"1"- DEFAULT_UNCHECKED_VALUE =
"0"
Constants inherited from Field
Instance Attribute Summary
Attributes inherited from Field
Class Method Summary collapse
-
.sizes ⇒ Object
Checkboxes only have their default size.
-
.styles ⇒ Object
rubocop:disable Layout/LineLength.
Instance Method Summary collapse
-
#call ⇒ Object
Returns the HTML to use for the actual input field element.
-
#initialize(attribute:, form:, disabled: false, options: {}, size: :default, unchecked_value: DEFAULT_UNCHECKED_VALUE, value: DEFAULT_CHECKED_VALUE) ⇒ Checkbox
constructor
A new instance of Checkbox.
- #input_field_type ⇒ Object
-
#input_options ⇒ Object
Returns the options argument for the input field.
Methods inherited from Field
Constructor Details
#initialize(attribute:, form:, disabled: false, options: {}, size: :default, unchecked_value: DEFAULT_UNCHECKED_VALUE, value: DEFAULT_CHECKED_VALUE) ⇒ Checkbox
Returns a new instance of Checkbox.
46 47 48 49 50 |
# File 'app/components/flowbite/input/checkbox.rb', line 46 def initialize(attribute:, form:, disabled: false, options: {}, size: :default, unchecked_value: DEFAULT_UNCHECKED_VALUE, value: DEFAULT_CHECKED_VALUE) super(attribute: attribute, form: form, disabled: disabled, options: , size: size) @unchecked_value = unchecked_value @value = value end |
Class Method Details
.sizes ⇒ Object
Checkboxes only have their default size.
17 18 19 20 21 |
# File 'app/components/flowbite/input/checkbox.rb', line 17 def sizes { default: ["w-4", "h-4"] } end |
.styles ⇒ Object
rubocop:disable Layout/LineLength
24 25 26 27 28 29 30 31 32 |
# File 'app/components/flowbite/input/checkbox.rb', line 24 def styles { default: Flowbite::Style.new( default: ["text-blue-600", "bg-gray-100", "border-gray-300", "rounded-sm", "focus:ring-blue-500", "dark:focus:ring-blue-600", "dark:ring-offset-gray-800", "focus:ring-2", "dark:bg-gray-700", "dark:border-gray-600"], disabled: ["text-blue-600", "bg-gray-100", "border-gray-300", "rounded-sm", "focus:ring-blue-500", "dark:focus:ring-blue-600", "dark:ring-offset-gray-800", "focus:ring-2", "dark:bg-gray-700", "dark:border-gray-600"], error: ["text-red-600", "bg-red-50", "border-red-500", "rounded-sm", "focus:ring-red-500", "dark:focus:ring-red-600", "dark:ring-offset-gray-800", "focus:ring-2", "dark:bg-gray-700", "dark:border-red-500"] ) }.freeze end |
Instance Method Details
#call ⇒ Object
Returns the HTML to use for the actual input field element.
36 37 38 39 40 41 42 43 44 |
# File 'app/components/flowbite/input/checkbox.rb', line 36 def call @form.send( input_field_type, @attribute, , checked_value, unchecked_value ) end |
#input_field_type ⇒ Object
52 53 54 |
# File 'app/components/flowbite/input/checkbox.rb', line 52 def input_field_type :check_box end |
#input_options ⇒ Object
Returns the options argument for the input field
57 58 59 60 61 62 |
# File 'app/components/flowbite/input/checkbox.rb', line 57 def { class: classes, disabled: disabled? }.merge() end |