Class: Anchor::InputComponent

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

Constant Summary collapse

ICON_CLASSES =
%w(
  absolute
  top-1/2
  -translate-y-1/2
  text-secondary
  pointer-events-none
).freeze
INPUT_CLASSES =
%w(
  form-input
  text-base
  min-h-[40px]
  resize-none
  block
  w-full
  rounded
  border
).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:, type:, starting_icon: nil, ending_icon: nil, **kwargs) ⇒ InputComponent

Returns a new instance of InputComponent.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/components/anchor/input_component.rb', line 22

def initialize(
  form_builder:,
  attribute:,
  type:,
  starting_icon: nil,
  ending_icon: nil,
  **kwargs
)
  @form_builder = form_builder
  @attribute = attribute
  @type = type
  @starting_icon = starting_icon
  @ending_icon = ending_icon

  super(**kwargs)
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



39
40
41
# File 'app/components/anchor/input_component.rb', line 39

def attribute
  @attribute
end

#ending_iconObject (readonly)

Returns the value of attribute ending_icon.



39
40
41
# File 'app/components/anchor/input_component.rb', line 39

def ending_icon
  @ending_icon
end

#starting_iconObject (readonly)

Returns the value of attribute starting_icon.



39
40
41
# File 'app/components/anchor/input_component.rb', line 39

def starting_icon
  @starting_icon
end

#typeObject (readonly)

Returns the value of attribute type.



39
40
41
# File 'app/components/anchor/input_component.rb', line 39

def type
  @type
end

Instance Method Details

#optionsObject



41
42
43
44
45
46
47
48
49
50
# File 'app/components/anchor/input_component.rb', line 41

def options
  {
    class: class_names(
      INPUT_CLASSES,
      "pl-11" => starting_icon?,
      "pr-11" => ending_icon?
    ),
    data: { testid: },
  }
end