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:, class: nil, 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:, class: nil, disabled: false, options: {}, size: :default, unchecked_value: DEFAULT_UNCHECKED_VALUE, value: DEFAULT_CHECKED_VALUE) ⇒ Checkbox
Returns a new instance of Checkbox.
48 49 50 51 52 |
# File 'app/components/flowbite/input/checkbox.rb', line 48 def initialize(attribute:, form:, class: nil, disabled: false, options: {}, size: :default, unchecked_value: DEFAULT_UNCHECKED_VALUE, value: DEFAULT_CHECKED_VALUE) super(attribute: attribute, class: binding.local_variable_get(:class), 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 33 34 |
# File 'app/components/flowbite/input/checkbox.rb', line 24 def styles Flowbite::Styles.from_hash( { default: { default: ["text-brand", "bg-neutral-secondary-medium", "border-default-medium", "rounded-sm", "focus:ring-brand", "focus:ring-2"], disabled: ["text-brand", "bg-neutral-secondary-medium", "border-default-medium", "rounded-sm", "focus:ring-brand", "focus:ring-2", "cursor-not-allowed"], error: ["text-danger", "bg-danger-soft", "border-danger-subtle", "rounded-sm", "focus:ring-danger", "focus:ring-2"] } }.freeze ) end |
Instance Method Details
#call ⇒ Object
Returns the HTML to use for the actual input field element.
38 39 40 41 42 43 44 45 46 |
# File 'app/components/flowbite/input/checkbox.rb', line 38 def call @form.send( input_field_type, @attribute, , checked_value, unchecked_value ) end |
#input_field_type ⇒ Object
54 55 56 |
# File 'app/components/flowbite/input/checkbox.rb', line 54 def input_field_type :check_box end |
#input_options ⇒ Object
Returns the options argument for the input field
59 60 61 62 63 64 |
# File 'app/components/flowbite/input/checkbox.rb', line 59 def { class: classes, disabled: disabled? }.merge() end |