Class: Anchor::LabelComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/anchor/label_component.rb

Constant Summary collapse

LABEL_CLASSES =
%w(
  font-semibold
  text-base
  text-primary
).freeze

Constants included from ViewHelper

ViewHelper::ANCHOR_HELPERS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Component

generate_id

Methods included from ViewHelper

#anchor_form_with, #anchor_svg, #deep_blank?, #merge_options, #popover_trigger_attributes

Methods included from FetchOrFallbackHelper

#fetch_or_fallback

Constructor Details

#initialize(form_builder:, attribute:, **options) ⇒ LabelComponent

Returns a new instance of LabelComponent.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/components/anchor/label_component.rb', line 11

def initialize(form_builder:, attribute:, **options)
  @form_builder = form_builder
  @attribute = attribute
  @options = options.merge(
    class: Array(options.delete(:class)) + LABEL_CLASSES
  )
  @required = ModelValidators
    .new(@form_builder.object, options)
    .attribute_required?(attribute)

  super()
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'app/components/anchor/label_component.rb', line 9

def options
  @options
end

Instance Method Details

#optional_suffixObject



24
25
26
27
28
29
30
31
32
33
# File 'app/components/anchor/label_component.rb', line 24

def optional_suffix
  if required_attribute?
    ""
  else
    tag.span(
      t(".optional_suffix"),
      class: "text-secondary font-normal italic"
    )
  end
end