Class: ViewComponent::InputComponent::InputTextComponent
- Inherits:
-
Object
- Object
- ViewComponent::InputComponent::InputTextComponent
- Includes:
- ComponentHelper
- Defined in:
- app/helpers/view_component/input_component/input_text_component.rb
Direct Known Subclasses
Constant Summary collapse
- INPUT_SIZE_STYLE =
{ md: 'input-text-md', lg: 'input-text-lg' }.freeze
- ICON_SIZE =
{ md: 'input-text-icon-md', lg: 'input-text-icon-lg' }.freeze
- INPUT_WRAPPER_STYLES =
{ md: 'input-text-div-base-md', lg: 'input-text-div-base-lg' }.freeze
- LABEL_STYLES =
{ md: 'input-text-label-md', lg: 'input-text-label-lg' }.freeze
- SUBTEXT_SIZE =
{ md: 'input-text-subtext-md', lg: 'input-text-subtext-lg' }.freeze
Instance Attribute Summary collapse
-
#disabled ⇒ Object
Returns the value of attribute disabled.
-
#error ⇒ Object
Returns the value of attribute error.
-
#form ⇒ Object
Returns the value of attribute form.
-
#html_options ⇒ Object
Returns the value of attribute html_options.
-
#icon_name ⇒ Object
Returns the value of attribute icon_name.
-
#icon_position ⇒ Object
Returns the value of attribute icon_position.
-
#label ⇒ Object
Returns the value of attribute label.
-
#name ⇒ Object
Returns the value of attribute name.
-
#size ⇒ Object
Returns the value of attribute size.
-
#subtext ⇒ Object
Returns the value of attribute subtext.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #icon_size ⇒ Object
- #icon_style ⇒ Object
-
#initialize(form:, name:, label:, type:, placeholder:, value:, subtext:, error:, icon_name:, icon_position:, disabled:, size:, html_options:) ⇒ InputTextComponent
constructor
A new instance of InputTextComponent.
- #input_style ⇒ Object
- #input_wrapper_style ⇒ Object
- #label_style ⇒ Object
- #placeholder ⇒ Object
- #placeholder=(value) ⇒ Object
- #subtext_style ⇒ Object
Methods included from ComponentHelper
Constructor Details
#initialize(form:, name:, label:, type:, placeholder:, value:, subtext:, error:, icon_name:, icon_position:, disabled:, size:, html_options:) ⇒ InputTextComponent
Returns a new instance of InputTextComponent.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/helpers/view_component/input_component/input_text_component.rb', line 36 def initialize(form:, name:, label:, type:, placeholder:, value:, subtext:, error:, icon_name:, icon_position:, disabled:, size:, html_options:) = resolve_error(form, name, error) self.form = form self.name = name self.label = label self.type = type self.value = value self.subtext = .presence || subtext # Prioritise error over subtext self.error = self.icon_name = icon_name self.icon_position = icon_position self.disabled = disabled self.size = size self. = self.[:placeholder] = placeholder self.[:class] = input_style self.[:disabled] = disabled if disabled end |
Instance Attribute Details
#disabled ⇒ Object
Returns the value of attribute disabled.
33 34 35 |
# File 'app/helpers/view_component/input_component/input_text_component.rb', line 33 def disabled @disabled end |
#error ⇒ Object
Returns the value of attribute error.
33 34 35 |
# File 'app/helpers/view_component/input_component/input_text_component.rb', line 33 def error @error end |
#form ⇒ Object
Returns the value of attribute form.
33 34 35 |
# File 'app/helpers/view_component/input_component/input_text_component.rb', line 33 def form @form end |
#html_options ⇒ Object
Returns the value of attribute html_options.
33 34 35 |
# File 'app/helpers/view_component/input_component/input_text_component.rb', line 33 def end |
#icon_name ⇒ Object
Returns the value of attribute icon_name.
33 34 35 |
# File 'app/helpers/view_component/input_component/input_text_component.rb', line 33 def icon_name @icon_name end |
#icon_position ⇒ Object
Returns the value of attribute icon_position.
33 34 35 |
# File 'app/helpers/view_component/input_component/input_text_component.rb', line 33 def icon_position @icon_position end |
#label ⇒ Object
Returns the value of attribute label.
33 34 35 |
# File 'app/helpers/view_component/input_component/input_text_component.rb', line 33 def label @label end |
#name ⇒ Object
Returns the value of attribute name.
33 34 35 |
# File 'app/helpers/view_component/input_component/input_text_component.rb', line 33 def name @name end |
#size ⇒ Object
Returns the value of attribute size.
33 34 35 |
# File 'app/helpers/view_component/input_component/input_text_component.rb', line 33 def size @size end |
#subtext ⇒ Object
Returns the value of attribute subtext.
33 34 35 |
# File 'app/helpers/view_component/input_component/input_text_component.rb', line 33 def subtext @subtext end |
#type ⇒ Object
Returns the value of attribute type.
33 34 35 |
# File 'app/helpers/view_component/input_component/input_text_component.rb', line 33 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
33 34 35 |
# File 'app/helpers/view_component/input_component/input_text_component.rb', line 33 def value @value end |
Instance Method Details
#icon_size ⇒ Object
119 120 121 |
# File 'app/helpers/view_component/input_component/input_text_component.rb', line 119 def icon_size ICON_SIZE[size.to_sym] end |
#icon_style ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 |
# File 'app/helpers/view_component/input_component/input_text_component.rb', line 107 def icon_style base = ['input-text-icon-base'] color_style = if disabled 'text-disabled-color' elsif error.present? 'text-danger-dark' else 'text-disabled-color group-focus-within:text-letter-color' end class_list(base, '', color_style) end |
#input_style ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/helpers/view_component/input_component/input_text_component.rb', line 57 def input_style base = ['input-text-base'] color_style = if disabled 'text-disabled-color' elsif error.present? 'text-danger focus:text-danger-dark' else 'text-disabled-color focus:text-letter-color' end size_style = INPUT_SIZE_STYLE[size.to_sym] class_list(base, size_style, color_style) end |
#input_wrapper_style ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/helpers/view_component/input_component/input_text_component.rb', line 79 def input_wrapper_style base = ['input-text-div-base group'] color_style = if disabled 'border-disabled-color' elsif error.present? 'border-danger focus-within:border-danger-dark ring-danger-dark' else 'border-slate-grey-50 focus-within:border-primary ring-primary' end size_style = INPUT_WRAPPER_STYLES[size.to_sym] class_list(base, size_style, color_style) end |
#label_style ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/helpers/view_component/input_component/input_text_component.rb', line 93 def label_style base = [] color_style = if disabled 'text-disabled-color' elsif error.present? 'text-danger-dark' else 'text-letter-color-light group-focus-within:text-primary' end size_style = LABEL_STYLES[size.to_sym] class_list(base, size_style, color_style) end |
#placeholder ⇒ Object
71 72 73 |
# File 'app/helpers/view_component/input_component/input_text_component.rb', line 71 def placeholder [:placeholder] end |
#placeholder=(value) ⇒ Object
75 76 77 |
# File 'app/helpers/view_component/input_component/input_text_component.rb', line 75 def placeholder=(value) [:placeholder] = value end |
#subtext_style ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/helpers/view_component/input_component/input_text_component.rb', line 123 def subtext_style base = [] color_style = if disabled 'text-disabled-color' elsif error.present? 'text-danger-dark' else 'text-letter-color-light' end size_style = SUBTEXT_SIZE[size.to_sym] class_list(base, size_style, color_style) end |