polaris_view_components 2.3.1 → 2.5.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/assets/javascripts/polaris_view_components/autocomplete_controller.js +2 -2
- data/app/assets/javascripts/polaris_view_components/select_controller.js +13 -0
- data/app/assets/javascripts/polaris_view_components.js +12 -1
- data/app/components/polaris/button_component.html.erb +43 -33
- data/app/components/polaris/headless_button.rb +3 -1
- data/app/components/polaris/labelled_component.rb +7 -3
- data/app/components/polaris/select_component.rb +5 -0
- data/app/helpers/polaris/form_builder.rb +21 -26
- data/lib/polaris/view_components/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84f1b013b1c1b56632fecca163692825151171015df3b9edca221b21c12e87d2
|
4
|
+
data.tar.gz: 6ca879737c1a5e7730dc6299feb6101ec53cfe35bc929a632a8b1950157cd7f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ad985b0add0dd115eefb5e94a64d5c53c8e5966bdfee188eec8e93da1c23ee327cc0bd0d35f62b11b178c6588bbc76cfeefb06de06d7eef1ac3faf0ff4cb50f
|
7
|
+
data.tar.gz: 25f136409d1e0c9aec94f43fc403a040f7f357cf1c53f5d9a1fe5ea567d6543cd9e0168b4d7b913e92c7842e5ee9efcf3fcafe5e064b79f4e9d17e6d429e2b97
|
@@ -31,14 +31,14 @@ export default class extends Controller {
|
|
31
31
|
detail: { value: input.value, label, selected: input.checked }
|
32
32
|
})
|
33
33
|
|
34
|
-
this.element.dispatchEvent(changeEvent)
|
35
|
-
|
36
34
|
if (!this.multipleValue) {
|
37
35
|
this.popoverController.forceHide()
|
38
36
|
this.inputTarget.value = label
|
39
37
|
if (this.hasHiddenInputTarget)
|
40
38
|
this.hiddenInputTarget.value = input.value
|
41
39
|
}
|
40
|
+
|
41
|
+
this.element.dispatchEvent(changeEvent)
|
42
42
|
}
|
43
43
|
|
44
44
|
onInputChange = debounce(() => {
|
@@ -11,4 +11,17 @@ export default class extends Controller {
|
|
11
11
|
const option = this.selectTarget.options[this.selectTarget.selectedIndex]
|
12
12
|
this.selectedOptionTarget.innerText = option.text
|
13
13
|
}
|
14
|
+
|
15
|
+
clearErrorMessages() {
|
16
|
+
const polarisSelect = this.selectTarget.closest(".Polaris-Select")
|
17
|
+
const wrapper = polarisSelect.parentElement
|
18
|
+
const inlineError = wrapper.querySelector(".Polaris-InlineError")
|
19
|
+
|
20
|
+
if (polarisSelect) {
|
21
|
+
polarisSelect.classList.remove("Polaris-Select--error")
|
22
|
+
}
|
23
|
+
if (inlineError) {
|
24
|
+
inlineError.remove()
|
25
|
+
}
|
26
|
+
}
|
14
27
|
}
|
@@ -203,12 +203,12 @@ class Autocomplete extends Controller {
|
|
203
203
|
selected: input.checked
|
204
204
|
}
|
205
205
|
});
|
206
|
-
this.element.dispatchEvent(changeEvent);
|
207
206
|
if (!this.multipleValue) {
|
208
207
|
this.popoverController.forceHide();
|
209
208
|
this.inputTarget.value = label;
|
210
209
|
if (this.hasHiddenInputTarget) this.hiddenInputTarget.value = input.value;
|
211
210
|
}
|
211
|
+
this.element.dispatchEvent(changeEvent);
|
212
212
|
}
|
213
213
|
onInputChange=debounce((() => {
|
214
214
|
if (this.isRemote) {
|
@@ -2276,6 +2276,17 @@ class Select extends Controller {
|
|
2276
2276
|
const option = this.selectTarget.options[this.selectTarget.selectedIndex];
|
2277
2277
|
this.selectedOptionTarget.innerText = option.text;
|
2278
2278
|
}
|
2279
|
+
clearErrorMessages() {
|
2280
|
+
const polarisSelect = this.selectTarget.closest(".Polaris-Select");
|
2281
|
+
const wrapper = polarisSelect.parentElement;
|
2282
|
+
const inlineError = wrapper.querySelector(".Polaris-InlineError");
|
2283
|
+
if (polarisSelect) {
|
2284
|
+
polarisSelect.classList.remove("Polaris-Select--error");
|
2285
|
+
}
|
2286
|
+
if (inlineError) {
|
2287
|
+
inlineError.remove();
|
2288
|
+
}
|
2289
|
+
}
|
2279
2290
|
}
|
2280
2291
|
|
2281
2292
|
class TextField extends Controller {
|
@@ -1,39 +1,49 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
<% button_content = capture do %>
|
2
|
+
<%= render Polaris::BaseComponent.new(tag: @tag, **system_arguments) do %>
|
3
|
+
<span class="Polaris-Button__Content">
|
4
|
+
<% if @loading %>
|
5
|
+
<span class="Polaris-Button__Spinner">
|
6
|
+
<%= polaris_spinner(size: :small) %>
|
7
|
+
</span>
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
<% if icon.present? || @icon_name.present? %>
|
11
|
+
<div class="Polaris-Button__Icon">
|
12
|
+
<%= icon.presence || polaris_icon(name: @icon_name) %>
|
13
|
+
</div>
|
14
|
+
<% if content.present? && !@plain %>
|
15
|
+
|
16
|
+
<% end %>
|
17
|
+
<% end %>
|
8
18
|
|
9
|
-
<% if icon.present? || @icon_name.present? %>
|
10
|
-
<div class="Polaris-Button__Icon">
|
11
|
-
<%= icon.presence || polaris_icon(name: @icon_name) %>
|
12
|
-
</div>
|
13
19
|
<% if content.present? %>
|
14
|
-
|
20
|
+
<div class="<%= @text_classes %>">
|
21
|
+
<%= content %>
|
22
|
+
</div>
|
15
23
|
<% end %>
|
16
|
-
<% end %>
|
17
24
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
25
|
+
<% if @disclosure.present? %>
|
26
|
+
<div class="Polaris-Button__Icon">
|
27
|
+
<% case @disclosure %>
|
28
|
+
<% when :down %>
|
29
|
+
<%= polaris_icon(name: "CaretDownIcon") %>
|
30
|
+
<% when :up %>
|
31
|
+
<%= polaris_icon(name: "CaretUpIcon") %>
|
32
|
+
<% when :select %>
|
33
|
+
<%= polaris_icon(name: "SelectIcon") %>
|
34
|
+
<% when :horizontal_dots %>
|
35
|
+
<%= polaris_icon(name: "MenuHorizontalIcon") %>
|
36
|
+
<% end %>
|
37
|
+
</div>
|
38
|
+
<% end %>
|
39
|
+
</span>
|
40
|
+
<% end %>
|
41
|
+
<% end %>
|
23
42
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
<%= polaris_icon(name: "CaretUpIcon") %>
|
31
|
-
<% when :select %>
|
32
|
-
<%= polaris_icon(name: "SelectIcon") %>
|
33
|
-
<% when :horizontal_dots %>
|
34
|
-
<%= polaris_icon(name: "MenuHorizontalIcon") %>
|
35
|
-
<% end %>
|
36
|
-
</div>
|
37
|
-
<% end %>
|
38
|
-
</span>
|
43
|
+
<% if @tooltip.present? %>
|
44
|
+
<%= polaris_tooltip(text: @tooltip) do %>
|
45
|
+
<%= button_content %>
|
46
|
+
<% end %>
|
47
|
+
<% else %>
|
48
|
+
<%= button_content %>
|
39
49
|
<% end %>
|
@@ -43,6 +43,7 @@ module Polaris
|
|
43
43
|
size: SIZE_DEFAULT,
|
44
44
|
text_align: TEXT_ALIGN_DEFAULT,
|
45
45
|
icon_name: nil,
|
46
|
+
tooltip: nil,
|
46
47
|
**system_arguments
|
47
48
|
)
|
48
49
|
@tag = url.present? ? "a" : "button"
|
@@ -50,11 +51,12 @@ module Polaris
|
|
50
51
|
"Polaris-Button__Text",
|
51
52
|
"Polaris-Button--removeUnderline": plain && monochrome && remove_underline
|
52
53
|
)
|
54
|
+
@plain = plain
|
53
55
|
@loading = loading
|
54
56
|
@disclosure = fetch_or_fallback(DISCLOSURE_OPTIONS, disclosure, DISCLOSURE_DEFAULT)
|
55
57
|
@disclosure = :down if @disclosure === true
|
56
58
|
@icon_name = icon_name
|
57
|
-
|
59
|
+
@tooltip = tooltip
|
58
60
|
@system_arguments = system_arguments
|
59
61
|
@system_arguments[:type] = submit ? "submit" : "button"
|
60
62
|
if loading
|
@@ -21,9 +21,13 @@ module Polaris
|
|
21
21
|
@help_text = help_text
|
22
22
|
@error = error
|
23
23
|
|
24
|
-
if label_action
|
25
|
-
|
26
|
-
|
24
|
+
if label_action
|
25
|
+
if label_action[:content].present?
|
26
|
+
label_content = label_action.delete(:content)
|
27
|
+
with_label_action(**label_action) { label_content }
|
28
|
+
elsif label_action[:icon_name].present?
|
29
|
+
with_label_action(**label_action)
|
30
|
+
end
|
27
31
|
end
|
28
32
|
|
29
33
|
@system_arguments = system_arguments
|
@@ -21,6 +21,7 @@ module Polaris
|
|
21
21
|
help_text: nil,
|
22
22
|
error: false,
|
23
23
|
grouped: false,
|
24
|
+
clear_errors_on_focus: false,
|
24
25
|
wrapper_arguments: {},
|
25
26
|
select_options: {},
|
26
27
|
input_options: {},
|
@@ -69,6 +70,7 @@ module Polaris
|
|
69
70
|
error: error
|
70
71
|
}.merge(wrapper_arguments)
|
71
72
|
|
73
|
+
@clear_errors_on_focus = clear_errors_on_focus
|
72
74
|
@select_options = select_options
|
73
75
|
|
74
76
|
@input_options = input_options
|
@@ -77,6 +79,9 @@ module Polaris
|
|
77
79
|
@input_options[:disabled] = disabled
|
78
80
|
@input_options[:data] ||= {}
|
79
81
|
prepend_option(@input_options[:data], :polaris_select_target, "select")
|
82
|
+
if @clear_errors_on_focus
|
83
|
+
prepend_option(@input_options[:data], :action, "click->polaris-select#clearErrorMessages")
|
84
|
+
end
|
80
85
|
prepend_option(@input_options[:data], :action, "polaris-select#update")
|
81
86
|
end
|
82
87
|
|
@@ -50,18 +50,14 @@ module Polaris
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def polaris_text_field(method, **options, &block)
|
53
|
-
options
|
54
|
-
|
55
|
-
options[:error] = !!options[:error]
|
56
|
-
end
|
53
|
+
apply_error_options(options, method)
|
54
|
+
|
57
55
|
render Polaris::TextFieldComponent.new(form: self, attribute: method, **options), &block
|
58
56
|
end
|
59
57
|
|
60
58
|
def polaris_select(method, **options, &block)
|
61
|
-
options
|
62
|
-
|
63
|
-
options[:error] = !!options[:error]
|
64
|
-
end
|
59
|
+
apply_error_options(options, method)
|
60
|
+
|
65
61
|
value = object&.public_send(method)
|
66
62
|
if value.present?
|
67
63
|
options[:selected] = value
|
@@ -70,34 +66,25 @@ module Polaris
|
|
70
66
|
end
|
71
67
|
|
72
68
|
def polaris_check_box(method, **options, &block)
|
73
|
-
options
|
74
|
-
|
75
|
-
options[:error] = !!options[:error]
|
76
|
-
end
|
69
|
+
apply_error_options(options, method)
|
70
|
+
|
77
71
|
render Polaris::CheckboxComponent.new(form: self, attribute: method, **options, &block)
|
78
72
|
end
|
79
73
|
|
80
74
|
def polaris_radio_button(method, **options, &block)
|
81
|
-
options
|
82
|
-
|
83
|
-
options[:error] = !!options[:error]
|
84
|
-
end
|
75
|
+
apply_error_options(options, method)
|
76
|
+
|
85
77
|
render Polaris::RadioButtonComponent.new(form: self, attribute: method, **options, &block)
|
86
78
|
end
|
87
79
|
|
88
80
|
def polaris_dropzone(method, **options, &block)
|
89
|
-
options
|
90
|
-
|
91
|
-
options[:error] = !!options[:error]
|
92
|
-
end
|
81
|
+
apply_error_options(options, method)
|
82
|
+
|
93
83
|
render Polaris::DropzoneComponent.new(form: self, attribute: method, **options, &block)
|
94
84
|
end
|
95
85
|
|
96
86
|
def polaris_collection_check_boxes(method, collection, value_method, text_method, **options, &block)
|
97
|
-
options
|
98
|
-
if options[:error_hidden] && options[:error]
|
99
|
-
options[:error] = !!options[:error]
|
100
|
-
end
|
87
|
+
apply_error_options(options, method)
|
101
88
|
|
102
89
|
value = object&.public_send(method)
|
103
90
|
if value.present?
|
@@ -124,11 +111,19 @@ module Polaris
|
|
124
111
|
end
|
125
112
|
|
126
113
|
def polaris_autocomplete(method, **options, &block)
|
127
|
-
options
|
114
|
+
apply_error_options(options, method)
|
115
|
+
|
116
|
+
render Polaris::AutocompleteComponent.new(form: self, attribute: method, name: method, **options), &block
|
117
|
+
end
|
118
|
+
|
119
|
+
private
|
120
|
+
|
121
|
+
def apply_error_options(options, method)
|
122
|
+
options[:error] ||= error_for(method) unless options.has_key?(:error)
|
123
|
+
|
128
124
|
if options[:error_hidden] && options[:error]
|
129
125
|
options[:error] = !!options[:error]
|
130
126
|
end
|
131
|
-
render Polaris::AutocompleteComponent.new(form: self, attribute: method, name: method, **options), &block
|
132
127
|
end
|
133
128
|
end
|
134
129
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polaris_view_components
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Gamble
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2025-
|
12
|
+
date: 2025-05-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|