polaris_view_components 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe4f47163b63610d0173fe647af2fcaa6bad29be973960033a07b44ee5c6fba0
4
- data.tar.gz: '04909bbb7787789799539aed696d529574f67e03a39760e9fc254d095ef1aa13'
3
+ metadata.gz: 78a6ae16cf340437e15af81ff47953f94b1f391af829678035890d5e990e1beb
4
+ data.tar.gz: 07b81a71aaea4b0609c5e3479bb531076df8f65fb589f69aab40181029791414
5
5
  SHA512:
6
- metadata.gz: 9860d6b8f697651f036358ed33207b25eb65068a57be56cca9e516136052a0109b4f8efd1bdf4da04c52448fc898ddd61b782a953108e8a78b722ef19f52a867
7
- data.tar.gz: 6a2358bb6124ff8bff6fb559caa354da1a0502ba40b0846cc47064126173f89f53e5a006a56d07c65f74b154e98a6bc206dd921a990833e4b21a301879c85de6
6
+ metadata.gz: 6ad09a8dc61def4c7fb827d312e19d46b920bb79e804468ca1e9bc5cdac341755ec56ade63230368ff7890fe830d01a7f991116f263e1d03b056a10b9a2c3676
7
+ data.tar.gz: e503ca46cc74f5c8ed8b87d73b517c3915f82c0147a99385fc58fa4f60a46596399149ca857b9348cbc2037fa5d77c67b12072684c397750833c2442361f681a
@@ -11,6 +11,15 @@ export default class extends Controller {
11
11
  }
12
12
  }
13
13
 
14
+ disableWithoutLoader(event) {
15
+ if (this.button.disabled) {
16
+ event.preventDefault()
17
+ } else {
18
+ this.button.disabled = true
19
+ this.button.classList.add("Polaris-Button--disabled")
20
+ }
21
+ }
22
+
14
23
  enable() {
15
24
  if (this.button.disabled) {
16
25
  this.button.disabled = false
@@ -9,6 +9,10 @@ export default class extends Controller {
9
9
  this.findElement("button").disable()
10
10
  }
11
11
 
12
+ disableButtonWithoutLoader() {
13
+ this.findElement("button").disableWithoutLoader()
14
+ }
15
+
12
16
  enableButton() {
13
17
  this.findElement("button").enable()
14
18
  }
@@ -34,6 +34,18 @@ export default class extends Controller {
34
34
  }
35
35
  }
36
36
 
37
+ clearErrorMessages() {
38
+ const wrapper = this.inputTarget.parentElement
39
+ const inlineError = this.inputTarget.closest(".polaris-text-field-wrapper").querySelector(".Polaris-InlineError")
40
+
41
+ if (wrapper) {
42
+ wrapper.classList.remove("Polaris-TextField--error")
43
+ }
44
+ if (inlineError) {
45
+ inlineError.remove()
46
+ }
47
+ }
48
+
37
49
  increase() {
38
50
  this.changeNumber(1)
39
51
  }
@@ -307,6 +307,14 @@ class Button extends Controller {
307
307
  this.buttonContent.insertAdjacentHTML("afterbegin", this.spinnerHTML);
308
308
  }
309
309
  }
310
+ disableWithoutLoader(event) {
311
+ if (this.button.disabled) {
312
+ event.preventDefault();
313
+ } else {
314
+ this.button.disabled = true;
315
+ this.button.classList.add("Polaris-Button--disabled");
316
+ }
317
+ }
310
318
  enable() {
311
319
  if (this.button.disabled) {
312
320
  this.button.disabled = false;
@@ -873,6 +881,9 @@ class Polaris extends Controller {
873
881
  disableButton() {
874
882
  this.findElement("button").disable();
875
883
  }
884
+ disableButtonWithoutLoader() {
885
+ this.findElement("button").disableWithoutLoader();
886
+ }
876
887
  enableButton() {
877
888
  this.findElement("button").enable();
878
889
  }
@@ -2280,6 +2291,16 @@ class TextField extends Controller {
2280
2291
  this.inputTarget.dispatchEvent(new Event("change"));
2281
2292
  }
2282
2293
  }
2294
+ clearErrorMessages() {
2295
+ const wrapper = this.inputTarget.parentElement;
2296
+ const inlineError = this.inputTarget.closest(".polaris-text-field-wrapper").querySelector(".Polaris-InlineError");
2297
+ if (wrapper) {
2298
+ wrapper.classList.remove("Polaris-TextField--error");
2299
+ }
2300
+ if (inlineError) {
2301
+ inlineError.remove();
2302
+ }
2303
+ }
2283
2304
  increase() {
2284
2305
  this.changeNumber(1);
2285
2306
  }
@@ -6,6 +6,7 @@ module Polaris
6
6
  name: nil,
7
7
  checked: false,
8
8
  disabled: false,
9
+ mulitple: false,
9
10
  value: "1",
10
11
  unchecked_value: "0",
11
12
  **system_arguments
@@ -22,8 +23,9 @@ module Polaris
22
23
 
23
24
  def system_arguments
24
25
  @system_arguments.tap do |opts|
25
- opts[:disabled] = true if @disabled
26
26
  opts[:checked] = true if @checked
27
+ opts[:disabled] = true if @disabled
28
+ opts[:multiple] = true if @multiple
27
29
  opts[:aria] ||= {}
28
30
  opts[:aria][:checked] = @checked
29
31
  if indeterminate?
@@ -16,6 +16,7 @@ module Polaris
16
16
  label_hidden: false,
17
17
  checked: false,
18
18
  disabled: false,
19
+ multiple: false,
19
20
  help_text: nil,
20
21
  error: nil,
21
22
  value: "1",
@@ -29,6 +30,7 @@ module Polaris
29
30
  @name = name
30
31
  @checked = checked
31
32
  @disabled = disabled
33
+ @multiple = multiple
32
34
  @value = value
33
35
  @unchecked_value = unchecked_value
34
36
 
@@ -76,6 +78,7 @@ module Polaris
76
78
  name: @name,
77
79
  checked: @checked,
78
80
  disabled: @disabled,
81
+ multiple: @multiple,
79
82
  value: @value,
80
83
  unchecked_value: @unchecked_value,
81
84
  **@input_options
@@ -10,6 +10,7 @@ module Polaris
10
10
  value: value,
11
11
  checked: @selected.include?(value),
12
12
  disabled: disabled || @disabled,
13
+ multiple: true,
13
14
  **system_arguments
14
15
  )
15
16
  end
@@ -52,6 +52,7 @@ module Polaris
52
52
  required: false,
53
53
  help_text: nil,
54
54
  error: false,
55
+ clear_errors_on_focus: false,
55
56
  wrapper_arguments: {},
56
57
  input_options: {},
57
58
  **system_arguments
@@ -83,6 +84,7 @@ module Polaris
83
84
  @required = required
84
85
  @help_text = help_text
85
86
  @error = error
87
+ @clear_errors_on_focus = clear_errors_on_focus
86
88
  @wrapper_arguments = wrapper_arguments
87
89
  @input_options = input_options
88
90
  @system_arguments = system_arguments
@@ -98,7 +100,8 @@ module Polaris
98
100
  label_action: @label_action,
99
101
  required: @required,
100
102
  help_text: @help_text,
101
- error: @error
103
+ error: @error,
104
+ classes: "polaris-text-field-wrapper"
102
105
  }.deep_merge(@wrapper_arguments)
103
106
  end
104
107
 
@@ -136,8 +139,14 @@ module Polaris
136
139
  placeholder: @placeholder,
137
140
  maxlength: @maxlength,
138
141
  minlength: @minlength,
139
- data: {polaris_text_field_target: "input"}
142
+ data: {
143
+ polaris_text_field_target: "input"
144
+ }
140
145
  }
146
+ if @clear_errors_on_focus
147
+ append_option(default_options[:data], :action, "focus->polaris-text-field#clearErrorMessages")
148
+ end
149
+
141
150
  if @type == :number
142
151
  default_options.merge!({
143
152
  step: @step,
@@ -87,5 +87,30 @@ module Polaris
87
87
  end
88
88
  render Polaris::DropzoneComponent.new(form: self, attribute: method, **options, &block)
89
89
  end
90
+
91
+ def polaris_collection_check_boxes(method, collection, value_method, text_method, **options, &block)
92
+ options[:error] ||= error_for(method)
93
+ if options[:error_hidden] && options[:error]
94
+ options[:error] = !!options[:error]
95
+ end
96
+
97
+ value = object&.public_send(method)
98
+ if value.present?
99
+ options[:selected] = value.map { |el| el.public_send(value_method) }
100
+ end
101
+
102
+ render Polaris::ChoiceListComponent.new(
103
+ form: self,
104
+ title: method.to_s.humanize,
105
+ attribute: method,
106
+ name: method,
107
+ **options,
108
+ &block
109
+ ) do |choice|
110
+ collection.each do |item|
111
+ choice.with_checkbox(label: item.public_send(text_method), value: item.public_send(value_method))
112
+ end
113
+ end
114
+ end
90
115
  end
91
116
  end
@@ -1,5 +1,5 @@
1
1
  module Polaris
2
2
  module ViewComponents
3
- VERSION = "1.2.0"
3
+ VERSION = "1.3.0"
4
4
  end
5
5
  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: 1.2.0
4
+ version: 1.3.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: 2023-10-01 00:00:00.000000000 Z
12
+ date: 2023-11-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails