sdr_view_components 0.17.0 → 0.18.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6fffa520e874d95db0c98e2154b4c6725d119919d9b58c723ed418d99ddf9f9e
4
- data.tar.gz: c6fea4f2e4a80fb4a2a9a81547d084c4c1900e30f6d1ca9bfdc0f35aacb387e8
3
+ metadata.gz: 5f59b6686400993be3c942c3f2b7c090fdb94c2e3f9aa7f5a6b83ba2818ec8dd
4
+ data.tar.gz: 7dea52d93f22c5aaca0e81dbd98abf50e12185cdffbd8a720b4dfc20801e5774
5
5
  SHA512:
6
- metadata.gz: e3c2ccadf81aaf8265e78a842c7eb6b4207a35c4f75b6026320dba695e240ab85182590d31a9b12782aef7ba68e6baa3a0d75112d226527fee48d04697c361b1
7
- data.tar.gz: 2ee11d5a9e3c2cf96a71a878e8e94cb05dcdaefac3b66943c8de2b16c43cbee156597e096264bc84fe13e5635bf12b64b01128431cccf3a59e6442e168145b40
6
+ metadata.gz: 7b5e0f8baac5f81b0fac04d9e44473c37e940def8cabe7f37625d84c840c8888d7a9fc7441b74d2c710c7bc621917577d6df96b5030ededaa3133f0671578553
7
+ data.tar.gz: 0d05f092127a49264b7418bb582722c15d246e3e2beb5dd1b95ecff4affc5ca19590aa800f5821a46884a27dac4112f59b2a48ce82f69fafb8dae5eaf2d48c16
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SdrViewComponents
4
- VERSION = '0.17.0'
4
+ VERSION = '0.18.0'
5
5
  end
@@ -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.17.0
4
+ version: 0.18.0
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