Class: Maglev::Uikit::Form::TextareaComponent

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

options: { value: nil, rows: 2, max_length: nil }



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

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

Instance Attribute Details

#html_optionsObject (readonly)

Returns the value of attribute html_options.



7
8
9
# File 'app/components/maglev/uikit/form/textarea_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/textarea_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/textarea_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/textarea_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/textarea_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/textarea_component.rb', line 7

def options
  @options
end

Instance Method Details

#dom_idObject



19
20
21
# File 'app/components/maglev/uikit/form/textarea_component.rb', line 19

def dom_id
  name.to_s.parameterize.underscore
end

#errorObject



47
48
49
# File 'app/components/maglev/uikit/form/textarea_component.rb', line 47

def error
  options[:error]
end

#max_lengthObject



35
36
37
# File 'app/components/maglev/uikit/form/textarea_component.rb', line 35

def max_length
  options[:max_length]
end

#max_length?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/components/maglev/uikit/form/textarea_component.rb', line 43

def max_length?
  max_length.present?
end

#num_charactersObject



39
40
41
# File 'app/components/maglev/uikit/form/textarea_component.rb', line 39

def num_characters
  value.to_s.length
end

#placeholderObject



23
24
25
# File 'app/components/maglev/uikit/form/textarea_component.rb', line 23

def placeholder
  options[:placeholder]
end

#rowsObject



31
32
33
# File 'app/components/maglev/uikit/form/textarea_component.rb', line 31

def rows
  options[:rows]
end

#valueObject



27
28
29
# File 'app/components/maglev/uikit/form/textarea_component.rb', line 27

def value
  options[:value]
end