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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bcec4cf002a116b2cd0892d277b5aace69a92b0c3fadb3da6cbb79b3f7e287ed
4
- data.tar.gz: 02f7514118e21301230aab72e81a648c646a6a0479aae2ecc96e1389fd04c75f
3
+ metadata.gz: aea28037c8a048d1fd92042e514fa46878c1aab6b7eeeef1aa818df89c3a23e4
4
+ data.tar.gz: aa0709d402ba1659a8095680845081c1e10d9a7e603b64cdca3736d25a3bd796
5
5
  SHA512:
6
- metadata.gz: ec955ffbc219f41a74ad74343ed098c2d06888a5977c7fae9e23345b6765ad34e96e33bcdaa3e40cbfcc8caeba982b9c816eef49dc6f5441e87a61cc031e71e1
7
- data.tar.gz: df56619d78fa80d26d0f73a0ad387b8e1f0d32f21916ea861a437fe345a2c8038066cf3188fe5ad44432e630c43469967405ee19b8a634038f81334b55884fba
6
+ metadata.gz: 45d4fb964f16be5118175cd7b94b3f64d0719a2d75d30e8bd85de931c5866e846ff54df39f731c5c702b0793bb6c4ed8bbca16250e489e37239b5644fe7c54f4
7
+ data.tar.gz: 88570ef44f95b099e9228b95e7bccadfc9b32ab33b44ff5c0e764feb6e62c3235fe395924d86a9d513a37d0480f6ff73420b3e313e523065cd03c589a6bd88b7
@@ -1,4 +1,4 @@
1
- <%= form.label field_name, class: classes do %>
1
+ <%= form.label field_name, class: classes, id: do %>
2
2
  <%= content || text %>
3
3
  <% end %>
4
4
  <%# This is outside the label so that clicking on it doesn't toggle some inputs like checkboxes. %>
@@ -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, type: 'radio', class: 'btn-check', data: %>
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
- def initialize(form:, field_name:, label:, value:, data: {}, position: :left) # rubocop:disable Metrics/ParameterLists
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'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SdrViewComponents
4
- VERSION = '0.23.3'
4
+ VERSION = '0.23.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sdr_view_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.3
4
+ version: 0.23.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Collier