Class: LightningUiKit::SwitchComponent
Instance Method Summary
collapse
Methods included from Errors
#error_messages, #has_errors?, #infer_errors_from_association
#merge_classes
#heroicon
Constructor Details
#initialize(name:, form: nil, label: nil, error: nil, description: nil, enabled: false, disabled: false, **options) ⇒ SwitchComponent
Returns a new instance of SwitchComponent.
6
7
8
9
10
11
12
13
14
15
|
# File 'app/components/lightning_ui_kit/switch_component.rb', line 6
def initialize(name:, form: nil, label: nil, error: nil, description: nil, enabled: false, disabled: false, **options)
@name = name
@form = form
@label = label
@error = error
@description = description
@enabled = enabled
@disabled = disabled
@options = options
end
|
Instance Method Details
#data ⇒ Object
17
18
19
|
# File 'app/components/lightning_ui_kit/switch_component.rb', line 17
def data
default_data.merge(@options[:data] || {})
end
|
#default_data ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'app/components/lightning_ui_kit/switch_component.rb', line 21
def default_data
{
slot: "control",
action: "click->lui-switch#toggle"
}.tap do |data|
if @disabled
data[:disabled] = "true"
end
if @enabled
data[:checked] = "true"
end
end
end
|
#error_data ⇒ Object
35
36
37
38
39
40
41
|
# File 'app/components/lightning_ui_kit/switch_component.rb', line 35
def error_data
{slot: "error"}.merge(@options[:error_data] || {}).tap do |data|
if @disabled
data[:disabled] = "true"
end
end
end
|