Class: Maglev::Uikit::Form::TextFieldComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/maglev/uikit/form/text_field_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label:, name:, options: {}, html_options: {}) ⇒ TextFieldComponent

options: { value: nil, placeholder: nil, error: nil } html_options: { data: { attribute: ‘value’ } }



11
12
13
14
15
16
17
18
# File 'app/components/maglev/uikit/form/text_field_component.rb', line 11

def initialize(label:, name:, options: {}, html_options: {})
  @label = label
  @name = name
  @options = options
  @html_options = html_options
  @input_data = html_options.delete(:data) || {}
  @input_action = input_data.delete(:action) || {}
end

Instance Attribute Details

#html_optionsObject (readonly)

Returns the value of attribute html_options.



7
8
9
# File 'app/components/maglev/uikit/form/text_field_component.rb', line 7

def html_options
  @html_options
end

#input_actionObject (readonly)

Returns the value of attribute input_action.



7
8
9
# File 'app/components/maglev/uikit/form/text_field_component.rb', line 7

def input_action
  @input_action
end

#input_dataObject (readonly)

Returns the value of attribute input_data.



7
8
9
# File 'app/components/maglev/uikit/form/text_field_component.rb', line 7

def input_data
  @input_data
end

#labelObject (readonly)

Returns the value of attribute label.



7
8
9
# File 'app/components/maglev/uikit/form/text_field_component.rb', line 7

def label
  @label
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'app/components/maglev/uikit/form/text_field_component.rb', line 7

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'app/components/maglev/uikit/form/text_field_component.rb', line 7

def options
  @options
end

Instance Method Details

#dom_idObject



20
21
22
# File 'app/components/maglev/uikit/form/text_field_component.rb', line 20

def dom_id
  name.to_s.parameterize.underscore
end

#errorObject



36
37
38
# File 'app/components/maglev/uikit/form/text_field_component.rb', line 36

def error
  options[:error]
end

#hintObject



28
29
30
# File 'app/components/maglev/uikit/form/text_field_component.rb', line 28

def hint
  options[:hint]
end

#placeholderObject



32
33
34
# File 'app/components/maglev/uikit/form/text_field_component.rb', line 32

def placeholder
  options[:placeholder]
end

#valueObject



24
25
26
# File 'app/components/maglev/uikit/form/text_field_component.rb', line 24

def value
  options[:value]
end