sdr_view_components 0.6.0 → 0.7.0
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/README.md +4 -0
- data/app/assets/sdr_view_components.css +8 -0
- data/app/components/sdr_view_components/forms/fieldset_component.html.erb +17 -0
- data/app/components/sdr_view_components/forms/fieldset_component.rb +43 -0
- data/app/components/sdr_view_components/forms/has_one_component.html.erb +7 -0
- data/app/components/sdr_view_components/forms/has_one_component.rb +30 -0
- data/app/components/sdr_view_components/tab_form/tabbed_form_builder.rb +1 -1
- data/lib/sdr_view_components/version.rb +1 -1
- data/spec/components/previews/sdr_view_components/forms/checkbox_component_preview/with_validation_error.html.erb +1 -0
- data/spec/components/previews/sdr_view_components/forms/fieldset_component_preview/default.html.erb +10 -0
- data/spec/components/previews/sdr_view_components/forms/fieldset_component_preview/hidden_label.html.erb +6 -0
- data/spec/components/previews/sdr_view_components/forms/fieldset_component_preview/mark_required.html.erb +6 -0
- data/spec/components/previews/sdr_view_components/forms/fieldset_component_preview/with_help_link.html.erb +9 -0
- data/spec/components/previews/sdr_view_components/forms/fieldset_component_preview/with_help_text.html.erb +9 -0
- data/spec/components/previews/sdr_view_components/forms/fieldset_component_preview/with_legend_slot.html.erb +9 -0
- data/spec/components/previews/sdr_view_components/forms/fieldset_component_preview/with_tooltip.html.erb +9 -0
- data/spec/components/previews/sdr_view_components/forms/fieldset_component_preview.rb +25 -0
- data/spec/components/previews/sdr_view_components/forms/radio_button_component_preview/with_validation_error.html.erb +1 -0
- metadata +13 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 20d06b21754a66cf773ed738934dca7b897e95de724e6ca8fc70942f56a8bf1c
|
|
4
|
+
data.tar.gz: 605b5ae6c58e73324e9bdbbac7d53ff6e0ddf9d53b845c75393255d411ef701d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b99a2ffdfb693b1780e6b44b93a51d0ba6ab62e9958336056ccacd59fd5e4b5d063961bcfe55d688d0b5c907ea0fc323872808cdd52743c1dfe44b7ceb676a39
|
|
7
|
+
data.tar.gz: 17849d2bfd15fd3e540ed8a6e0307825c00efbf53143836c2547d10f5a812ac490b71b5ae0cb0007aced34068b68debfe9970449633d8005969018497869ba29
|
data/README.md
CHANGED
|
@@ -125,6 +125,10 @@ Each of the supported components above uses the provided "basic" components:
|
|
|
125
125
|
|
|
126
126
|
At a minimum, each of these components must be provided wih the `form:` and `field_name:` parameters. Additionally, you can provide additional parameters that will be passed to the standard ActionView::Helpers::Tag.
|
|
127
127
|
|
|
128
|
+
#### Fieldset component
|
|
129
|
+
|
|
130
|
+
`SdrViewComponents::Forms::FieldsetComponent` renders a `<fieldset>` for grouping related fields (e.g. a set of checkboxes) that don't belong to a single bound form field. It supports a `label:` (or a `legend` slot for custom markup), `tooltip:`, `mark_required:`, `help_text:`, and a `help_link` slot. Any other keyword arguments (`id:`, `data:`, `aria:`, etc.) are passed through to the `<fieldset>` tag.
|
|
131
|
+
|
|
128
132
|
### Tab form components
|
|
129
133
|
|
|
130
134
|
SdrViewComponents provides components for rendering a tabbed form, where a form's fields are split across tabs rather than shown all at once:
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<%= tag.fieldset class: classes, **options do %>
|
|
2
|
+
<% if legend? || label %>
|
|
3
|
+
<%= tag.legend class: legend_classes do %>
|
|
4
|
+
<% if legend? %>
|
|
5
|
+
<%= legend %>
|
|
6
|
+
<% else %>
|
|
7
|
+
<%= tag.label class: label_classes do %><%= label %><% end %>
|
|
8
|
+
<% end %>
|
|
9
|
+
<%= render SdrViewComponents::Elements::TooltipComponent.new(target_label: label, tooltip:) %>
|
|
10
|
+
<%= help_link if help_link? %>
|
|
11
|
+
<% if help_text.present? %>
|
|
12
|
+
<p class="mb-2"><%= help_text %></p>
|
|
13
|
+
<% end %>
|
|
14
|
+
<% end %>
|
|
15
|
+
<% end %>
|
|
16
|
+
<%= content %>
|
|
17
|
+
<% end %>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SdrViewComponents
|
|
4
|
+
module Forms
|
|
5
|
+
# Component for rendering a form fieldset.
|
|
6
|
+
class FieldsetComponent < BaseComponent
|
|
7
|
+
renders_one :legend # Provide legend or label
|
|
8
|
+
renders_one :help_link # Optional
|
|
9
|
+
|
|
10
|
+
def initialize(label: nil, hidden_label: false, classes: [], label_classes: [], legend_classes: [], # rubocop:disable Metrics/ParameterLists
|
|
11
|
+
tooltip: nil, mark_required: false, help_text: nil, **options)
|
|
12
|
+
@label = label
|
|
13
|
+
@hidden_label = hidden_label
|
|
14
|
+
@classes = classes
|
|
15
|
+
@label_classes = label_classes
|
|
16
|
+
@legend_classes = legend_classes
|
|
17
|
+
@tooltip = tooltip
|
|
18
|
+
@options = options
|
|
19
|
+
@mark_required = mark_required
|
|
20
|
+
@help_text = help_text
|
|
21
|
+
super()
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
attr_reader :options, :tooltip, :mark_required, :help_text
|
|
25
|
+
|
|
26
|
+
def label_classes
|
|
27
|
+
merge_classes(@label_classes, @hidden_label ? 'visually-hidden' : 'form-label fw-bold')
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def label
|
|
31
|
+
mark_label_required(label: @label, mark_required:) if @label.present?
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def classes
|
|
35
|
+
merge_classes('form-fieldset', @classes)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def legend_classes
|
|
39
|
+
merge_classes(@legend_classes)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<%= render SdrViewComponents::Forms::FieldsetComponent.new(**fieldset_args) do %>
|
|
2
|
+
<%= tag.div class: 'mb-3' do %>
|
|
3
|
+
<%= form.fields_for field_name do |nested_form| %>
|
|
4
|
+
<%= render form_component.new(form: nested_form, **form_component_args) %>
|
|
5
|
+
<% end %>
|
|
6
|
+
<% end %>
|
|
7
|
+
<% end %>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SdrViewComponents
|
|
4
|
+
module Forms
|
|
5
|
+
# Encapsulates a has_one (non-repeatable) form.
|
|
6
|
+
class HasOneComponent < BaseComponent
|
|
7
|
+
def initialize(form:, field_name:, form_component:, **args)
|
|
8
|
+
@form = form
|
|
9
|
+
@field_name = field_name
|
|
10
|
+
@form_component = form_component
|
|
11
|
+
@args = args
|
|
12
|
+
super()
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
attr_reader :form, :field_name, :form_component, :args
|
|
16
|
+
|
|
17
|
+
# Returns a hash of arguments for the fieldset component.
|
|
18
|
+
# Includes argument prefixed with 'fieldset_'.
|
|
19
|
+
def fieldset_args
|
|
20
|
+
args_for(args:, prefix: 'fieldset_')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Returns a hash of arguments for the form component.
|
|
24
|
+
# Includes argument prefixed with 'form_'.
|
|
25
|
+
def form_component_args
|
|
26
|
+
args_for(args:, prefix: 'form_')
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -14,7 +14,7 @@ module SdrViewComponents
|
|
|
14
14
|
# created via `fields_for`, by falling back to the parent builder's `id`. Rails' `fields_for`
|
|
15
15
|
# doesn't otherwise propagate the `html: { id: }` option to nested builders.
|
|
16
16
|
class TabbedFormBuilder < ActionView::Helpers::FormBuilder
|
|
17
|
-
FIELD_METHODS = %i[text_field email_field textarea text_area hidden_field file_field radio_button
|
|
17
|
+
FIELD_METHODS = %i[text_field email_field textarea text_area hidden_field file_field radio_button check_box
|
|
18
18
|
date_field].freeze
|
|
19
19
|
|
|
20
20
|
FIELD_METHODS.each do |field_method|
|
data/spec/components/previews/sdr_view_components/forms/fieldset_component_preview/default.html.erb
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<%= render SdrViewComponents::Forms::FieldsetComponent.new(label: 'Contributors') do %>
|
|
2
|
+
<div class="form-check">
|
|
3
|
+
<input class="form-check-input" type="checkbox" id="contributor1" name="contributor1">
|
|
4
|
+
<label class="form-check-label" for="contributor1">Jane Stanford</label>
|
|
5
|
+
</div>
|
|
6
|
+
<div class="form-check">
|
|
7
|
+
<input class="form-check-input" type="checkbox" id="contributor2" name="contributor2">
|
|
8
|
+
<label class="form-check-label" for="contributor2">Leland Stanford</label>
|
|
9
|
+
</div>
|
|
10
|
+
<% end %>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<%= render SdrViewComponents::Forms::FieldsetComponent.new(label: 'Contributors', hidden_label: true) do %>
|
|
2
|
+
<div class="form-check">
|
|
3
|
+
<input class="form-check-input" type="checkbox" id="contributor1" name="contributor1">
|
|
4
|
+
<label class="form-check-label" for="contributor1">Jane Stanford</label>
|
|
5
|
+
</div>
|
|
6
|
+
<% end %>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<%= render SdrViewComponents::Forms::FieldsetComponent.new(label: 'Contributors', mark_required: true) do %>
|
|
2
|
+
<div class="form-check">
|
|
3
|
+
<input class="form-check-input" type="checkbox" id="contributor1" name="contributor1">
|
|
4
|
+
<label class="form-check-label" for="contributor1">Jane Stanford</label>
|
|
5
|
+
</div>
|
|
6
|
+
<% end %>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<%= render SdrViewComponents::Forms::FieldsetComponent.new(label: 'Contributors') do |component| %>
|
|
2
|
+
<% component.with_help_link do %>
|
|
3
|
+
<a href="#" class="ms-2">What is a contributor?</a>
|
|
4
|
+
<% end %>
|
|
5
|
+
<div class="form-check">
|
|
6
|
+
<input class="form-check-input" type="checkbox" id="contributor1" name="contributor1">
|
|
7
|
+
<label class="form-check-label" for="contributor1">Jane Stanford</label>
|
|
8
|
+
</div>
|
|
9
|
+
<% end %>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<%= render SdrViewComponents::Forms::FieldsetComponent.new(
|
|
2
|
+
label: 'Contributors',
|
|
3
|
+
help_text: 'Add every contributor who created this resource.'
|
|
4
|
+
) do %>
|
|
5
|
+
<div class="form-check">
|
|
6
|
+
<input class="form-check-input" type="checkbox" id="contributor1" name="contributor1">
|
|
7
|
+
<label class="form-check-label" for="contributor1">Jane Stanford</label>
|
|
8
|
+
</div>
|
|
9
|
+
<% end %>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<%= render SdrViewComponents::Forms::FieldsetComponent.new do |component| %>
|
|
2
|
+
<% component.with_legend do %>
|
|
3
|
+
<span class="form-label fw-bold">Contributors <em>(custom legend markup)</em></span>
|
|
4
|
+
<% end %>
|
|
5
|
+
<div class="form-check">
|
|
6
|
+
<input class="form-check-input" type="checkbox" id="contributor1" name="contributor1">
|
|
7
|
+
<label class="form-check-label" for="contributor1">Jane Stanford</label>
|
|
8
|
+
</div>
|
|
9
|
+
<% end %>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<%= render SdrViewComponents::Forms::FieldsetComponent.new(
|
|
2
|
+
label: 'Contributors',
|
|
3
|
+
tooltip: 'Select every contributor who created this resource.'
|
|
4
|
+
) do %>
|
|
5
|
+
<div class="form-check">
|
|
6
|
+
<input class="form-check-input" type="checkbox" id="contributor1" name="contributor1">
|
|
7
|
+
<label class="form-check-label" for="contributor1">Jane Stanford</label>
|
|
8
|
+
</div>
|
|
9
|
+
<% end %>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SdrViewComponents
|
|
4
|
+
module Forms
|
|
5
|
+
class FieldsetComponentPreview < ViewComponent::Preview
|
|
6
|
+
def default; end
|
|
7
|
+
|
|
8
|
+
# @!group Label options
|
|
9
|
+
def hidden_label; end
|
|
10
|
+
|
|
11
|
+
def mark_required; end
|
|
12
|
+
|
|
13
|
+
def with_tooltip; end
|
|
14
|
+
|
|
15
|
+
def with_legend_slot; end
|
|
16
|
+
# @!endgroup
|
|
17
|
+
|
|
18
|
+
# @!group Help
|
|
19
|
+
def with_help_text; end
|
|
20
|
+
|
|
21
|
+
def with_help_link; end
|
|
22
|
+
# @!endgroup
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
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.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Aaron Collier
|
|
@@ -117,7 +117,11 @@ files:
|
|
|
117
117
|
- app/components/sdr_view_components/forms/checkbox_component.rb
|
|
118
118
|
- app/components/sdr_view_components/forms/field_component.html.erb
|
|
119
119
|
- app/components/sdr_view_components/forms/field_component.rb
|
|
120
|
+
- app/components/sdr_view_components/forms/fieldset_component.html.erb
|
|
121
|
+
- app/components/sdr_view_components/forms/fieldset_component.rb
|
|
120
122
|
- app/components/sdr_view_components/forms/file_component.rb
|
|
123
|
+
- app/components/sdr_view_components/forms/has_one_component.html.erb
|
|
124
|
+
- app/components/sdr_view_components/forms/has_one_component.rb
|
|
121
125
|
- app/components/sdr_view_components/forms/help_text_component.html.erb
|
|
122
126
|
- app/components/sdr_view_components/forms/help_text_component.rb
|
|
123
127
|
- app/components/sdr_view_components/forms/invalid_feedback_component.rb
|
|
@@ -242,6 +246,14 @@ files:
|
|
|
242
246
|
- spec/components/previews/sdr_view_components/forms/checkbox_component_preview/with_help_text.html.erb
|
|
243
247
|
- spec/components/previews/sdr_view_components/forms/checkbox_component_preview/with_label.html.erb
|
|
244
248
|
- spec/components/previews/sdr_view_components/forms/checkbox_component_preview/with_validation_error.html.erb
|
|
249
|
+
- spec/components/previews/sdr_view_components/forms/fieldset_component_preview.rb
|
|
250
|
+
- spec/components/previews/sdr_view_components/forms/fieldset_component_preview/default.html.erb
|
|
251
|
+
- spec/components/previews/sdr_view_components/forms/fieldset_component_preview/hidden_label.html.erb
|
|
252
|
+
- spec/components/previews/sdr_view_components/forms/fieldset_component_preview/mark_required.html.erb
|
|
253
|
+
- spec/components/previews/sdr_view_components/forms/fieldset_component_preview/with_help_link.html.erb
|
|
254
|
+
- spec/components/previews/sdr_view_components/forms/fieldset_component_preview/with_help_text.html.erb
|
|
255
|
+
- spec/components/previews/sdr_view_components/forms/fieldset_component_preview/with_legend_slot.html.erb
|
|
256
|
+
- spec/components/previews/sdr_view_components/forms/fieldset_component_preview/with_tooltip.html.erb
|
|
245
257
|
- spec/components/previews/sdr_view_components/forms/file_component_preview.rb
|
|
246
258
|
- spec/components/previews/sdr_view_components/forms/file_component_preview/default.html.erb
|
|
247
259
|
- spec/components/previews/sdr_view_components/forms/file_component_preview/with_additional_container_content.html.erb
|