Class: Arara::TextFieldComponent
- Inherits:
-
ActionView::Component::Base
- Object
- ActionView::Component::Base
- Arara::TextFieldComponent
- Includes:
- BaseComponent
- Defined in:
- app/components/arara/text_field_component.rb
Instance Attribute Summary collapse
-
#full_width ⇒ Object
readonly
Returns the value of attribute full_width.
-
#helper_text ⇒ Object
readonly
Returns the value of attribute helper_text.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#placeholder ⇒ Object
readonly
Returns the value of attribute placeholder.
-
#textarea ⇒ Object
readonly
Returns the value of attribute textarea.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #data_controller ⇒ Object
- #default_data_controller ⇒ Object
- #default_html_class ⇒ Object
- #has_error? ⇒ Boolean
- #helper_line_class ⇒ Object
- #helper_text_class ⇒ Object
- #html_input_options ⇒ Object
- #html_input_tag ⇒ Object
- #html_options ⇒ Object
-
#initialize(variant: "default", label: nil, helper_text: nil, max_length: nil, textarea: false, id:, name: nil, value: nil, full_width: false, has_error: false, type: "text", placeholder: nil, **kw) ⇒ TextFieldComponent
constructor
A new instance of TextFieldComponent.
- #is_outlined? ⇒ Boolean
- #is_textarea? ⇒ Boolean
Methods included from BaseComponent
#default_html_tag, #html_class, #html_content, #html_data, #html_tag, included
Constructor Details
#initialize(variant: "default", label: nil, helper_text: nil, max_length: nil, textarea: false, id:, name: nil, value: nil, full_width: false, has_error: false, type: "text", placeholder: nil, **kw) ⇒ TextFieldComponent
Returns a new instance of TextFieldComponent.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/components/arara/text_field_component.rb', line 9 def initialize(variant: "default", label: nil, helper_text: nil, max_length: nil, textarea: false, id:, name: nil, value: nil, full_width: false, has_error: false, type: "text", placeholder: nil, **kw) super(tag: "div", variant: variant, **kw) @label = label @helper_text = helper_text @max_length = max_length @textarea = textarea @id = id @name = name @value = value @full_width = full_width @has_error = has_error @user_variant = "outlined" if textarea @type = type @placeholder = placeholder end |
Instance Attribute Details
#full_width ⇒ Object (readonly)
Returns the value of attribute full_width.
5 6 7 |
# File 'app/components/arara/text_field_component.rb', line 5 def full_width @full_width end |
#helper_text ⇒ Object (readonly)
Returns the value of attribute helper_text.
5 6 7 |
# File 'app/components/arara/text_field_component.rb', line 5 def helper_text @helper_text end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'app/components/arara/text_field_component.rb', line 5 def id @id end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
5 6 7 |
# File 'app/components/arara/text_field_component.rb', line 5 def label @label end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'app/components/arara/text_field_component.rb', line 5 def name @name end |
#placeholder ⇒ Object (readonly)
Returns the value of attribute placeholder.
5 6 7 |
# File 'app/components/arara/text_field_component.rb', line 5 def placeholder @placeholder end |
#textarea ⇒ Object (readonly)
Returns the value of attribute textarea.
5 6 7 |
# File 'app/components/arara/text_field_component.rb', line 5 def textarea @textarea end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'app/components/arara/text_field_component.rb', line 5 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'app/components/arara/text_field_component.rb', line 5 def value @value end |
Instance Method Details
#data_controller ⇒ Object
90 91 92 |
# File 'app/components/arara/text_field_component.rb', line 90 def data_controller "mdc-text-field" end |
#default_data_controller ⇒ Object
85 86 87 88 |
# File 'app/components/arara/text_field_component.rb', line 85 def default_data_controller "mdc-text-field" nil end |
#default_html_class ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'app/components/arara/text_field_component.rb', line 30 def default_html_class classes = ["mdc-text-field"] classes << "mdc-text-field--fullwidth" if full_width classes << "mdc-text-field--textarea" if is_textarea? classes << "mdc-text-field--error" if has_error? classes << "mdc-text-field--outlined" if user_variant == "outlined" classes.join(" ") end |
#has_error? ⇒ Boolean
26 27 28 |
# File 'app/components/arara/text_field_component.rb', line 26 def has_error? @has_error end |
#helper_line_class ⇒ Object
74 75 76 77 78 |
# File 'app/components/arara/text_field_component.rb', line 74 def helper_line_class classes = ["mdc-text-field-helper-line"] classes << "mdc-text-field-helper-line--error" if has_error? classes.join(" ") end |
#helper_text_class ⇒ Object
80 81 82 83 |
# File 'app/components/arara/text_field_component.rb', line 80 def helper_text_class classes = ["mdc-text-field-helper-text mdc-text-field-helper-text--persistent mdc-text-field-helper-text--validation-msg"] classes.join(" ") end |
#html_input_options ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/components/arara/text_field_component.rb', line 53 def opts = { class: "mdc-text-field__input", id: id, type: type, aria: { labelledby: "#{id}-label", controls: "#{id}-helper", describedby: "#{id}-helper" } } opts.merge!(name: name) if name opts.merge!(value: value) if value opts[:data] = opts.has_key?(:data) ? opts[:data] : {} opts[:data][:action] = "focusin->#{data_controller}#handleFocus" opts.merge!(placeholder: placeholder) if placeholder # opts.merge!(rows: 4, cols: 40) if textarea opts.merge!(maxlength: max_length) if max_length opts end |
#html_input_tag ⇒ Object
48 49 50 51 |
# File 'app/components/arara/text_field_component.rb', line 48 def html_input_tag return "textarea" if textarea "input" end |
#html_options ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'app/components/arara/text_field_component.rb', line 39 def opts = super opts.deep_symbolize_keys! opts[:data] = opts.has_key?(:data) ? opts[:data] : {} opts[:data][:target] = opts[:data].has_key?(:target) ? opts[:data][:target] : "" opts[:data][:target].concat(" #{data_controller}.element") opts end |
#is_outlined? ⇒ Boolean
94 95 96 |
# File 'app/components/arara/text_field_component.rb', line 94 def is_outlined? user_variant == "outlined" && is_textarea? end |
#is_textarea? ⇒ Boolean
98 99 100 |
# File 'app/components/arara/text_field_component.rb', line 98 def is_textarea? textarea end |