Class: Flowbite::Input::Label
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Flowbite::Input::Label
- Defined in:
- app/components/flowbite/input/label.rb
Overview
Constant Summary collapse
- STATES =
[ DEFAULT = :default, DISABLED = :disabled, ERROR = :error ].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#classes ⇒ Object
Returns an array with the CSS classes to apply to the label element.
- #errors? ⇒ Boolean
-
#initialize(attribute:, form:, class: nil, disabled: false, options: {}) ⇒ Label
constructor
A new instance of Label.
Constructor Details
#initialize(attribute:, form:, class: nil, disabled: false, options: {}) ⇒ Label
Returns a new instance of Label.
46 47 48 49 50 51 52 53 |
# File 'app/components/flowbite/input/label.rb', line 46 def initialize(attribute:, form:, class: nil, disabled: false, options: {}) @attribute = attribute @class = Array.wrap(binding.local_variable_get(:class)) @disabled = disabled @form = form @object = form.object @options = end |
Class Method Details
.classes(state: :default, style: :default) ⇒ Object
14 15 16 17 |
# File 'app/components/flowbite/input/label.rb', line 14 def classes(state: :default, style: :default) style = styles.fetch(style) style.fetch(state) end |
.styles ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/components/flowbite/input/label.rb', line 19 def styles Flowbite::Styles.from_hash( { default: { default: ["block", "mb-2.5", "text-sm", "font-medium", "text-heading"], disabled: ["block", "mb-2.5", "text-sm", "font-medium", "text-fg-disabled"], error: ["block", "mb-2.5", "text-sm", "font-medium", "text-fg-danger-strong"] } }.freeze ) end |
Instance Method Details
#call ⇒ Object
32 33 34 35 36 37 38 |
# File 'app/components/flowbite/input/label.rb', line 32 def call if content? @form.label(@attribute, content, **) else @form.label(@attribute, **) end end |
#classes ⇒ Object
Returns an array with the CSS classes to apply to the label element
56 57 58 |
# File 'app/components/flowbite/input/label.rb', line 56 def classes self.class.classes(state: state) + @class end |
#errors? ⇒ Boolean
40 41 42 43 44 |
# File 'app/components/flowbite/input/label.rb', line 40 def errors? return false unless @object @object.errors.include?(@attribute.intern) end |