Class: ViewComponent::InputComponent::TextareaComponent
- Inherits:
-
Object
- Object
- ViewComponent::InputComponent::TextareaComponent
- Includes:
- ComponentHelper
- Defined in:
- app/helpers/view_component/input_component/textarea_component.rb
Constant Summary collapse
- TEXTAREA_SIZES =
%w[md lg].freeze
- TEXTAREA_SIZE_STYLE =
{ md: 'textarea-component-md main-text-md-normal', lg: 'textarea-component-lg main-text-lg-medium' }.freeze
- LABEL_STYLES =
{ md: 'general-text-sm-normal', lg: 'general-text-md-normal' }.freeze
- SUPPORT_TEXT_STYLES =
{ md: 'general-text-sm-normal px-3', lg: 'general-text-md-normal px-3 md:px-4' }.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.
-
#label ⇒ Object
Returns the value of attribute label.
-
#name ⇒ Object
Returns the value of attribute name.
-
#placeholder ⇒ Object
Returns the value of attribute placeholder.
-
#rows ⇒ Object
Returns the value of attribute rows.
-
#size ⇒ Object
Returns the value of attribute size.
-
#support_text ⇒ Object
Returns the value of attribute support_text.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(form:, name:, label:, placeholder:, value:, rows:, size:, support_text:, error:, disabled:, html_options:) ⇒ TextareaComponent
constructor
A new instance of TextareaComponent.
- #label_style ⇒ Object
- #support_text_style ⇒ Object
- #textarea_style ⇒ Object
Methods included from ComponentHelper
Constructor Details
#initialize(form:, name:, label:, placeholder:, value:, rows:, size:, support_text:, error:, disabled:, html_options:) ⇒ TextareaComponent
Returns a new instance of TextareaComponent.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/helpers/view_component/input_component/textarea_component.rb', line 28 def initialize(form:, name:, label:, placeholder:, value:, rows:, size:, support_text:, error:, disabled:, html_options:) raise "Incorrect textarea size: #{size}" unless TEXTAREA_SIZES.include?(size) = resolve_error(form, name, error) self.form = form self.name = name self.label = label self.placeholder = placeholder self.value = value self.rows = rows self.size = size self.support_text = (.presence || support_text) self.error = self.disabled = disabled self. = self.[:placeholder] = placeholder self.[:rows] ||= rows self.[:disabled] = true if disabled self.[:class] = textarea_style end |
Instance Attribute Details
#disabled ⇒ Object
Returns the value of attribute disabled.
25 26 27 |
# File 'app/helpers/view_component/input_component/textarea_component.rb', line 25 def disabled @disabled end |
#error ⇒ Object
Returns the value of attribute error.
25 26 27 |
# File 'app/helpers/view_component/input_component/textarea_component.rb', line 25 def error @error end |
#form ⇒ Object
Returns the value of attribute form.
25 26 27 |
# File 'app/helpers/view_component/input_component/textarea_component.rb', line 25 def form @form end |
#html_options ⇒ Object
Returns the value of attribute html_options.
25 26 27 |
# File 'app/helpers/view_component/input_component/textarea_component.rb', line 25 def @html_options end |
#label ⇒ Object
Returns the value of attribute label.
25 26 27 |
# File 'app/helpers/view_component/input_component/textarea_component.rb', line 25 def label @label end |
#name ⇒ Object
Returns the value of attribute name.
25 26 27 |
# File 'app/helpers/view_component/input_component/textarea_component.rb', line 25 def name @name end |
#placeholder ⇒ Object
Returns the value of attribute placeholder.
25 26 27 |
# File 'app/helpers/view_component/input_component/textarea_component.rb', line 25 def placeholder @placeholder end |
#rows ⇒ Object
Returns the value of attribute rows.
25 26 27 |
# File 'app/helpers/view_component/input_component/textarea_component.rb', line 25 def rows @rows end |
#size ⇒ Object
Returns the value of attribute size.
25 26 27 |
# File 'app/helpers/view_component/input_component/textarea_component.rb', line 25 def size @size end |
#support_text ⇒ Object
Returns the value of attribute support_text.
25 26 27 |
# File 'app/helpers/view_component/input_component/textarea_component.rb', line 25 def support_text @support_text end |
#value ⇒ Object
Returns the value of attribute value.
25 26 27 |
# File 'app/helpers/view_component/input_component/textarea_component.rb', line 25 def value @value end |
Instance Method Details
#label_style ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/helpers/view_component/input_component/textarea_component.rb', line 68 def label_style base = ['textarea-label'] size_style = LABEL_STYLES[size.to_sym] color_style = if disabled 'text-disabled-color' elsif error.present? 'text-danger-dark' else 'text-letter-color-light group-focus-within:text-primary' end class_list(base, size_style, color_style) end |
#support_text_style ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/helpers/view_component/input_component/textarea_component.rb', line 84 def support_text_style base = ['textarea-support-text'] size_style = SUPPORT_TEXT_STYLES[size.to_sym] color_style = if disabled 'text-disabled-color' elsif error.present? 'text-danger-dark' else 'text-slate-grey-50' end class_list(base, size_style, color_style) end |
#textarea_style ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/helpers/view_component/input_component/textarea_component.rb', line 52 def textarea_style base = ['textarea-component-base field-sizing-content'] size_style = TEXTAREA_SIZE_STYLE[size.to_sym] color_style = if disabled 'textarea-disabled-state' elsif error.present? 'textarea-error-state' else 'textarea-active-state' end class_list(base, size_style, color_style) end |