sdr_view_components 0.8.1 → 0.10.0

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.
Files changed (19) hide show
  1. checksums.yaml +4 -4
  2. data/app/components/component_support/button_support.rb +2 -1
  3. data/app/components/sdr_view_components/elements/button_component.rb +3 -2
  4. data/app/components/sdr_view_components/elements/button_form_component.rb +8 -5
  5. data/app/components/sdr_view_components/elements/button_link_component.rb +5 -2
  6. data/app/components/sdr_view_components/elements/icon_button_component.html.erb +1 -1
  7. data/app/components/sdr_view_components/elements/icon_button_component.rb +5 -3
  8. data/app/components/sdr_view_components/elements/icon_button_form_component.rb +62 -0
  9. data/app/components/sdr_view_components/elements/icon_button_link_component.html.erb +1 -1
  10. data/app/components/sdr_view_components/elements/icon_button_link_component.rb +3 -2
  11. data/app/components/sdr_view_components/tables/base_table_component.html.erb +1 -1
  12. data/lib/sdr_view_components/version.rb +1 -1
  13. data/spec/components/previews/sdr_view_components/elements/button_component_preview.rb +12 -0
  14. data/spec/components/previews/sdr_view_components/elements/button_form_component_preview.rb +31 -0
  15. data/spec/components/previews/sdr_view_components/elements/button_link_component_preview.rb +12 -0
  16. data/spec/components/previews/sdr_view_components/elements/icon_button_component_preview.rb +17 -0
  17. data/spec/components/previews/sdr_view_components/elements/icon_button_form_component_preview.rb +34 -0
  18. data/spec/components/previews/sdr_view_components/elements/icon_button_link_component_preview.rb +20 -0
  19. metadata +4 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a89b7fb8bfdf855c3cd22ea788658b10738f042a3900b5475b7edaa9f54bac5
4
- data.tar.gz: acd6997c3b3781ec16a49f3ee029d58211f1ed99e980f9502e06c7621b6e227f
3
+ metadata.gz: ef8577c7ba2659565cc9bc0fc7abde0dc81581d56d4ca04d0fd97c6af6bfa152
4
+ data.tar.gz: 762e2ab51b230c2c65620d63f9521adc652bd8dd177307066a4d37c2614ccab9
5
5
  SHA512:
6
- metadata.gz: 3d076c42c048b050edd2ed57655e9203a3a534fbaa57008eed50cbcf2572f78efc3c2edf61558f542446b9b6fb413682b40eec5e42ec5110bc20f012c254fc0c
7
- data.tar.gz: b398eb960a67d533b2b7ca2676c71fff58a5dba641acc2d0c1a9ef56b4ed6d79952df88f1e18a6d0714ae38c0b0e2001297446ec0cdb76bd2d62e69331c299a4
6
+ metadata.gz: 5afcd584845fcd490a6bb7a371c59ce5d890e7f37dafa66e601b3720d887c3af65a75f973e597836903386a1988562e94bf719ef7c396e51f03f7afe872f9ed7
7
+ data.tar.gz: 0a53d768a9355718afda4fa06c609b5ee5d61563637c5bb8ad52443a4070eb61c203a02b0f357db8f6f3b64f0d1b0981afaecbb67830a2709430e768f8410214
@@ -3,11 +3,12 @@
3
3
  module ComponentSupport
4
4
  # General support for buttons.
5
5
  class ButtonSupport
6
- def self.classes(variant: nil, size: nil, classes: [], bordered: true)
6
+ def self.classes(variant: nil, size: nil, classes: [], bordered: true, disabled: false)
7
7
  ComponentSupport::CssClasses.merge('btn',
8
8
  variant ? "btn-#{variant}" : nil,
9
9
  size ? "btn-#{size}" : nil,
10
10
  bordered ? nil : %w[border border-0],
11
+ disabled ? 'disabled' : nil,
11
12
  classes)
12
13
  end
13
14
  end
@@ -4,13 +4,14 @@ module SdrViewComponents
4
4
  module Elements
5
5
  # Generic button component
6
6
  class ButtonComponent < BaseComponent
7
- def initialize(label: nil, classes: [], variant: nil, size: nil, bordered: true, **options) # rubocop:disable Metrics/ParameterLists
7
+ def initialize(label: nil, classes: [], variant: nil, size: nil, bordered: true, disabled: false, **options) # rubocop:disable Metrics/ParameterLists
8
8
  @label = label
9
9
  @classes = classes
10
10
  @variant = variant
11
11
  @size = size
12
12
  @options = options
13
13
  @bordered = bordered
14
+ @disabled = disabled
14
15
  super()
15
16
  end
16
17
 
@@ -19,7 +20,7 @@ module SdrViewComponents
19
20
  def call
20
21
  tag.button(
21
22
  class: ComponentSupport::ButtonSupport.classes(variant: @variant, size: @size, classes: @classes,
22
- bordered: @bordered),
23
+ bordered: @bordered, disabled: @disabled),
23
24
  type: 'button',
24
25
  **options
25
26
  ) do
@@ -4,8 +4,8 @@ module SdrViewComponents
4
4
  module Elements
5
5
  # Component for a button that is wrapped in a form
6
6
  class ButtonFormComponent < BaseComponent
7
- def initialize(link:, label: nil, variant: :primary, classes: [], method: :get, confirm: nil, # rubocop:disable Metrics/ParameterLists
8
- top: true, data: {})
7
+ def initialize(link:, label: nil, variant: :primary, classes: [], method: :get, confirm: nil, # rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
8
+ top: true, data: {}, disabled: false, params: {})
9
9
  @link = link
10
10
  @label = label
11
11
  @variant = variant
@@ -14,15 +14,18 @@ module SdrViewComponents
14
14
  @confirm = confirm
15
15
  @top = top
16
16
  @data = data
17
+ @disabled = disabled
18
+ @params = params
17
19
  super()
18
20
  end
19
21
 
20
- attr_reader :link
22
+ attr_reader :link, :params
21
23
 
22
24
  def call
23
25
  button_to(link, method: @method,
24
- class: ComponentSupport::ButtonSupport.classes(variant: @variant, classes:),
25
- form: { data: }) do
26
+ class: ComponentSupport::ButtonSupport.classes(variant: @variant, classes:, disabled: @disabled),
27
+ form: { data: },
28
+ params:) do
26
29
  @label || content
27
30
  end
28
31
  end
@@ -4,7 +4,8 @@ module SdrViewComponents
4
4
  module Elements
5
5
  # Component for a button that is a link
6
6
  class ButtonLinkComponent < BaseComponent
7
- def initialize(link:, label: nil, variant: :primary, classes: [], bordered: true, size: nil, **options) # rubocop:disable Metrics/ParameterLists
7
+ def initialize(link:, label: nil, variant: :primary, classes: [], bordered: true, size: nil, # rubocop:disable Metrics/ParameterLists
8
+ disabled: false, **options)
8
9
  @link = link
9
10
  @label = label
10
11
  @variant = variant
@@ -12,6 +13,7 @@ module SdrViewComponents
12
13
  @classes = classes
13
14
  @bordered = bordered
14
15
  @size = size
16
+ @disabled = disabled
15
17
  super()
16
18
  end
17
19
 
@@ -19,7 +21,8 @@ module SdrViewComponents
19
21
 
20
22
  def call
21
23
  link_to(link, class: ComponentSupport::ButtonSupport.classes(classes: @classes, variant: @variant,
22
- bordered: @bordered, size: @size),
24
+ bordered: @bordered, size: @size,
25
+ disabled: @disabled),
23
26
  **@options) do
24
27
  label || content
25
28
  end
@@ -1,3 +1,3 @@
1
- <%= render SdrViewComponents::Elements::ButtonComponent.new(classes:, variant: :'outline-primary', **options) do %>
1
+ <%= render SdrViewComponents::Elements::ButtonComponent.new(classes:, variant: :'outline-primary', disabled:, **options) do %>
2
2
  <%= button_icon %><span class="visually-hidden"><%= label %></span>
3
3
  <% end %>
@@ -4,10 +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: [], **options)
7
+ def initialize(icon:, label:, classes: [], icon_classes: [], disabled: false, **options) # rubocop:disable Metrics/ParameterLists
8
8
  @icon = icon
9
9
  @label = label
10
10
  @classes = classes
11
+ @icon_classes = icon_classes
12
+ @disabled = disabled
11
13
  @options = options
12
14
  super()
13
15
  end
@@ -16,14 +18,14 @@ module SdrViewComponents
16
18
  raise SdrViewComponents::Error::UnknownComponentIcon, "Unknown icon type: #{@icon}" unless button_icon?
17
19
  end
18
20
 
19
- attr_reader :label, :options
21
+ attr_reader :label, :options, :disabled
20
22
 
21
23
  def classes
22
24
  merge_classes(%w[border border-0], @classes)
23
25
  end
24
26
 
25
27
  def button_icon
26
- helpers.public_send(:"#{@icon}_icon")
28
+ helpers.public_send(:"#{@icon}_icon", classes: @icon_classes)
27
29
  end
28
30
 
29
31
  private
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SdrViewComponents
4
+ module Elements
5
+ # Component for a button which is an icon and is wrapped in a form
6
+ class IconButtonFormComponent < BaseComponent
7
+ def initialize(link:, icon:, label:, variant: :'outline-primary', classes: [], icon_classes: [], method: :get, # rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
8
+ confirm: nil, top: true, data: {}, disabled: false, params: {})
9
+ @link = link
10
+ @icon = icon
11
+ @label = label
12
+ @variant = variant
13
+ @classes = classes
14
+ @icon_classes = icon_classes
15
+ @method = method
16
+ @confirm = confirm
17
+ @top = top
18
+ @data = data
19
+ @disabled = disabled
20
+ @params = params
21
+ super()
22
+ end
23
+
24
+ def before_render
25
+ raise SdrViewComponents::Error::UnknownComponentIcon, "Unknown icon type: #{@icon}" unless button_icon?
26
+ end
27
+
28
+ attr_reader :link, :params, :label
29
+
30
+ def call
31
+ button_to(link, method: @method,
32
+ class: ComponentSupport::ButtonSupport.classes(variant: @variant, classes:, disabled: @disabled),
33
+ form: { data: },
34
+ params:) do
35
+ concat button_icon
36
+ concat tag.span(label, class: 'visually-hidden')
37
+ end
38
+ end
39
+
40
+ def classes
41
+ merge_classes(%w[border border-0], @classes)
42
+ end
43
+
44
+ def data
45
+ @data.tap do |data|
46
+ data[:turbo_frame] = '_top' if @top
47
+ data[:turbo_confirm] = @confirm if @confirm
48
+ end
49
+ end
50
+
51
+ def button_icon
52
+ helpers.public_send(:"#{@icon}_icon", classes: @icon_classes)
53
+ end
54
+
55
+ private
56
+
57
+ def button_icon?
58
+ helpers.respond_to?(:"#{@icon}_icon")
59
+ end
60
+ end
61
+ end
62
+ end
@@ -1,3 +1,3 @@
1
- <%= render SdrViewComponents::Elements::ButtonLinkComponent.new(classes:, variant: :'outline-primary', link:, **options) do %>
1
+ <%= render SdrViewComponents::Elements::ButtonLinkComponent.new(classes:, variant: :'outline-primary', link:, disabled:, **options) do %>
2
2
  <%= button_icon %><span class="visually-hidden"><%= label %></span>
3
3
  <% end %>
@@ -4,17 +4,18 @@ 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, **options) # rubocop:disable Metrics/ParameterLists
7
+ def initialize(icon:, label:, classes: [], icon_classes: [], link: nil, disabled: false, **options) # rubocop:disable Metrics/ParameterLists
8
8
  @icon = icon
9
9
  @label = label
10
10
  @classes = classes
11
11
  @link = link
12
12
  @options = options
13
13
  @icon_classes = icon_classes
14
+ @disabled = disabled
14
15
  super()
15
16
  end
16
17
 
17
- attr_reader :label, :link, :options
18
+ attr_reader :label, :link, :options, :disabled
18
19
 
19
20
  def classes
20
21
  merge_classes(%w[border border-0], @classes)
@@ -1,7 +1,7 @@
1
1
  <% @table_content = capture do %>
2
2
  <%= tag.table class: classes, 'aria-label': label, **@table_options do %>
3
3
  <% if show_label? %>
4
- <caption><%= label || caption %></caption>
4
+ <caption><%= caption || label %></caption>
5
5
  <% end %>
6
6
  <% if headers? %>
7
7
  <%= tag.thead class: head_classes do %>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SdrViewComponents
4
- VERSION = '0.8.1'
4
+ VERSION = '0.10.0'
5
5
  end
@@ -63,6 +63,18 @@ module SdrViewComponents
63
63
  end
64
64
  # @!endgroup
65
65
 
66
+ # @!group Disabled State
67
+ def enabled
68
+ render SdrViewComponents::Elements::ButtonComponent.new(label: 'Enabled Button', variant: 'primary',
69
+ disabled: false)
70
+ end
71
+
72
+ def disabled
73
+ render SdrViewComponents::Elements::ButtonComponent.new(label: 'Disabled Button', variant: 'primary',
74
+ disabled: true)
75
+ end
76
+ # @!endgroup
77
+
66
78
  def default
67
79
  render SdrViewComponents::Elements::ButtonComponent.new(label: 'Default Button')
68
80
  end
@@ -89,6 +89,37 @@ module SdrViewComponents
89
89
  end
90
90
  # @!endgroup
91
91
 
92
+ # @!group Disabled State
93
+ def enabled
94
+ render SdrViewComponents::Elements::ButtonFormComponent.new(
95
+ link: '/action',
96
+ label: 'Enabled Button',
97
+ variant: :primary,
98
+ disabled: false
99
+ )
100
+ end
101
+
102
+ def disabled
103
+ render SdrViewComponents::Elements::ButtonFormComponent.new(
104
+ link: '/action',
105
+ label: 'Disabled Button',
106
+ variant: :primary,
107
+ disabled: true
108
+ )
109
+ end
110
+ # @!endgroup
111
+
112
+ # @!group Params
113
+ def with_params
114
+ render SdrViewComponents::Elements::ButtonFormComponent.new(
115
+ link: '/action',
116
+ label: 'Submit with Params',
117
+ variant: :primary,
118
+ params: { foo: 'bar', baz: 'qux' }
119
+ )
120
+ end
121
+ # @!endgroup
122
+
92
123
  def default
93
124
  render SdrViewComponents::Elements::ButtonFormComponent.new(link: '/', label: 'Form Button')
94
125
  end
@@ -79,6 +79,18 @@ module SdrViewComponents
79
79
  end
80
80
  # @!endgroup
81
81
 
82
+ # @!group Disabled State
83
+ def enabled
84
+ render SdrViewComponents::Elements::ButtonLinkComponent.new(link: '/example', label: 'Enabled Link Button',
85
+ variant: :primary, disabled: false)
86
+ end
87
+
88
+ def disabled
89
+ render SdrViewComponents::Elements::ButtonLinkComponent.new(link: '/example', label: 'Disabled Link Button',
90
+ variant: :primary, disabled: true)
91
+ end
92
+ # @!endgroup
93
+
82
94
  def default
83
95
  render SdrViewComponents::Elements::ButtonLinkComponent.new(link: '/example', label: 'Default Link Button')
84
96
  end
@@ -12,6 +12,23 @@ module SdrViewComponents
12
12
  render SdrViewComponents::Elements::IconButtonComponent.new(icon: :download, label: 'Download file')
13
13
  end
14
14
  # @!endgroup
15
+
16
+ # @!group Disabled State
17
+ def enabled
18
+ render SdrViewComponents::Elements::IconButtonComponent.new(icon: :delete, label: 'Delete item',
19
+ disabled: false)
20
+ end
21
+
22
+ def disabled
23
+ render SdrViewComponents::Elements::IconButtonComponent.new(icon: :delete, label: 'Delete item',
24
+ disabled: true)
25
+ end
26
+ # @!endgroup
27
+
28
+ def with_icon_classes
29
+ render SdrViewComponents::Elements::IconButtonComponent.new(icon: :delete, label: 'Delete item',
30
+ icon_classes: %w[fs-4])
31
+ end
15
32
  end
16
33
  end
17
34
  end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SdrViewComponents
4
+ module Elements
5
+ class IconButtonFormComponentPreview < ViewComponent::Preview
6
+ def default
7
+ render SdrViewComponents::Elements::IconButtonFormComponent.new(link: '/example', icon: :download,
8
+ label: 'Download item')
9
+ end
10
+
11
+ def with_confirmation
12
+ render SdrViewComponents::Elements::IconButtonFormComponent.new(
13
+ link: '/delete-item',
14
+ icon: :delete,
15
+ label: 'Delete item',
16
+ method: :delete,
17
+ confirm: 'Are you sure you want to delete this item?'
18
+ )
19
+ end
20
+
21
+ # @!group Disabled State
22
+ def enabled
23
+ render SdrViewComponents::Elements::IconButtonFormComponent.new(link: '/example', icon: :download,
24
+ label: 'Download item', disabled: false)
25
+ end
26
+
27
+ def disabled
28
+ render SdrViewComponents::Elements::IconButtonFormComponent.new(link: '/example', icon: :download,
29
+ label: 'Download item', disabled: true)
30
+ end
31
+ # @!endgroup
32
+ end
33
+ end
34
+ end
@@ -10,6 +10,26 @@ module SdrViewComponents
10
10
  link: '/example'
11
11
  )
12
12
  end
13
+
14
+ # @!group Disabled State
15
+ def enabled
16
+ render SdrViewComponents::Elements::IconButtonLinkComponent.new(
17
+ icon: :download,
18
+ label: 'Download item',
19
+ link: '/example',
20
+ disabled: false
21
+ )
22
+ end
23
+
24
+ def disabled
25
+ render SdrViewComponents::Elements::IconButtonLinkComponent.new(
26
+ icon: :download,
27
+ label: 'Download item',
28
+ link: '/example',
29
+ disabled: true
30
+ )
31
+ end
32
+ # @!endgroup
13
33
  end
14
34
  end
15
35
  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.8.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Collier
@@ -82,6 +82,7 @@ files:
82
82
  - app/components/sdr_view_components/elements/horizontal_rule_component.rb
83
83
  - app/components/sdr_view_components/elements/icon_button_component.html.erb
84
84
  - app/components/sdr_view_components/elements/icon_button_component.rb
85
+ - app/components/sdr_view_components/elements/icon_button_form_component.rb
85
86
  - app/components/sdr_view_components/elements/icon_button_link_component.html.erb
86
87
  - app/components/sdr_view_components/elements/icon_button_link_component.rb
87
88
  - app/components/sdr_view_components/elements/modal_component.html.erb
@@ -199,6 +200,7 @@ files:
199
200
  - spec/components/previews/sdr_view_components/elements/horizontal_rule_component_preview.rb
200
201
  - spec/components/previews/sdr_view_components/elements/horizontal_rule_component_preview/default.html.erb
201
202
  - spec/components/previews/sdr_view_components/elements/icon_button_component_preview.rb
203
+ - spec/components/previews/sdr_view_components/elements/icon_button_form_component_preview.rb
202
204
  - spec/components/previews/sdr_view_components/elements/icon_button_link_component_preview.rb
203
205
  - spec/components/previews/sdr_view_components/elements/modal_component_preview.rb
204
206
  - spec/components/previews/sdr_view_components/elements/modal_component_preview/default.html.erb
@@ -373,7 +375,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
373
375
  - !ruby/object:Gem::Version
374
376
  version: '0'
375
377
  requirements: []
376
- rubygems_version: 4.0.17
378
+ rubygems_version: 4.0.6
377
379
  specification_version: 4
378
380
  summary: Rails gem for providing SDR-specific ViewComponents.
379
381
  test_files: []