sdr_view_components 0.1.9 → 0.1.10

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: 1afffad2e6ed29d15558f17747dede5386da6e4535767947fb6b1970985f436e
4
- data.tar.gz: 60a9a0124d9d480c4194933f1548d1e2dd2b499d67ef6254199afc3e8e734abe
3
+ metadata.gz: 296ea41f2742301fbcbfe4e4997327a0a88f9062789f0e987298b023704695b8
4
+ data.tar.gz: b763fa492037241155bb55464d27437d3316df043b3c8cafc86e4e72d51f29a8
5
5
  SHA512:
6
- metadata.gz: ef3eb4a9b57b8664d1d4991c7707094e2bbe21760fee98bb400a752e6400663460214b8a8d085b9848ca5eae9f1c753bce68f093f637fecb369657829309920d
7
- data.tar.gz: '0229b05c83c16f0d3404efe05369dd8b6b2de73286c8b0b9c8c0568febfb82abc853e8dc812ae738f68fd808016281cad65ff0606c7376ab1a72b15c8a5f57d8'
6
+ metadata.gz: fed14277e8b2afcc9e8a2ba17dcd7b42cf44c1396b7b93aa2b0ef90a6880de1eb43840f87fa308a1eeea3c4431be25e75969bccfd0cb384cef88a488c3912f31
7
+ data.tar.gz: f0b094384fa97b827ccd899fe40e3deb03cdf180ff9165ca2cc78dba1b8dd35d60c4a1fd19e71e79b7cc36b8d1f0022eca271b469a0509bb9211268fa638f5c3
@@ -1,12 +1,12 @@
1
1
  <%= tag.div role:, class: classes, data:, id: do %>
2
2
  <% if icon? %>
3
- <%= tag.div class: icon_classes, role: 'img', 'aria-label': "#{variant} alert icon" %>
3
+ <div class="fs-3 me-3 align-self-center d-flex justify-content-center"><%= icon %></div>
4
4
  <% end %>
5
5
  <div class="text-body">
6
6
  <% if title.present? %>
7
7
  <div class="fw-semibold"><%= title %></div>
8
8
  <% end %>
9
- <%= content %>
9
+ <%= content || text %>
10
10
  </div>
11
11
  <% if dismissible? %>
12
12
  <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
@@ -4,34 +4,24 @@ module SdrViewComponents
4
4
  module Elements
5
5
  # Component for rendering an alert.
6
6
  class AlertComponent < BaseComponent
7
- # NOTE: This component has been altered from the H3 version.
8
-
9
- ICONS = {
10
- danger: 'bi bi-exclamation-triangle-fill',
11
- success: 'bi bi-check-circle-fill',
12
- note: 'bi bi-exclamation-circle-fill',
13
- info: 'bi bi-info-circle-fill',
14
- warning: 'bi bi-exclamation-triangle-fill'
15
- }.freeze
16
-
17
7
  # Variants are :danger, :success, :note, :info, :warning, :input
18
8
  # input is not part of the component library
19
- def initialize(title: nil, variant: :info, dismissible: false, data: {}, classes: [], id: nil, # rubocop:disable Metrics/ParameterLists
20
- role: 'alert')
21
- raise ArgumentError, 'Invalid variant' unless %i[danger success note info warning
22
- input].include?(variant.to_sym)
9
+ def initialize(title: nil, variant: :info, dismissible: false, # rubocop:disable Metrics/ParameterLists
10
+ data: {}, classes: [], id: nil, role: 'alert', text: nil)
11
+ raise ArgumentError, 'Invalid variant' unless %i[danger success note info warning input].include?(variant.to_sym)
23
12
 
24
13
  @title = title
25
- @variant = variant.to_sym
14
+ @variant = variant
26
15
  @dismissible = dismissible
27
16
  @data = data
28
17
  @classes = classes
29
18
  @id = id
30
19
  @role = role
20
+ @text = text
31
21
  super()
32
22
  end
33
23
 
34
- attr_reader :title, :variant, :data, :id, :role
24
+ attr_reader :title, :variant, :data, :id, :role, :text
35
25
 
36
26
  def classes
37
27
  merge_classes(%w[alert d-flex shadow-sm align-items-center], variant_class, dismissible_class, @classes)
@@ -50,15 +40,15 @@ module SdrViewComponents
50
40
  end
51
41
 
52
42
  def icon?
53
- ICONS.key?(variant)
43
+ helpers.respond_to?(:"#{variant}_icon")
54
44
  end
55
45
 
56
- def icon_classes
57
- merge_classes('fs-3 me-3 align-self-center d-flex justify-content-center', ICONS[variant])
46
+ def icon
47
+ helpers.public_send(:"#{variant}_icon", role: 'img', aria: { label: "#{variant} alert icon" })
58
48
  end
59
49
 
60
50
  def render?
61
- title.present? || content.present?
51
+ title.present? || content.present? || text.present?
62
52
  end
63
53
  end
64
54
  end
@@ -17,7 +17,7 @@ module SdrViewComponents
17
17
  }
18
18
 
19
19
  def page_title_from_breadcrumbs
20
- breadcrumbs.filter_map(&:truncated_text).unshift('SDR').join(' | ')
20
+ CGI.unescapeHTML(breadcrumbs.filter_map(&:truncated_text).unshift('SDR').join(' | '))
21
21
  end
22
22
  end
23
23
  end
@@ -21,5 +21,11 @@ module SdrViewComponents
21
21
  app.config.assets.paths << Engine.root.join('app', 'assets', 'stylesheets').to_s
22
22
  app.config.assets.precompile += %w[sdr_view_components.css]
23
23
  end
24
+
25
+ initializer 'sdr_view_components.helpers' do
26
+ ActiveSupport.on_load(:action_view) do
27
+ include SdrViewComponents::Helpers
28
+ end
29
+ end
24
30
  end
25
31
  end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SdrViewComponents
4
+ # Helpers module for the SDR View Components gem
5
+ module Helpers
6
+ # Helper for rendering icons.
7
+ module IconHelper
8
+ extend ActionView::Helpers::TagHelper
9
+
10
+ def icon(icon_classes:, classes: nil, **)
11
+ all_classes = ComponentSupport::CssClasses.merge(icon_classes, classes)
12
+ content_tag(:i, nil, class: all_classes, **)
13
+ end
14
+
15
+ def right_arrow_icon(**)
16
+ icon(icon_classes: 'bi bi-arrow-right', **)
17
+ end
18
+
19
+ def danger_icon(**)
20
+ icon(icon_classes: 'bi bi-exclamation-triangle-fill', **)
21
+ end
22
+
23
+ def note_icon(**)
24
+ icon(icon_classes: 'bi bi-exclamation-circle-fill', **)
25
+ end
26
+
27
+ def success_icon(**)
28
+ icon(icon_classes: 'bi bi-check-circle-fill', **)
29
+ end
30
+
31
+ def info_icon(fill: true, **)
32
+ icon(icon_classes: ['bi', fill ? 'bi-info-circle-fill' : 'bi-info-circle'], **)
33
+ end
34
+
35
+ def warning_icon(**)
36
+ icon(icon_classes: 'bi bi-exclamation-triangle-fill', **)
37
+ end
38
+
39
+ def delete_icon(**)
40
+ icon(icon_classes: 'bi bi-trash', **)
41
+ end
42
+
43
+ def edit_icon(**)
44
+ icon(icon_classes: 'bi bi-pencil', **)
45
+ end
46
+
47
+ def first_icon(**)
48
+ icon(icon_classes: 'bi bi-chevron-double-left', **)
49
+ end
50
+
51
+ def last_icon(**)
52
+ icon(icon_classes: 'bi bi-chevron-double-right', **)
53
+ end
54
+
55
+ def next_icon(**)
56
+ icon(icon_classes: 'bi bi-chevron-right', **)
57
+ end
58
+
59
+ def previous_icon(**)
60
+ icon(icon_classes: 'bi bi-chevron-left', **)
61
+ end
62
+
63
+ def upload_icon(fill: true, **)
64
+ icon(icon_classes: ['bi', fill ? 'bi-cloud-upload-fill' : 'bi-cloud-upload'], **)
65
+ end
66
+
67
+ def move_up_icon(**)
68
+ icon(icon_classes: 'bi bi-arrow-up', **)
69
+ end
70
+
71
+ def move_down_icon(**)
72
+ icon(icon_classes: 'bi bi-arrow-down', **)
73
+ end
74
+
75
+ def calendar_icon(**)
76
+ icon(icon_classes: 'bi bi-calendar', **)
77
+ end
78
+
79
+ def search_icon(**)
80
+ icon(icon_classes: 'bi bi-search', **)
81
+ end
82
+
83
+ def bulb_icon(**)
84
+ icon(icon_classes: 'bi bi-lightbulb', **)
85
+ end
86
+
87
+ def quote_icon(**)
88
+ icon(icon_classes: 'bi bi-quote', **)
89
+ end
90
+
91
+ def download_icon(**)
92
+ icon(icon_classes: 'bi bi-download', **)
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SdrViewComponents
4
+ # Helpers module for the SDR View Components gem
5
+ module Helpers
6
+ include IconHelper
7
+ end
8
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SdrViewComponents
4
- VERSION = '0.1.9'
4
+ VERSION = '0.1.10'
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sdr_view_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Collier
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-01-06 00:00:00.000000000 Z
10
+ date: 2026-02-24 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rails
@@ -126,6 +126,8 @@ files:
126
126
  - config/routes.rb
127
127
  - lib/sdr_view_components.rb
128
128
  - lib/sdr_view_components/engine.rb
129
+ - lib/sdr_view_components/helpers.rb
130
+ - lib/sdr_view_components/helpers/icon_helper.rb
129
131
  - lib/sdr_view_components/version.rb
130
132
  homepage: https://github.com/sul-dlss/sdr_view_components
131
133
  licenses: []