Class: Flowbite::Input::Hint

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/flowbite/input/hint.rb

Overview

A hint element for input fields.

Provides additional context or instructions for the user.

See flowbite.com/docs/forms/input-field/#helper-text

Constant Summary collapse

STATES =
[
  DEFAULT = :default
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute:, form:, class: nil, options: {}) ⇒ Hint

Returns a new instance of Hint.



40
41
42
43
44
45
46
# File 'app/components/flowbite/input/hint.rb', line 40

def initialize(attribute:, form:, class: nil, options: {})
  @attribute = attribute
  @class = Array.wrap(binding.local_variable_get(:class))
  @form = form
  @options = options
  @object = form.object
end

Class Method Details

.classes(state: :default, style: :default) ⇒ Object



16
17
18
19
# File 'app/components/flowbite/input/hint.rb', line 16

def classes(state: :default, style: :default)
  style = styles.fetch(style)
  style.fetch(state)
end

.stylesObject



21
22
23
24
25
26
27
28
29
# File 'app/components/flowbite/input/hint.rb', line 21

def styles
  Flowbite::Styles.from_hash(
    {
      default: {
        default: ["mt-2.5", "text-sm", "text-body"]
      }
    }.freeze
  )
end

Instance Method Details

#callObject



32
33
34
35
36
37
38
# File 'app/components/flowbite/input/hint.rb', line 32

def call
  tag.p(
    content,
    class: classes,
    **@options
  )
end

#classesObject

Returns an array with the CSS classes to apply to the label element



49
50
51
# File 'app/components/flowbite/input/hint.rb', line 49

def classes
  self.class.classes(state: state) + @class
end