sdr_view_components 0.19.0 → 0.19.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2022709968e8b976ee79e3e086b4a7e17210babd054ddb8167f8892a0381b02c
4
- data.tar.gz: c55ccadec5da2a76b69cf9f3fb0ace9849fe102b3125458ee635cd3b399ae6c6
3
+ metadata.gz: b7e98c7b84b43710c239985c71175d49be411cfd26f70cec388b2391893a798d
4
+ data.tar.gz: ba602671e45720b1b3f5bbe57e6e50d2f50a251a1c081b053d6c72b7f835b52e
5
5
  SHA512:
6
- metadata.gz: 53dd2d4b2a4f20b8a1d820648acd667aa510b0273d9f86a40f036057c4a80a6c6ebcd17328f8fb453d2ce17294bcfc7fe7bf6182577a131b9f3efac572ac35cc
7
- data.tar.gz: 2e4ed587465f79ec3d6544000e9bd2b1853d53c063f4c405a3119ddc278d69e3f4d27d47ea82eab0d41eb0db1a345393688d4d1cda93d8a027c25d818892fc07
6
+ metadata.gz: 96b5ab0fb01f11779ed608befef00b365cb34d20edbcf6e7ef7c872c3821c65094f5f16262faaf1823166be3af00ccc799c71877e6f195a396cc7d4dc589eb9b
7
+ data.tar.gz: e185afc99b4e87a0ae7da054dbbcca27e25ab3afb138dc8ef60fbed2aecdde83874fb30bb04d6aa3fa6134921dd5e726b592ff9bb74cfe2cda60ed3980be2ddc
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ComponentSupport
4
+ # Renders the icon of an icon button, whose accessible name is its visually hidden label.
5
+ module IconButtonSupport
6
+ def before_render
7
+ raise SdrViewComponents::Error::UnknownComponentIcon, "Unknown icon type: #{@icon}" unless button_icon?
8
+ end
9
+
10
+ # A nil icon is for a button whose classes draw its own icon (e.g., btn-close).
11
+ def button_icon
12
+ return if @icon.nil?
13
+
14
+ helpers.public_send(:"#{@icon}_icon", classes: @icon_classes, aria: { hidden: true })
15
+ end
16
+
17
+ private
18
+
19
+ def button_icon?
20
+ @icon.nil? || helpers.respond_to?(:"#{@icon}_icon")
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
- <%= render SdrViewComponents::Elements::ButtonComponent.new(classes:, variant: :'outline-primary', disabled:, **options) do %>
1
+ <%= render SdrViewComponents::Elements::ButtonComponent.new(classes:, variant:, disabled:, **options) do %>
2
2
  <%= button_icon %><span class="visually-hidden"><%= label %></span>
3
3
  <% end %>
@@ -4,9 +4,12 @@ module SdrViewComponents
4
4
  module Elements
5
5
  # Component for a button which is an icon
6
6
  class IconButtonComponent < BaseComponent
7
- def initialize(icon:, label:, classes: [], icon_classes: [], disabled: false, **options) # rubocop:disable Metrics/ParameterLists
7
+ include ComponentSupport::IconButtonSupport
8
+
9
+ def initialize(icon:, label:, variant: :'outline-primary', classes: [], icon_classes: [], disabled: false, **options) # rubocop:disable Metrics/ParameterLists
8
10
  @icon = icon
9
11
  @label = label
12
+ @variant = variant
10
13
  @classes = classes
11
14
  @icon_classes = icon_classes
12
15
  @disabled = disabled
@@ -14,25 +17,11 @@ module SdrViewComponents
14
17
  super()
15
18
  end
16
19
 
17
- def before_render
18
- raise SdrViewComponents::Error::UnknownComponentIcon, "Unknown icon type: #{@icon}" unless button_icon?
19
- end
20
-
21
- attr_reader :label, :options, :disabled
20
+ attr_reader :label, :variant, :options, :disabled
22
21
 
23
22
  def classes
24
23
  merge_classes(%w[icon-button border border-0], @classes)
25
24
  end
26
-
27
- def button_icon
28
- helpers.public_send(:"#{@icon}_icon", classes: @icon_classes)
29
- end
30
-
31
- private
32
-
33
- def button_icon?
34
- helpers.respond_to?(:"#{@icon}_icon")
35
- end
36
25
  end
37
26
  end
38
27
  end
@@ -4,6 +4,8 @@ module SdrViewComponents
4
4
  module Elements
5
5
  # Component for a button which is an icon and is wrapped in a form
6
6
  class IconButtonFormComponent < BaseComponent
7
+ include ComponentSupport::IconButtonSupport
8
+
7
9
  def initialize(link:, icon:, label:, variant: :'outline-primary', size: nil, classes: [], icon_classes: [], # rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
8
10
  method: :get, confirm: nil, top: true, data: {}, disabled: false, params: {})
9
11
  @link = link
@@ -22,10 +24,6 @@ module SdrViewComponents
22
24
  super()
23
25
  end
24
26
 
25
- def before_render
26
- raise SdrViewComponents::Error::UnknownComponentIcon, "Unknown icon type: #{@icon}" unless button_icon?
27
- end
28
-
29
27
  attr_reader :link, :params, :label
30
28
 
31
29
  def call
@@ -51,16 +49,6 @@ module SdrViewComponents
51
49
  data[:turbo_confirm] = @confirm if @confirm
52
50
  end
53
51
  end
54
-
55
- def button_icon
56
- helpers.public_send(:"#{@icon}_icon", classes: @icon_classes)
57
- end
58
-
59
- private
60
-
61
- def button_icon?
62
- helpers.respond_to?(:"#{@icon}_icon")
63
- end
64
52
  end
65
53
  end
66
54
  end
@@ -1,3 +1,3 @@
1
- <%= render SdrViewComponents::Elements::ButtonLinkComponent.new(classes:, variant: :'outline-primary', link:, disabled:, **options) do %>
1
+ <%= render SdrViewComponents::Elements::ButtonLinkComponent.new(classes:, variant:, link:, disabled:, **options) do %>
2
2
  <%= button_icon %><span class="visually-hidden"><%= label %></span>
3
3
  <% end %>
@@ -4,9 +4,13 @@ module SdrViewComponents
4
4
  module Elements
5
5
  # Component for a button which is an icon
6
6
  class IconButtonLinkComponent < BaseComponent
7
- def initialize(icon:, label:, classes: [], icon_classes: [], link: nil, disabled: false, **options) # rubocop:disable Metrics/ParameterLists
7
+ include ComponentSupport::IconButtonSupport
8
+
9
+ def initialize(icon:, label:, variant: :'outline-primary', classes: [], icon_classes: [], link: nil, # rubocop:disable Metrics/ParameterLists
10
+ disabled: false, **options)
8
11
  @icon = icon
9
12
  @label = label
13
+ @variant = variant
10
14
  @classes = classes
11
15
  @link = link
12
16
  @options = options
@@ -15,15 +19,11 @@ module SdrViewComponents
15
19
  super()
16
20
  end
17
21
 
18
- attr_reader :label, :link, :options, :disabled
22
+ attr_reader :label, :variant, :link, :options, :disabled
19
23
 
20
24
  def classes
21
25
  merge_classes(%w[icon-button border border-0], @classes)
22
26
  end
23
-
24
- def button_icon
25
- helpers.public_send(:"#{@icon}_icon", classes: @icon_classes)
26
- end
27
27
  end
28
28
  end
29
29
  end
@@ -1,8 +1,8 @@
1
1
  <%= tag.div class: classes do %>
2
2
  <% if image_path %>
3
- <%= tag.img src: image_path, alt: 'Spinner', class: spinner_classes, role: 'status', style: spinner_style, **spinner_options %>
3
+ <%= tag.img src: image_path, alt: '', class: spinner_classes, style: spinner_style, **spinner_options %>
4
4
  <% else %>
5
- <%= tag.div class: spinner_classes, role: 'status', style: spinner_style, **spinner_options %>
5
+ <%= tag.div class: spinner_classes, style: spinner_style, **spinner_options %>
6
6
  <% end %>
7
- <%= tag.div class: message_classes do %><%= message %><% end %>
7
+ <%= tag.div class: message_classes, role: 'status' do %><%= status_message %><% end %>
8
8
  <% end %>
@@ -4,10 +4,12 @@ module SdrViewComponents
4
4
  module Elements
5
5
  # It spins.
6
6
  class SpinnerComponent < BaseComponent
7
- def initialize(message: 'Loading...', message_classes: [], message_position: :right, hide_message: false, # rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
7
+ DEFAULT_MESSAGE = 'Loading...'
8
+
9
+ def initialize(message: DEFAULT_MESSAGE, message_classes: [], message_position: :right, hide_message: false, # rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
8
10
  image_path: nil, variant: nil, classes: [],
9
11
  height: nil, width: nil, speed: 0.75, spinner_classes: ['mx-2'], **spinner_options)
10
- @message = message
12
+ @message = message.presence
11
13
  @variant = variant
12
14
  @hide_message = hide_message
13
15
  @classes = classes
@@ -22,14 +24,19 @@ module SdrViewComponents
22
24
  super()
23
25
  end
24
26
 
25
- attr_reader :message, :image_path, :spinner_options
27
+ attr_reader :image_path, :spinner_options
28
+
29
+ # Never blank, so the status region always announces something.
30
+ def status_message
31
+ @message || DEFAULT_MESSAGE
32
+ end
26
33
 
27
34
  def spinner_classes
28
35
  merge_classes('spinner-border', variant_class, border_class, @spinner_classes)
29
36
  end
30
37
 
31
38
  def message_classes
32
- merge_classes(@message_classes, @hide_message ? 'visually-hidden' : nil)
39
+ merge_classes(@message_classes, hide_message? ? 'visually-hidden' : nil)
33
40
  end
34
41
 
35
42
  def classes
@@ -46,6 +53,10 @@ module SdrViewComponents
46
53
 
47
54
  private
48
55
 
56
+ def hide_message?
57
+ @hide_message || @message.nil?
58
+ end
59
+
49
60
  def message_position_classes
50
61
  case @message_position # rubocop:disable Style/HashLikeCase
51
62
  when :bottom
@@ -7,5 +7,5 @@
7
7
  },
8
8
  data:
9
9
  ) do %>
10
- <%= helpers.info_icon(fill: true) %>
10
+ <%= helpers.info_icon(fill: true, aria: { hidden: true }) %>
11
11
  <% end %>
@@ -14,15 +14,15 @@
14
14
  <ul class="list-unstyled fw-semibold">
15
15
  <li>
16
16
  <a href="https://library.stanford.edu/all-locations-and-hours">All locations and hours
17
- <i class="bi bi-arrow-right-short"></i></a>
17
+ <i class="bi bi-arrow-right-short" aria-hidden="true"></i></a>
18
18
  </li>
19
19
  <li>
20
20
  <a href="https://library.stanford.edu/">Library website
21
- <i class="bi bi-arrow-right-short"></i></a>
21
+ <i class="bi bi-arrow-right-short" aria-hidden="true"></i></a>
22
22
  </li>
23
23
  <li>
24
24
  <a href="https://mylibrary.stanford.edu">My Account
25
- <i class="bi bi-arrow-right-short"></i></a>
25
+ <i class="bi bi-arrow-right-short" aria-hidden="true"></i></a>
26
26
  </li>
27
27
  </ul>
28
28
  </section>
@@ -6,7 +6,7 @@
6
6
  <a class="su-brand-bar__logo" href="https://www.stanford.edu">Stanford University</a>
7
7
  </div>
8
8
  </div>
9
- <%= tag.nav class: collapsible_navbar_classes do %>
9
+ <%= tag.nav class: collapsible_navbar_classes, 'aria-label': primary_navigation_label do %>
10
10
  <div class="container">
11
11
  <%= render SdrViewComponents::Structure::HeaderSulLogoComponent.new(sul_logo:) %>
12
12
  <button
@@ -42,7 +42,7 @@
42
42
  </div>
43
43
  </div>
44
44
  <%= tag.div class: navbar_classes do %>
45
- <nav class="collapse navbar-collapse align-items-start justify-content-md-end navbar-expand-md d-md-flex flex-column flex-md-row" aria-label="browse" id="user-util-collapse">
45
+ <%= tag.nav class: 'collapse navbar-collapse align-items-start justify-content-md-end navbar-expand-md d-md-flex flex-column flex-md-row', 'aria-label': secondary_navigation_label, id: 'user-util-collapse' do %>
46
46
  <% if secondary_navigation_links.any? %>
47
47
  <hr class="d-md-none text-white vw-100 my-0">
48
48
  <ul class="navbar-nav justify-content-md-end gap-0 gap-md-4 w-100 fw-semibold">
@@ -57,7 +57,7 @@
57
57
  <%= link %>
58
58
  <% end %>
59
59
  </ul>
60
- </nav>
60
+ <% end %>
61
61
  <% end %>
62
62
  </div>
63
63
  </div>
@@ -25,17 +25,23 @@ module SdrViewComponents
25
25
  # Used only when variant is :dark.
26
26
  # param rosette [Boolean] Whether to show the rosette logo.
27
27
  # param sul_logo [String, nil] Optional URL for SUL logo image. (polychrome, stacked-lg, stacked-mobile)
28
- def initialize(title:, subtitle: nil, variant: :light, background_color: nil, rosette: true, sul_logo: nil) # rubocop:disable Metrics/ParameterLists
28
+ # param primary_navigation_label [String] aria-label for the top bar nav holding the primary links.
29
+ # param secondary_navigation_label [String] aria-label for the collapsible nav holding the secondary links.
30
+ def initialize(title:, subtitle: nil, variant: :light, background_color: nil, rosette: true, sul_logo: nil, # rubocop:disable Metrics/ParameterLists
31
+ primary_navigation_label: 'Utility', secondary_navigation_label: 'browse')
29
32
  @title = title
30
33
  @subtitle = subtitle
31
34
  @variant = variant
32
35
  @background_color = background_color
33
36
  @rosette = rosette
34
37
  @sul_logo = sul_logo
38
+ @primary_navigation_label = primary_navigation_label
39
+ @secondary_navigation_label = secondary_navigation_label
35
40
  super()
36
41
  end
37
42
 
38
- attr_reader :background_color, :rosette, :subtitle, :sul_logo, :title, :variant
43
+ attr_reader :background_color, :primary_navigation_label, :rosette,
44
+ :secondary_navigation_label, :subtitle, :sul_logo, :title, :variant
39
45
 
40
46
  def masthead_classes
41
47
  merge_classes('masthead', VARIANT_MASTHEAD_CLASS[variant])
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SdrViewComponents
4
- VERSION = '0.19.0'
4
+ VERSION = '0.19.1'
5
5
  end
@@ -11,6 +11,17 @@ module SdrViewComponents
11
11
  )
12
12
  end
13
13
 
14
+ # A button whose classes draw its own icon.
15
+ def without_icon
16
+ render SdrViewComponents::Elements::IconButtonLinkComponent.new(
17
+ icon: nil,
18
+ label: 'Remove item',
19
+ link: '/example',
20
+ classes: 'btn-close',
21
+ variant: nil
22
+ )
23
+ end
24
+
14
25
  # @!group Disabled State
15
26
  def enabled
16
27
  render SdrViewComponents::Elements::IconButtonLinkComponent.new(
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.19.0
4
+ version: 0.19.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Collier
@@ -65,6 +65,7 @@ files:
65
65
  - app/components/base_component.rb
66
66
  - app/components/component_support/button_support.rb
67
67
  - app/components/component_support/css_classes.rb
68
+ - app/components/component_support/icon_button_support.rb
68
69
  - app/components/sdr_view_components/elements/alert_component.html.erb
69
70
  - app/components/sdr_view_components/elements/alert_component.rb
70
71
  - app/components/sdr_view_components/elements/banner_component.html.erb