sdr_view_components 0.1.8 → 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: 6ed77ab15d611e21337871d3d410b784454ec8e1a356fe91050b2250d7bc7d14
4
- data.tar.gz: 10f9d789b3ca10d8b1bef44adf1dbb61639267115340f6d113d08d2d70d54002
3
+ metadata.gz: 296ea41f2742301fbcbfe4e4997327a0a88f9062789f0e987298b023704695b8
4
+ data.tar.gz: b763fa492037241155bb55464d27437d3316df043b3c8cafc86e4e72d51f29a8
5
5
  SHA512:
6
- metadata.gz: 05475af8c2288f5f14ccfc0590fdb86374f530df207cf3fd82aa877d2377dbc91af5fde8742db8a74b16f6ef3dd1135a03450ec0a0bc083d0e4d4de404656844
7
- data.tar.gz: fe4975a4869e202997e972c67999d66f9e729e7edc0e26f68ab83aaa7b6690579b6e0fa06a263f083c42f0fad2e81c1fead6d527235079dedb6fae7ff7c6e0b8
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
@@ -7,6 +7,10 @@ module SdrViewComponents
7
7
  def call
8
8
  form.file_field field_name, class: classes, **args
9
9
  end
10
+
11
+ def classes
12
+ merge_classes('form-control', @classes)
13
+ end
10
14
  end
11
15
  end
12
16
  end
@@ -7,6 +7,7 @@ module SdrViewComponents
7
7
  def initialize(**args)
8
8
  args[:container_classes] = merge_classes('form-check', args[:container_classes])
9
9
  args[:label_default_class] = 'form-check-label'
10
+ args[:variant] = :help_text_below
10
11
  super
11
12
  end
12
13
 
@@ -1,8 +1,9 @@
1
1
  <%= tag.div class: container_classes, **container_args do %>
2
2
  <%= render SdrViewComponents::Forms::LabelComponent.new(form:, field_name: label_field_name, **label_args) %>
3
- <%= render SdrViewComponents::Forms::HelpTextComponent.new(**help_text_args) %>
3
+ <%= render SdrViewComponents::Forms::HelpTextComponent.new(**help_text_args) unless help_text_below? %>
4
4
  <%= render input_component %>
5
5
  <%= render SdrViewComponents::Forms::InvalidFeedbackComponent.new(form:, field_name:, **error_args) %>
6
+ <%= render SdrViewComponents::Forms::HelpTextComponent.new(**help_text_args) if help_text_below? %>
6
7
 
7
8
  <%= additional_container_content %>
8
9
  <% end %>
@@ -6,15 +6,20 @@ module SdrViewComponents
6
6
  class FieldComponent < BaseComponent
7
7
  renders_one :additional_container_content
8
8
 
9
- def initialize(form:, field_name:, container_classes: [], **args)
9
+ def initialize(form:, field_name:, container_classes: [], variant: :default, **args)
10
10
  @form = form
11
11
  @field_name = field_name
12
12
  @container_classes = container_classes
13
+ @variant = variant
14
+ # In the help_text_below variant, the help text is rendered below the input field.
15
+ # This is necessary for some types of fields such as checkboxes.
16
+ raise ArgumentError, 'invalid variant' unless %i[default help_text_below].include?(@variant)
17
+
13
18
  @args = args
14
19
  super()
15
20
  end
16
21
 
17
- attr_reader :form, :args, :field_name
22
+ attr_reader :form, :args, :field_name, :variant
18
23
 
19
24
  # Any component that inherits from FieldComponent must implement this method
20
25
  # or provide its own template.
@@ -71,6 +76,10 @@ module SdrViewComponents
71
76
  def container_classes
72
77
  merge_classes(@container_classes)
73
78
  end
79
+
80
+ def help_text_below?
81
+ variant == :help_text_below
82
+ end
74
83
  ##########################################################################
75
84
 
76
85
  private
@@ -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.8'
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.8
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: 2025-12-17 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: []