Class: LightningUiKit::RadioGroupComponent
Instance Method Summary
collapse
Methods included from Labelable
#effective_label, #render_label?
Methods included from Errors
#error_messages, #has_errors?, #infer_errors_from_association
#merge_classes
#heroicon
Constructor Details
#initialize(name:, label: nil, form: nil, error: nil, description: nil, selected: nil, disabled: false, **options) ⇒ RadioGroupComponent
Returns a new instance of RadioGroupComponent.
7
8
9
10
11
12
13
14
15
16
|
# File 'app/components/lightning_ui_kit/radio_group_component.rb', line 7
def initialize(name:, label: nil, form: nil, error: nil, description: nil, selected: nil, disabled: false, **options)
@name = name
@label = label
@form = form
@error = error
@description = description
@selected = selected
@disabled = disabled
@options = options
end
|
Instance Method Details
#classes ⇒ Object
18
19
20
21
22
23
|
# File 'app/components/lightning_ui_kit/radio_group_component.rb', line 18
def classes
merge_classes([
"lui:[&>[data-slot=label]+[data-slot=description]]:mt-1 lui:[&>[data-slot=label]+[data-slot=options]]:mt-3 lui:[&>[data-slot=description]+[data-slot=options]]:mt-3 lui:[&>[data-slot=options]+[data-slot=error]]:mt-3 lui:*:data-[slot=label]:font-medium",
@options[:class]
].compact.join(" "))
end
|
#data ⇒ Object
25
26
27
28
29
|
# File 'app/components/lightning_ui_kit/radio_group_component.rb', line 25
def data
{
controller: "lui-radio-group"
}.merge(@options[:data] || {})
end
|
#description_data ⇒ Object
37
38
39
40
41
|
# File 'app/components/lightning_ui_kit/radio_group_component.rb', line 37
def description_data
{slot: "description"}.tap do |data|
data[:disabled] = "true" if @disabled
end
end
|
#error_data ⇒ Object
43
44
45
46
47
|
# File 'app/components/lightning_ui_kit/radio_group_component.rb', line 43
def error_data
{slot: "error"}.tap do |data|
data[:disabled] = "true" if @disabled
end
end
|
#label_data ⇒ Object
31
32
33
34
35
|
# File 'app/components/lightning_ui_kit/radio_group_component.rb', line 31
def label_data
{slot: "label"}.tap do |data|
data[:disabled] = "true" if @disabled
end
end
|
#render_hidden_field ⇒ Object
59
60
61
62
63
64
65
|
# File 'app/components/lightning_ui_kit/radio_group_component.rb', line 59
def render_hidden_field
if @form
@form.hidden_field(@name, value: @selected, data: {lui_radio_group_target: "field"})
else
helpers.hidden_field_tag(@name, @selected, data: {lui_radio_group_target: "field"})
end
end
|
#render_label ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'app/components/lightning_ui_kit/radio_group_component.rb', line 49
def render_label
return unless render_label?
tag.label(
effective_label,
class: "lui:text-base/6 lui:text-foreground lui:select-none lui:data-disabled:opacity-50 lui:sm:text-sm/6",
data: label_data
)
end
|
#selected?(value) ⇒ Boolean
67
68
69
|
# File 'app/components/lightning_ui_kit/radio_group_component.rb', line 67
def selected?(value)
@selected.to_s == value.to_s
end
|