sdr_view_components 0.22.0 → 0.23.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 +14 -0
- data/app/components/sdr_view_components/elements/button_component.rb +2 -0
- data/app/components/sdr_view_components/elements/link_toggle_component.html.erb +7 -0
- data/app/components/sdr_view_components/elements/link_toggle_component.rb +37 -0
- data/app/components/sdr_view_components/forms/toggle_component.rb +1 -0
- data/lib/sdr_view_components/version.rb +1 -1
- data/spec/components/previews/sdr_view_components/elements/link_toggle_component_preview.rb +17 -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: b3102801d311a012457cd19a83738bbcac342156ec8c29e0d4fa47e772785b38
|
|
4
|
+
data.tar.gz: 3fd97897e0a627b545bfd522d7563bbb46b47c48349a2d623c03aeb8c65286b4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b0a243260da7907878cd72fc031bf020c5e6579c29856eecaf957a4fa9ec6254c68745138f0189baf4588c2de2ab00b872653213927d854d6ddfb2dd9335101c
|
|
7
|
+
data.tar.gz: 3d20e40b35b6751d7ce5647b4f422c63e72d4deced01566032f1987958ff34a235f52fb5da536767bccca9631d29df41905a67eda4a58eeea98bdb88adae6504
|
data/README.md
CHANGED
|
@@ -312,6 +312,20 @@ SdrViewComponents provides components for building navigation bar items and drop
|
|
|
312
312
|
</ul>
|
|
313
313
|
```
|
|
314
314
|
|
|
315
|
+
### Link toggle component
|
|
316
|
+
|
|
317
|
+
`SdrViewComponents::Elements::LinkToggleComponent` renders a group of links styled like `Forms::ToggleComponent`, for navigation such as switching between views of a page (use `Forms::ToggleComponent` when the choice is a form field). Each link is a hash of `label:`, `path:` and `selected:`; other keys are passed to `link_to`. The selected link gets the `active` class and `aria-current="page"`. `label:` is the group's accessible name and `classes:` adds classes to the container.
|
|
318
|
+
|
|
319
|
+
```erb
|
|
320
|
+
<%= render SdrViewComponents::Elements::LinkToggleComponent.new(
|
|
321
|
+
label: 'Select view',
|
|
322
|
+
links: [
|
|
323
|
+
{ label: 'List view', path: list_path, selected: true },
|
|
324
|
+
{ label: 'Grid view', path: grid_path, selected: false }
|
|
325
|
+
]
|
|
326
|
+
) %>
|
|
327
|
+
```
|
|
328
|
+
|
|
315
329
|
## Component library version
|
|
316
330
|
The [component-library](https://github.com/sul-dlss/component-library/) version is set in `lib/sdr_view_components/configuration.rb`.
|
|
317
331
|
|
|
@@ -22,6 +22,8 @@ module SdrViewComponents
|
|
|
22
22
|
class: ComponentSupport::ButtonSupport.classes(variant: @variant, size: @size, classes: @classes,
|
|
23
23
|
bordered: @bordered, disabled: @disabled),
|
|
24
24
|
type: 'button',
|
|
25
|
+
# The class only styles the button; the attribute keeps it from being focused or clicked.
|
|
26
|
+
disabled: @disabled,
|
|
25
27
|
**options
|
|
26
28
|
) do
|
|
27
29
|
label || content
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SdrViewComponents
|
|
4
|
+
module Elements
|
|
5
|
+
# Component for a toggle-like group of links, e.g., for switching between views of the same page.
|
|
6
|
+
#
|
|
7
|
+
# Switching views is navigation, not data entry, so this renders links rather than a radio group
|
|
8
|
+
# The design mirrors Forms::ToggleComponent so the .toggle-radio
|
|
9
|
+
# styles apply to the links, with .active (and aria-current) in place of :checked.
|
|
10
|
+
class LinkToggleComponent < BaseComponent
|
|
11
|
+
# @param links [Array<Hash>] one entry per link, with :label, :path and :selected (Boolean);
|
|
12
|
+
# any other keys are passed on to link_to
|
|
13
|
+
# @param label [String] the accessible name of the group (e.g., 'Select view')
|
|
14
|
+
# @param classes [Array<String>, String] additional classes for the container
|
|
15
|
+
def initialize(links:, label:, classes: [])
|
|
16
|
+
@links = links
|
|
17
|
+
@label = label
|
|
18
|
+
@classes = classes
|
|
19
|
+
super()
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
attr_reader :links, :label
|
|
23
|
+
|
|
24
|
+
def container_classes
|
|
25
|
+
merge_classes('toggle-radio', @classes)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# @return [Hash] the link_to options for a link
|
|
29
|
+
def link_options(link)
|
|
30
|
+
link.except(:label, :path, :selected).merge(
|
|
31
|
+
class: merge_classes('btn rounded-pill', link[:selected] ? 'active' : nil),
|
|
32
|
+
'aria-current': link[:selected] ? 'page' : nil
|
|
33
|
+
)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
module SdrViewComponents
|
|
4
4
|
module Forms
|
|
5
5
|
# Component for a toggle-like radio button group field
|
|
6
|
+
# The design mirrors Elements::LinkToggleComponent, which uses links for navigation
|
|
6
7
|
class ToggleComponent < FieldComponent
|
|
7
8
|
renders_one :left_toggle_option, lambda { |**args|
|
|
8
9
|
Forms::ToggleOptionComponent.new(position: :left, **args)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SdrViewComponents
|
|
4
|
+
module Elements
|
|
5
|
+
class LinkToggleComponentPreview < ViewComponent::Preview
|
|
6
|
+
def default
|
|
7
|
+
render SdrViewComponents::Elements::LinkToggleComponent.new(
|
|
8
|
+
label: 'Select view',
|
|
9
|
+
links: [
|
|
10
|
+
{ label: 'List view', path: '/example/list', selected: true },
|
|
11
|
+
{ label: 'Grid view', path: '/example/grid', selected: false }
|
|
12
|
+
]
|
|
13
|
+
)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
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.23.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Aaron Collier
|
|
@@ -88,6 +88,8 @@ files:
|
|
|
88
88
|
- app/components/sdr_view_components/elements/icon_button_form_component.rb
|
|
89
89
|
- app/components/sdr_view_components/elements/icon_button_link_component.html.erb
|
|
90
90
|
- app/components/sdr_view_components/elements/icon_button_link_component.rb
|
|
91
|
+
- app/components/sdr_view_components/elements/link_toggle_component.html.erb
|
|
92
|
+
- app/components/sdr_view_components/elements/link_toggle_component.rb
|
|
91
93
|
- app/components/sdr_view_components/elements/modal_component.html.erb
|
|
92
94
|
- app/components/sdr_view_components/elements/modal_component.rb
|
|
93
95
|
- app/components/sdr_view_components/elements/nav_link_component.html.erb
|
|
@@ -219,6 +221,7 @@ files:
|
|
|
219
221
|
- spec/components/previews/sdr_view_components/elements/icon_button_component_preview.rb
|
|
220
222
|
- spec/components/previews/sdr_view_components/elements/icon_button_form_component_preview.rb
|
|
221
223
|
- spec/components/previews/sdr_view_components/elements/icon_button_link_component_preview.rb
|
|
224
|
+
- spec/components/previews/sdr_view_components/elements/link_toggle_component_preview.rb
|
|
222
225
|
- spec/components/previews/sdr_view_components/elements/modal_component_preview.rb
|
|
223
226
|
- spec/components/previews/sdr_view_components/elements/modal_component_preview/default.html.erb
|
|
224
227
|
- spec/components/previews/sdr_view_components/elements/modal_component_preview/with_header_and_footer.html.erb
|