sdr_view_components 0.23.3 → 0.23.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/components/sdr_view_components/forms/label_component.html.erb +1 -1
- data/app/components/sdr_view_components/forms/label_component.rb +4 -3
- data/app/components/sdr_view_components/forms/toggle_component.html.erb +2 -2
- data/app/components/sdr_view_components/forms/toggle_component.rb +5 -0
- data/app/components/sdr_view_components/forms/toggle_option_component.html.erb +1 -1
- data/app/components/sdr_view_components/forms/toggle_option_component.rb +8 -1
- data/lib/sdr_view_components/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: aea28037c8a048d1fd92042e514fa46878c1aab6b7eeeef1aa818df89c3a23e4
|
|
4
|
+
data.tar.gz: aa0709d402ba1659a8095680845081c1e10d9a7e603b64cdca3736d25a3bd796
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 45d4fb964f16be5118175cd7b94b3f64d0719a2d75d30e8bd85de931c5866e846ff54df39f731c5c702b0793bb6c4ed8bbca16250e489e37239b5644fe7c54f4
|
|
7
|
+
data.tar.gz: 88570ef44f95b099e9228b95e7bccadfc9b32ab33b44ff5c0e764feb6e62c3235fe395924d86a9d513a37d0480f6ff73420b3e313e523065cd03c589a6bd88b7
|
|
@@ -4,9 +4,10 @@ module SdrViewComponents
|
|
|
4
4
|
module Forms
|
|
5
5
|
# Component for rendering a form label.
|
|
6
6
|
class LabelComponent < BaseComponent
|
|
7
|
-
def initialize(form:, field_name:, text: nil, default_class: 'form-label', hidden: false, # rubocop:disable Metrics/ParameterLists
|
|
8
|
-
classes: [], tooltip: nil, caption: nil, mark_required: false)
|
|
7
|
+
def initialize(form:, field_name:, text: nil, default_class: 'form-label', hidden: false, # rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
|
|
8
|
+
classes: [], tooltip: nil, caption: nil, mark_required: false, id: nil)
|
|
9
9
|
@form = form
|
|
10
|
+
@id = id
|
|
10
11
|
@text = text
|
|
11
12
|
@field_name = field_name
|
|
12
13
|
@hidden = hidden
|
|
@@ -18,7 +19,7 @@ module SdrViewComponents
|
|
|
18
19
|
super()
|
|
19
20
|
end
|
|
20
21
|
|
|
21
|
-
attr_reader :field_name, :form, :tooltip, :caption, :mark_required
|
|
22
|
+
attr_reader :field_name, :form, :tooltip, :caption, :mark_required, :id
|
|
22
23
|
|
|
23
24
|
def text
|
|
24
25
|
mark_label_required(label: @text.presence || field_name, mark_required:)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<%= tag.div(class: container_classes, **container_args) do %>
|
|
2
2
|
<div class="d-flex"> <%# Aligns label and tooltip %>
|
|
3
|
-
<%= render SdrViewComponents::Forms::LabelComponent.new(form:, field_name:, **label_args) %>
|
|
3
|
+
<%= render SdrViewComponents::Forms::LabelComponent.new(form:, field_name:, id: label_id, **label_args) %>
|
|
4
4
|
</div>
|
|
5
|
-
<div class="btn-group btn-group-toggle" role="group">
|
|
5
|
+
<div class="btn-group btn-group-toggle" role="group" aria-labelledby="<%= label_id %>">
|
|
6
6
|
<%= left_toggle_option %>
|
|
7
7
|
<%= right_toggle_option %>
|
|
8
8
|
</div>
|
|
@@ -21,6 +21,11 @@ module SdrViewComponents
|
|
|
21
21
|
|
|
22
22
|
attr_reader :form, :field_name
|
|
23
23
|
|
|
24
|
+
# The label names the radio group, since it has no single input to point at.
|
|
25
|
+
def label_id
|
|
26
|
+
form.field_id(field_name, 'label')
|
|
27
|
+
end
|
|
28
|
+
|
|
24
29
|
# toggle-radio applies the component library's toggle styles.
|
|
25
30
|
def container_classes
|
|
26
31
|
merge_classes('toggle-radio', super)
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
<%= form.radio_button field_name, value,
|
|
1
|
+
<%= form.radio_button field_name, value, **radio_options %>
|
|
2
2
|
<%= form.label(field_name, label, value:, class: label_classes) %>
|
|
@@ -4,7 +4,8 @@ module SdrViewComponents
|
|
|
4
4
|
module Forms
|
|
5
5
|
# Component for a toggle option
|
|
6
6
|
class ToggleOptionComponent < BaseComponent
|
|
7
|
-
|
|
7
|
+
# @param checked [Boolean, nil] overrides the checked state, which otherwise comes from the form's object
|
|
8
|
+
def initialize(form:, field_name:, label:, value:, data: {}, position: :left, checked: nil) # rubocop:disable Metrics/ParameterLists
|
|
8
9
|
raise ArgumentError, 'position must be :left or :right' unless %i[left right].include?(position)
|
|
9
10
|
|
|
10
11
|
@form = form
|
|
@@ -13,11 +14,17 @@ module SdrViewComponents
|
|
|
13
14
|
@value = value
|
|
14
15
|
@data = data
|
|
15
16
|
@position = position
|
|
17
|
+
@checked = checked
|
|
16
18
|
super()
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
attr_reader :form, :field_name, :label, :value, :data
|
|
20
22
|
|
|
23
|
+
# Rails treats a checked key, even nil, as an override, so it is only passed when given.
|
|
24
|
+
def radio_options
|
|
25
|
+
{ type: 'radio', class: 'btn-check', data:, checked: @checked }.compact
|
|
26
|
+
end
|
|
27
|
+
|
|
21
28
|
# The component library's toggle-radio styles round each option, so no rounding classes are added here.
|
|
22
29
|
def label_classes
|
|
23
30
|
'btn'
|