Class: LightningUiKit::TextareaComponent

Inherits:
BaseComponent
  • Object
show all
Includes:
Errors
Defined in:
app/components/lightning_ui_kit/textarea_component.rb

Instance Method Summary collapse

Methods included from Errors

#error_messages, #has_errors?, #infer_errors_from_association

Methods inherited from BaseComponent

#merge_classes

Methods included from HeroiconHelper

#heroicon

Constructor Details

#initialize(name:, value: nil, autofocus: false, label: nil, form: nil, type: :text, error: nil, description: nil, disabled: false, multiple: false, rows: 3, cols: nil, **options) ⇒ TextareaComponent

Returns a new instance of TextareaComponent.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/components/lightning_ui_kit/textarea_component.rb', line 6

def initialize(name:, value: nil, autofocus: false, label: nil, form: nil, type: :text, error: nil, description: nil, disabled: false, multiple: false, rows: 3, cols: nil, **options)
  @name = name
  @value = value
  @disabled = disabled
  @autofocus = autofocus
  @rows = rows
  @multiple = multiple
  @cols = cols
  @error = error
  @label = label
  @form = form
  @type = type
  @description = description
  @options = options
end

Instance Method Details

#dataObject



22
23
24
# File 'app/components/lightning_ui_kit/textarea_component.rb', line 22

def data
  @options[:data] || {}
end

#description_dataObject



42
43
44
45
46
47
48
# File 'app/components/lightning_ui_kit/textarea_component.rb', line 42

def description_data
  {slot: "description"}.merge(@options[:description_data] || {}).tap do |data|
    if @disabled
      data[:disabled] = "true"
    end
  end
end

#error_dataObject



50
51
52
53
54
55
56
# File 'app/components/lightning_ui_kit/textarea_component.rb', line 50

def error_data
  {slot: "error"}.merge(@options[:error_data] || {}).tap do |data|
    if @disabled
      data[:disabled] = "true"
    end
  end
end

#input_dataObject



26
27
28
29
30
31
32
# File 'app/components/lightning_ui_kit/textarea_component.rb', line 26

def input_data
  (@options[:input_data] || {}).tap do |data|
    if has_errors?
      data[:invalid] = "true"
    end
  end
end

#label_dataObject



34
35
36
37
38
39
40
# File 'app/components/lightning_ui_kit/textarea_component.rb', line 34

def label_data
  {slot: "label"}.merge(@options[:label_data] || {}).tap do |data|
    if @disabled
      data[:disabled] = "true"
    end
  end
end