sdr_view_components 0.9.0 → 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.
- checksums.yaml +4 -4
- data/app/components/sdr_view_components/elements/button_form_component.rb +6 -4
- data/app/components/sdr_view_components/elements/icon_button_component.rb +3 -2
- data/app/components/sdr_view_components/elements/icon_button_form_component.rb +62 -0
- data/app/components/sdr_view_components/tables/base_table_component.html.erb +1 -1
- data/lib/sdr_view_components/version.rb +1 -1
- data/spec/components/previews/sdr_view_components/elements/button_form_component_preview.rb +11 -0
- data/spec/components/previews/sdr_view_components/elements/icon_button_component_preview.rb +5 -0
- data/spec/components/previews/sdr_view_components/elements/icon_button_form_component_preview.rb +34 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ef8577c7ba2659565cc9bc0fc7abde0dc81581d56d4ca04d0fd97c6af6bfa152
|
|
4
|
+
data.tar.gz: 762e2ab51b230c2c65620d63f9521adc652bd8dd177307066a4d37c2614ccab9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5afcd584845fcd490a6bb7a371c59ce5d890e7f37dafa66e601b3720d887c3af65a75f973e597836903386a1988562e94bf719ef7c396e51f03f7afe872f9ed7
|
|
7
|
+
data.tar.gz: 0a53d768a9355718afda4fa06c609b5ee5d61563637c5bb8ad52443a4070eb61c203a02b0f357db8f6f3b64f0d1b0981afaecbb67830a2709430e768f8410214
|
|
@@ -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: {}, disabled: false)
|
|
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
|
|
@@ -15,15 +15,17 @@ module SdrViewComponents
|
|
|
15
15
|
@top = top
|
|
16
16
|
@data = data
|
|
17
17
|
@disabled = disabled
|
|
18
|
+
@params = params
|
|
18
19
|
super()
|
|
19
20
|
end
|
|
20
21
|
|
|
21
|
-
attr_reader :link
|
|
22
|
+
attr_reader :link, :params
|
|
22
23
|
|
|
23
24
|
def call
|
|
24
25
|
button_to(link, method: @method,
|
|
25
26
|
class: ComponentSupport::ButtonSupport.classes(variant: @variant, classes:, disabled: @disabled),
|
|
26
|
-
form: { data: }
|
|
27
|
+
form: { data: },
|
|
28
|
+
params:) do
|
|
27
29
|
@label || content
|
|
28
30
|
end
|
|
29
31
|
end
|
|
@@ -4,10 +4,11 @@ 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: [], disabled: false, **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
|
|
11
12
|
@disabled = disabled
|
|
12
13
|
@options = options
|
|
13
14
|
super()
|
|
@@ -24,7 +25,7 @@ module SdrViewComponents
|
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
def button_icon
|
|
27
|
-
helpers.public_send(:"#{@icon}_icon")
|
|
28
|
+
helpers.public_send(:"#{@icon}_icon", classes: @icon_classes)
|
|
28
29
|
end
|
|
29
30
|
|
|
30
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,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><%=
|
|
4
|
+
<caption><%= caption || label %></caption>
|
|
5
5
|
<% end %>
|
|
6
6
|
<% if headers? %>
|
|
7
7
|
<%= tag.thead class: head_classes do %>
|
|
@@ -109,6 +109,17 @@ module SdrViewComponents
|
|
|
109
109
|
end
|
|
110
110
|
# @!endgroup
|
|
111
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
|
+
|
|
112
123
|
def default
|
|
113
124
|
render SdrViewComponents::Elements::ButtonFormComponent.new(link: '/', label: 'Form Button')
|
|
114
125
|
end
|
data/spec/components/previews/sdr_view_components/elements/icon_button_form_component_preview.rb
ADDED
|
@@ -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
|
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.
|
|
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
|