sdr_view_components 0.17.0 → 0.18.1
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 +11 -0
- data/app/assets/sdr_view_components.css +21 -0
- data/app/components/sdr_view_components/elements/collapsible_section_component.html.erb +11 -0
- data/app/components/sdr_view_components/elements/collapsible_section_component.rb +32 -0
- data/app/components/sdr_view_components/tab_form/tabbed_form_builder.rb +16 -1
- data/lib/sdr_view_components/version.rb +1 -1
- data/spec/components/previews/sdr_view_components/elements/collapsible_section_component_preview.rb +25 -0
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5de046f013212327fcf03eefd5dcbdaa0918dc20a8a33687036d6802ec5f98fe
|
|
4
|
+
data.tar.gz: afe2f59fef8352750a73ee9327e5e39d253571dc7792aa887208b5b072465611
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6452476e378e3df685166323eac91b36a6df362e9b2db163b2fd4dbc4365b7211cab17ede65438b82ad9a9a8133a027372aee706cf2acc24af544a301f803c32
|
|
7
|
+
data.tar.gz: ad821a7e03619fb08e414ddcef5143e59399c11b4c3b6e2899334684cbbeba48a0b35ba62ea9b571c74e129435c57e20d37cba43ebe5cda2d543f3c0b3075c88
|
data/README.md
CHANGED
|
@@ -228,6 +228,17 @@ See the Lookbook preview for `SdrViewComponents::TabForm::TabListComponent` for
|
|
|
228
228
|
<% render SdrViewComponent::....>
|
|
229
229
|
```
|
|
230
230
|
|
|
231
|
+
### Collapsible section component
|
|
232
|
+
|
|
233
|
+
`SdrViewComponents::Elements::CollapsibleSectionComponent` renders a heading that shows / hides the section content using Bootstrap's collapse. The `id:` is used for the collapsed content and must be unique on the page. It is expanded unless `expanded: false` is given.
|
|
234
|
+
|
|
235
|
+
```erb
|
|
236
|
+
<%= render SdrViewComponents::Elements::CollapsibleSectionComponent.new(id: 'pages', heading: 'Pages (12)', level: :h3,
|
|
237
|
+
heading_classes: 'text-uppercase') do %>
|
|
238
|
+
<p>Section content.</p>
|
|
239
|
+
<% end %>
|
|
240
|
+
```
|
|
241
|
+
|
|
231
242
|
### Navigation components
|
|
232
243
|
|
|
233
244
|
SdrViewComponents provides components for building navigation bar items and dropdown menus:
|
|
@@ -176,6 +176,27 @@ fieldset.form-fieldset legend {
|
|
|
176
176
|
padding-bottom: 80px;
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
+
/* Collapsible section */
|
|
180
|
+
.collapsible-section-toggle {
|
|
181
|
+
display: inline-flex;
|
|
182
|
+
align-items: center;
|
|
183
|
+
gap: 0.5rem;
|
|
184
|
+
padding: 0;
|
|
185
|
+
border: 0;
|
|
186
|
+
background: none;
|
|
187
|
+
color: inherit;
|
|
188
|
+
font: inherit;
|
|
189
|
+
text-transform: inherit;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
.collapsible-section-icon {
|
|
193
|
+
transition: transform 0.2s ease-in-out;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.collapsible-section-toggle.collapsed .collapsible-section-icon {
|
|
197
|
+
transform: rotate(180deg);
|
|
198
|
+
}
|
|
199
|
+
|
|
179
200
|
/* Tables */
|
|
180
201
|
table.table-h3 caption {
|
|
181
202
|
padding: .25rem;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<%= tag.section class: classes do %>
|
|
2
|
+
<%= render SdrViewComponents::Elements::HeadingComponent.new(level:, classes: heading_classes) do %>
|
|
3
|
+
<%= tag.button type: 'button', class: toggle_classes, data: { bs_toggle: 'collapse', bs_target: "##{id}" }, aria: { expanded:, controls: id } do %>
|
|
4
|
+
<%= helpers.icon(icon_classes: 'bi bi-chevron-up', classes: 'collapsible-section-icon', aria: { hidden: true }) %>
|
|
5
|
+
<%= heading %>
|
|
6
|
+
<% end %>
|
|
7
|
+
<% end %>
|
|
8
|
+
<%= tag.div id:, class: collapse_classes do %>
|
|
9
|
+
<%= content %>
|
|
10
|
+
<% end %>
|
|
11
|
+
<% end %>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SdrViewComponents
|
|
4
|
+
module Elements
|
|
5
|
+
# Component for a section whose heading toggles (Bootstrap collapse) the display of its content.
|
|
6
|
+
class CollapsibleSectionComponent < BaseComponent
|
|
7
|
+
def initialize(id:, heading:, level: :h2, expanded: true, classes: [], heading_classes: []) # rubocop:disable Metrics/ParameterLists
|
|
8
|
+
@id = id
|
|
9
|
+
@heading = heading
|
|
10
|
+
@level = level
|
|
11
|
+
@expanded = expanded
|
|
12
|
+
@classes = classes
|
|
13
|
+
@heading_classes = heading_classes
|
|
14
|
+
super()
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
attr_reader :id, :heading, :level, :expanded, :heading_classes
|
|
18
|
+
|
|
19
|
+
def classes
|
|
20
|
+
merge_classes('collapsible-section', @classes)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def toggle_classes
|
|
24
|
+
merge_classes('collapsible-section-toggle', expanded ? nil : 'collapsed')
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def collapse_classes
|
|
28
|
+
merge_classes('collapse', expanded ? 'show' : nil)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -30,12 +30,27 @@ module SdrViewComponents
|
|
|
30
30
|
|
|
31
31
|
def select(method, choices = nil, options = {}, html_options = {}, &)
|
|
32
32
|
html_options[:form] ||= id
|
|
33
|
-
super
|
|
33
|
+
return super unless html_options[:multiple] && options.fetch(:include_hidden, true)
|
|
34
|
+
|
|
35
|
+
# Rails' hidden blank input (so that selecting nothing is submitted) doesn't get the form attribute.
|
|
36
|
+
select_hidden_field(method, html_options) +
|
|
37
|
+
super(method, choices, options.merge(include_hidden: false), html_options, &)
|
|
34
38
|
end
|
|
35
39
|
|
|
36
40
|
def id
|
|
37
41
|
super || options[:parent_builder]&.id
|
|
38
42
|
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
def select_hidden_field(method, html_options)
|
|
47
|
+
hidden_options = { value: '', multiple: true, form: html_options[:form], name: html_options[:name],
|
|
48
|
+
disabled: html_options[:disabled] }.compact
|
|
49
|
+
# Without an id, so that it doesn't duplicate the select's.
|
|
50
|
+
hidden_options[:id] = nil
|
|
51
|
+
hidden_options[:autocomplete] = 'off' unless ActionView::Base.remove_hidden_field_autocomplete
|
|
52
|
+
hidden_field(method, hidden_options)
|
|
53
|
+
end
|
|
39
54
|
end
|
|
40
55
|
end
|
|
41
56
|
end
|
data/spec/components/previews/sdr_view_components/elements/collapsible_section_component_preview.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SdrViewComponents
|
|
4
|
+
module Elements
|
|
5
|
+
class CollapsibleSectionComponentPreview < ViewComponent::Preview
|
|
6
|
+
def expanded
|
|
7
|
+
render SdrViewComponents::Elements::CollapsibleSectionComponent.new(id: 'expanded-section',
|
|
8
|
+
heading: 'Pages (2)',
|
|
9
|
+
level: :h3,
|
|
10
|
+
heading_classes: 'text-uppercase') do
|
|
11
|
+
'Section content goes here.'
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def collapsed
|
|
16
|
+
render SdrViewComponents::Elements::CollapsibleSectionComponent.new(id: 'collapsed-section',
|
|
17
|
+
heading: 'Supplemental files (1)',
|
|
18
|
+
level: :h3,
|
|
19
|
+
expanded: false) do
|
|
20
|
+
'Section content goes here.'
|
|
21
|
+
end
|
|
22
|
+
end
|
|
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.18.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Aaron Collier
|
|
@@ -78,6 +78,8 @@ files:
|
|
|
78
78
|
- app/components/sdr_view_components/elements/button_link_component.rb
|
|
79
79
|
- app/components/sdr_view_components/elements/card_component.html.erb
|
|
80
80
|
- app/components/sdr_view_components/elements/card_component.rb
|
|
81
|
+
- app/components/sdr_view_components/elements/collapsible_section_component.html.erb
|
|
82
|
+
- app/components/sdr_view_components/elements/collapsible_section_component.rb
|
|
81
83
|
- app/components/sdr_view_components/elements/heading_component.rb
|
|
82
84
|
- app/components/sdr_view_components/elements/horizontal_rule_component.rb
|
|
83
85
|
- app/components/sdr_view_components/elements/icon_button_component.html.erb
|
|
@@ -200,6 +202,7 @@ files:
|
|
|
200
202
|
- spec/components/previews/sdr_view_components/elements/button_form_component_preview.rb
|
|
201
203
|
- spec/components/previews/sdr_view_components/elements/button_link_component_preview.rb
|
|
202
204
|
- spec/components/previews/sdr_view_components/elements/card_component_preview.rb
|
|
205
|
+
- spec/components/previews/sdr_view_components/elements/collapsible_section_component_preview.rb
|
|
203
206
|
- spec/components/previews/sdr_view_components/elements/heading_component_preview.rb
|
|
204
207
|
- spec/components/previews/sdr_view_components/elements/horizontal_rule_component_preview.rb
|
|
205
208
|
- spec/components/previews/sdr_view_components/elements/horizontal_rule_component_preview/default.html.erb
|