sdr_view_components 0.1.11 → 0.1.12

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: 01f608d9c6fecfed05ce1ff741a7225fc78b1838f3b6e76d59288ae635543cb7
4
- data.tar.gz: 7bc2e6168f24571747fcf66e178561603c7aacd3814a7f0b5913df093eb113fc
3
+ metadata.gz: 7a2356dbdb335e6faf249112ef1aa9711408edba8e89675dae3b58d9190225b5
4
+ data.tar.gz: e203e4bc7b9dd792086edb62664d88c317aefa7863327832b54de94429d3a578
5
5
  SHA512:
6
- metadata.gz: cba3c38d743396ec1efedb31b03a778a84e4f235c1bab770ddae879331d71df70fbc75ae76122fa2227bf356322f11d301da4f99d55ea92557169d23ebe52387
7
- data.tar.gz: fcb96d3f1d3e9a94355e25934b550f710b35fc43264dc7af89fe74a480a1bd1923380b2b3c36b29eb7e79413ce14fae7b5df00c8bf2cda819f412cec09ac2ad4
6
+ metadata.gz: 11bb7de3197385a9a6c69a62d86ee6767d8efc3ccdebd34054f114559ace7d607e36c12db4af3c5463dad8899ad29e6b191f0eaddf4b902865f3226b9ddda759
7
+ data.tar.gz: aa19ff327bd0cee2aba5514c4baaae5eaa184fe876ac51c4b6a4b767282586ac8c89032561a7533516d45fa51a164f46ff5f2941cbbf45e696916685b45cf782
@@ -0,0 +1,4 @@
1
+ <%= tag.div class: classes, style:, data: do %>
2
+ <%= header %>
3
+ <%= body %>
4
+ <% end %>
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SdrViewComponents
4
+ module Elements
5
+ # Component for a card
6
+ class CardComponent < BaseComponent
7
+ renders_one :body, lambda { |**args|
8
+ SectionComponent.new(default_class: 'card-body', **args)
9
+ }
10
+ renders_one :header, lambda { |**args|
11
+ SectionComponent.new(default_class: 'card-header', **args)
12
+ }
13
+
14
+ def initialize(classes: [], style: nil, data: {})
15
+ @classes = classes
16
+ @style = style
17
+ @data = data
18
+ super()
19
+ end
20
+
21
+ def classes
22
+ merge_classes('card', @classes)
23
+ end
24
+
25
+ attr_reader :style, :data
26
+
27
+ # Component for a card section
28
+ class SectionComponent < BaseComponent
29
+ def initialize(default_class:, classes: [], **options)
30
+ @classes = classes
31
+ @default_class = default_class
32
+ @options = options
33
+ super()
34
+ end
35
+
36
+ attr_reader :options
37
+
38
+ def classes
39
+ merge_classes(@default_class, @classes)
40
+ end
41
+
42
+ def call
43
+ tag.div(class: classes, **options) do
44
+ content
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SdrViewComponents
4
+ module Elements
5
+ # Applies an h# component with the expected styling.
6
+ class HeadingComponent < BaseComponent
7
+ def initialize(level:, text: nil, variant: nil, classes: [])
8
+ raise ArgumentError, 'Invalid level' unless %i[h1 h2 h3 h4 h5 h6].include?(level.to_sym)
9
+
10
+ @level = level
11
+ @variant = variant
12
+ @classes = classes
13
+ @text = text # Provide text or content
14
+ super()
15
+ end
16
+
17
+ def classes
18
+ merge_classes(variant_class, @classes)
19
+ end
20
+
21
+ # Renders the component without the need for a .erb partial.
22
+ def call
23
+ content_tag(@level, class: classes) do
24
+ @text || content
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def variant_class
31
+ return unless @variant
32
+
33
+ @variant.to_s
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SdrViewComponents
4
+ module Elements
5
+ # Component for a horizontal rule (line).
6
+ class HorizontalRuleComponent < BaseComponent
7
+ def initialize(classes: [])
8
+ @classes = classes
9
+ super()
10
+ end
11
+
12
+ def call
13
+ tag.hr class: classes
14
+ end
15
+
16
+ def classes
17
+ merge_classes(@classes)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ <%= tag.div class: classes, tabindex: '-1', id: do %>
2
+ <div class="modal-dialog">
3
+ <div class="modal-content">
4
+ <div class="modal-header">
5
+ <div class="position-absolute top-0 end-0">
6
+ <button type="button" class="btn-close mt-2 me-2" data-bs-dismiss="modal" aria-label="Close"></button>
7
+ </div>
8
+ <% if header? %>
9
+ <%= header %>
10
+ <% end %>
11
+ </div>
12
+ <div class="modal-body">
13
+ <%= body %>
14
+ </div>
15
+ <% if footer? %>
16
+ <div class="modal-footer">
17
+ <%= footer %>
18
+ </div>
19
+ <% end %>
20
+ </div>
21
+ </div>
22
+ <% end %>
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SdrViewComponents
4
+ module Elements
5
+ # Renders a modal dialog
6
+ class ModalComponent < BaseComponent
7
+ renders_one :header # optional
8
+ renders_one :footer # optional
9
+ renders_one :body
10
+
11
+ def initialize(id:, size: :lg)
12
+ @id = id
13
+ @size = size
14
+ super()
15
+ end
16
+
17
+ attr_reader :id
18
+
19
+ def classes
20
+ merge_classes('modal', @size ? "modal-#{@size}" : nil)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ <li class="nav-item">
2
+ <%= tag.a class: 'nav-link', href: path, **options do %><%= title %><% end %>
3
+ </li>
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SdrViewComponents
4
+ module Elements
5
+ # A single link in the header nav, bootstrap-style
6
+ class NavLinkComponent < ViewComponent::Base
7
+ def initialize(title:, path:, **options)
8
+ @title = title
9
+ @path = path
10
+ @options = options
11
+ super()
12
+ end
13
+
14
+ attr_reader :title, :path, :options
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ <%= tag.div class: classes, role: 'progressbar', 'aria-label': label, 'aria-valuenow': percent, 'aria-valuemax': '100', **options do %>
2
+ <%= tag.div class: bar_classes, style: bar_style %>
3
+ <% end %>
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SdrViewComponents
4
+ module Elements
5
+ # Wait for it.
6
+ class ProgressBarComponent < BaseComponent
7
+ def initialize(label:, percent: 0, variant: nil, classes: [], striped: true, **options) # rubocop:disable Metrics/ParameterLists
8
+ @label = label
9
+ @percent = percent
10
+ @variant = variant
11
+ @classes = classes
12
+ @striped = striped
13
+ @options = options
14
+ super()
15
+ end
16
+
17
+ attr_reader :label, :percent, :options
18
+
19
+ def bar_classes
20
+ merge_classes('progress-bar', variant_class, @striped ? 'progress-bar-striped' : nil)
21
+ end
22
+
23
+ def bar_style
24
+ "width: #{percent}%;"
25
+ end
26
+
27
+ def classes
28
+ merge_classes('progress', @classes)
29
+ end
30
+
31
+ private
32
+
33
+ def variant_class
34
+ return unless @variant
35
+
36
+ "bg-#{@variant}"
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,8 @@
1
+ <%= tag.div class: classes do %>
2
+ <% if image_path %>
3
+ <%= tag.img src: image_path, alt: 'Spinner', class: spinner_classes, role: 'status', style: spinner_style, **options %>
4
+ <% else %>
5
+ <%= tag.div class: spinner_classes, role: 'status', style: spinner_style, **options %>
6
+ <% end %>
7
+ <%= tag.div class: message_classes do %><%= message %><% end %>
8
+ <% end %>
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SdrViewComponents
4
+ module Elements
5
+ # It spins.
6
+ class SpinnerComponent < BaseComponent
7
+ def initialize(message: 'Loading...', message_classes: [], message_position: :right, hide_message: false, # rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
8
+ image_path: nil, variant: nil, classes: [],
9
+ height: nil, width: nil, speed: 0.75, **options)
10
+ @message = message
11
+ @variant = variant
12
+ @hide_message = hide_message
13
+ @classes = classes
14
+ @image_path = image_path # Optionally spin an image
15
+ @height = height
16
+ @width = width
17
+ @message_classes = message_classes
18
+ @speed = speed # In seconds, so a larger number is slower. The default (0.75) is the same as Bootstrap's default.
19
+ @options = options
20
+ @message_position = message_position # :bottom or :right
21
+ super()
22
+ end
23
+
24
+ attr_reader :message, :image_path, :options
25
+
26
+ def spinner_classes
27
+ merge_classes('spinner-border', variant_class, border_class, 'mx-2')
28
+ end
29
+
30
+ def message_classes
31
+ merge_classes(@message_classes, @hide_message ? 'visually-hidden' : nil)
32
+ end
33
+
34
+ def classes
35
+ merge_classes(@classes, 'd-flex', message_position_classes)
36
+ end
37
+
38
+ def spinner_style
39
+ return unless @height && @width
40
+
41
+ "height: #{@height}px; width: #{@width}px; --bs-spinner-animation-speed: #{@speed}s;"
42
+ end
43
+
44
+ private
45
+
46
+ def message_position_classes
47
+ case @message_position # rubocop:disable Style/HashLikeCase
48
+ when :bottom
49
+ 'flex-column'
50
+ when :right
51
+ 'align-items-center'
52
+ when :top
53
+ 'flex-column-reverse'
54
+ when :left
55
+ 'flex-row-reverse align-items-center justify-content-end'
56
+ end
57
+ end
58
+
59
+ def variant_class
60
+ return unless @variant
61
+
62
+ "text-#{@variant}"
63
+ end
64
+
65
+ def border_class
66
+ return unless image_path
67
+
68
+ 'border-0'
69
+ end
70
+ end
71
+ end
72
+ end
@@ -4,9 +4,10 @@ module SdrViewComponents
4
4
  module Elements
5
5
  # Component for rendering a tooltip.
6
6
  class TooltipComponent < BaseComponent
7
- def initialize(target_label:, tooltip: nil)
7
+ def initialize(target_label:, tooltip: nil, data: {})
8
8
  @target_label = target_label
9
9
  @tooltip = tooltip
10
+ @data = data
10
11
  super()
11
12
  end
12
13
 
@@ -18,21 +19,14 @@ module SdrViewComponents
18
19
  tooltip.present?
19
20
  end
20
21
 
21
- def data # rubocop:disable Metrics/MethodLength
22
+ def data
22
23
  {
23
24
  bs_html: true,
24
25
  bs_toggle: 'tooltip',
25
26
  bs_title: tooltip,
26
27
  bs_trigger: 'focus',
27
28
  tooltips_target: 'icon'
28
- }.tap do |data|
29
- if Settings.ahoy.tooltip
30
- data[:controller] = 'ahoy-tooltip'
31
- data[:ahoy_tooltip_label_value] = target_label
32
- # Note that this is only tracking tooltip when shown by clicking, not when shown by focus.
33
- data[:action] = 'click->ahoy-tooltip#track'
34
- end
35
- end
29
+ }.merge(@data)
36
30
  end
37
31
  end
38
32
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SdrViewComponents
4
- VERSION = '0.1.11'
4
+ VERSION = '0.1.12'
5
5
  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.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Collier
@@ -77,11 +77,23 @@ files:
77
77
  - app/components/sdr_view_components/elements/button_component.rb
78
78
  - app/components/sdr_view_components/elements/button_form_component.rb
79
79
  - app/components/sdr_view_components/elements/button_link_component.rb
80
+ - app/components/sdr_view_components/elements/card_component.html.erb
81
+ - app/components/sdr_view_components/elements/card_component.rb
82
+ - app/components/sdr_view_components/elements/heading_component.rb
83
+ - app/components/sdr_view_components/elements/horizontal_rule_component.rb
84
+ - app/components/sdr_view_components/elements/modal_component.html.erb
85
+ - app/components/sdr_view_components/elements/modal_component.rb
86
+ - app/components/sdr_view_components/elements/nav_link_component.html.erb
87
+ - app/components/sdr_view_components/elements/nav_link_component.rb
80
88
  - app/components/sdr_view_components/elements/navigation/dropdown_menu_component.html.erb
81
89
  - app/components/sdr_view_components/elements/navigation/dropdown_menu_component.rb
82
90
  - app/components/sdr_view_components/elements/navigation/nav_item_component.rb
91
+ - app/components/sdr_view_components/elements/progress_bar_component.html.erb
92
+ - app/components/sdr_view_components/elements/progress_bar_component.rb
83
93
  - app/components/sdr_view_components/elements/skip_links_component.html.erb
84
94
  - app/components/sdr_view_components/elements/skip_links_component.rb
95
+ - app/components/sdr_view_components/elements/spinner_component.html.erb
96
+ - app/components/sdr_view_components/elements/spinner_component.rb
85
97
  - app/components/sdr_view_components/elements/toast_component.html.erb
86
98
  - app/components/sdr_view_components/elements/toast_component.rb
87
99
  - app/components/sdr_view_components/elements/tooltip_component.html.erb