Class: Flowbite::Input::Label

Inherits:
ViewComponent::Base
  • Object
show all
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

Constructor Details

#initialize(attribute:, form:, disabled: false, options: {}) ⇒ Label

Returns a new instance of Label.



42
43
44
45
46
47
48
# File 'app/components/flowbite/input/label.rb', line 42

def initialize(attribute:, form:, disabled: false, options: {})
  @attribute = attribute
  @disabled = disabled
  @form = form
  @object = form.object
  @options = 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

.stylesObject



19
20
21
22
23
24
25
26
27
# File 'app/components/flowbite/input/label.rb', line 19

def styles
  {
    default: Flowbite::Style.new(
      default: ["block", "mb-2", "text-sm", "font-medium", "text-gray-900", "dark:text-white"],
      disabled: ["block", "mb-2", "text-sm", "font-medium", "text-gray-400", "dark:text-gray-500"],
      error: ["block", "mb-2", "text-sm", "font-medium", "text-red-700", "dark:text-red-500"]
    )
  }.freeze
end

Instance Method Details

#callObject



30
31
32
33
34
35
36
# File 'app/components/flowbite/input/label.rb', line 30

def call
  if content?
    @form.label(@attribute, content, **options)
  else
    @form.label(@attribute, **options)
  end
end

#classesObject

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



51
52
53
# File 'app/components/flowbite/input/label.rb', line 51

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

#errors?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/components/flowbite/input/label.rb', line 38

def errors?
  @object.errors.include?(@attribute.intern)
end