polaris_view_components 1.2.0 → 1.4.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: 3dc9a731d4c3dc7615b6148d0ac7980afce53a98c9c31dafcc6993e73716ee3c
4
+ data.tar.gz: c5321641a35f94d11b8a1769e61f65c31156454d1a3d06f223780f9022f9015f
5
5
  SHA512:
6
- metadata.gz: 9860d6b8f697651f036358ed33207b25eb65068a57be56cca9e516136052a0109b4f8efd1bdf4da04c52448fc898ddd61b782a953108e8a78b722ef19f52a867
7
- data.tar.gz: 6a2358bb6124ff8bff6fb559caa354da1a0502ba40b0846cc47064126173f89f53e5a006a56d07c65f74b154e98a6bc206dd921a990833e4b21a301879c85de6
6
+ metadata.gz: aa891ef13f9226354394f89da3896e2c6e42cb7d3b07b1b2076508303a523087ea48945011acf9cd84c7ccea565b2d6f5fb356185eb44dec4997189579a551a1
7
+ data.tar.gz: 35ebfe95fd139e6979ee622a1c362f08896e462c33ecfdc9c5cef6d2159b4115dbd9d8b8f1792b83399a03ec179e8c654dd4b6270a3172b114a27d1c87170f0c
@@ -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
@@ -0,0 +1,5 @@
1
+ <%= polaris_card(sectioned: false, style: "padding-top: 1em; padding-bottom: 1em;") do |card| %>
2
+ <% items.each do |item| %>
3
+ <%= item %>
4
+ <% end %>
5
+ <% end %>
@@ -0,0 +1,13 @@
1
+ module Polaris
2
+ class NavigationListComponent < Polaris::Component
3
+ renders_many :items, Polaris::Navigation::ItemComponent
4
+
5
+ def initialize(**system_arguments)
6
+ @system_arguments = system_arguments
7
+ end
8
+
9
+ def renders?
10
+ items.any?
11
+ end
12
+ end
13
+ end
@@ -108,12 +108,17 @@
108
108
  <% if has_pagination? %>
109
109
  <div class="Polaris-Page-Header__PaginationWrapper">
110
110
  <nav aria-label="Pagination">
111
- <%= polaris_button_group(segmented: true) do |group| %>
111
+ <%= polaris_button_group(segmented: @pagination_label.blank?) do |group| %>
112
112
  <% group.with_item do %>
113
113
  <%= polaris_button(url: @prev_url, outline: true, disabled: @prev_url.blank?) do |button| %>
114
114
  <% button.with_icon(name: "ChevronLeftMinor") %>
115
115
  <% end %>
116
116
  <% end %>
117
+ <% if @pagination_label.present? %>
118
+ <% group.with_item do %>
119
+ <div aria-live="polite"><%= @pagination_label %></div>
120
+ <% end %>
121
+ <% end %>
117
122
  <% group.with_item do %>
118
123
  <%= polaris_button(url: @next_url, outline: true, disabled: @next_url.blank?) do |button| %>
119
124
  <% button.with_icon(name: "ChevronRightMinor") %>
@@ -18,6 +18,7 @@ module Polaris
18
18
  back_url: nil,
19
19
  prev_url: nil,
20
20
  next_url: nil,
21
+ pagination_label: nil,
21
22
  narrow_width: false,
22
23
  full_width: false,
23
24
  divider: false,
@@ -30,6 +31,7 @@ module Polaris
30
31
  @back_url = back_url
31
32
  @prev_url = prev_url
32
33
  @next_url = next_url
34
+ @pagination_label = pagination_label
33
35
  @narrow_width = narrow_width
34
36
  @full_width = full_width
35
37
  @divider = divider
@@ -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
@@ -49,6 +49,7 @@ module Polaris
49
49
  modal: "Polaris::ModalComponent",
50
50
  modal_section: "Polaris::Modal::SectionComponent",
51
51
  navigation: "Polaris::NavigationComponent",
52
+ navigation_list: "Polaris::NavigationListComponent",
52
53
  option_list: "Polaris::OptionListComponent",
53
54
  page: "Polaris::PageComponent",
54
55
  page_actions: "Polaris::PageActionsComponent",
@@ -33,10 +33,7 @@ module Polaris
33
33
 
34
34
  initializer "polaris_view_components.helpers" do
35
35
  ActiveSupport.on_load(:action_controller_base) do
36
- require "polaris/view_helper"
37
36
  helper Polaris::ViewHelper
38
-
39
- require "polaris/url_helper"
40
37
  helper Polaris::UrlHelper
41
38
  end
42
39
  end
@@ -1,5 +1,5 @@
1
1
  module Polaris
2
2
  module ViewComponents
3
- VERSION = "1.2.0"
3
+ VERSION = "1.4.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.4.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-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -860,6 +860,8 @@ files:
860
860
  - app/components/polaris/navigation/section_component.rb
861
861
  - app/components/polaris/navigation_component.html.erb
862
862
  - app/components/polaris/navigation_component.rb
863
+ - app/components/polaris/navigation_list_component.html.erb
864
+ - app/components/polaris/navigation_list_component.rb
863
865
  - app/components/polaris/option_list/checkbox_component.html.erb
864
866
  - app/components/polaris/option_list/checkbox_component.rb
865
867
  - app/components/polaris/option_list/option_component.rb