polaris_view_helpers 2.0.1 → 2.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cfad6d181259f671a5f644fd891405bb34dcb6d9aba94626a27ba33335037206
4
- data.tar.gz: 9eb55b6f8532ad4f6770756b61fcdd00e84be6fa43b0ff972f76b156d950849c
3
+ metadata.gz: 4b62227d0f99eb053fa324a587911a47f878901ee976d990d7938668b2ec1bab
4
+ data.tar.gz: 7dbf42024bbf724c72088f3f4156a01b1f743f03ff331389d90c0c5bb2e6d19b
5
5
  SHA512:
6
- metadata.gz: '09de1b763866657352bd49200844809176520abcd7fd57f80e9f8e467bc57880300c1694e8c3d0778ad7b970983ade731c0152cafbeb726edf7cbdf91e35bb8e'
7
- data.tar.gz: d3269067cfebab14a1e7b6597dc21652afb49b0386ea46e139981addd72dbd8e924aaf16ea6ac49d0a28a027e213536184d79b7a9bc716eeedcabf43bfdaab2a
6
+ metadata.gz: 796fc720c1fb265a7461cd17680daaa89658c8b899de2bc70a64e98b3e5044ddf47a24c34fc9c5e7da00351c13a01346bbc821da1bc2244a1d52dced0b3452d4
7
+ data.tar.gz: 2d3f7410c5f92f75b2a4d5c8830852c72ede75c61eaf114cf182d5d7943ad055fb705ac9333d8ec98e221d637c1b8f3e36eae8ca8166422c8ab9af3a733ff704
@@ -19,7 +19,7 @@
19
19
  </div>
20
20
  <div class="Polaris-Connected">
21
21
  <div class="Polaris-Connected__Item Polaris-Connected__Item--primary">
22
- <div class="Polaris-TextField">
22
+ <div class="No-Polaris-TextField">
23
23
  <%= input %>
24
24
  </div>
25
25
  </div>
@@ -19,10 +19,11 @@
19
19
  </div>
20
20
  <div class="Polaris-Connected">
21
21
  <div class="Polaris-Connected__Item Polaris-Connected__Item--primary">
22
- <div class="Polaris-TextField">
22
+ <div class="Polaris-TextField <%= (form.object&.errors && form.object&.errors[att.to_sym]&.any?) ? "Polaris-TextField--error" : "" %>">
23
23
  <%= form.send element_type, att, id: "#{form.object.class.name.tableize.singularize}_#{att}", class: "Polaris-TextField__Input", placeholder: options[:placeholder] %>
24
24
  <div class="Polaris-TextField__Backdrop"></div>
25
25
  </div>
26
+ <%= polaris_form_element_errors form, att %>
26
27
  </div>
27
28
  </div>
28
29
  </div>
@@ -0,0 +1,7 @@
1
+ <% if form.object&.errors && form.object&.errors[attribute.to_sym]&.any? %>
2
+ <div class="Polaris-Labelled__Error">
3
+ <% form.object.errors[attribute.to_sym].each do |error| %>
4
+ <%= polaris_inline_error form, attribute, error %>
5
+ <% end %>
6
+ </div>
7
+ <% end %>
@@ -5,7 +5,7 @@
5
5
  <%= form.label att, text, class: 'Polaris-Label__Text' %>
6
6
  </div>
7
7
  </div>
8
- <div class="Polaris-TextField">
8
+ <div class="No-Polaris-TextField">
9
9
  <%= capture(&block) %>
10
10
  </div>
11
11
  </div>
@@ -0,0 +1,15 @@
1
+ <div id="<%= attribute.to_s.underscore %>_error" class="Polaris-InlineError">
2
+ <div class="Polaris-InlineError__Icon">
3
+ <span class="Polaris-Icon">
4
+ <svg viewBox="0 0 20 20" class="Polaris-Icon__Svg" focusable="false" aria-hidden="true">
5
+ <path d="M10 6a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5a.75.75 0 0 1 .75-.75Z">
6
+ </path>
7
+ <path d="M11 13a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z">
8
+ </path>
9
+ <path fill-rule="evenodd" d="M17 10a7 7 0 1 1-14 0 7 7 0 0 1 14 0Zm-1.5 0a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0Z">
10
+ </path>
11
+ </svg>
12
+ </span>
13
+ </div>
14
+ <span class="Polaris-Text--root Polaris-Text--bodyMd"><%= attribute.to_s.humanize %> <%= error %></span>
15
+ </div>
@@ -6,7 +6,7 @@
6
6
  <label id="<%= listname %>_label" for="<%= listname %>" class="Polaris-Label__Text"><%= title %></label>
7
7
  </div>
8
8
  </div>
9
- <div class="Polaris-Select">
9
+ <div class="Polaris-Select <%= form.object.errors[attribute.to_sym].any? ? "Polaris-Select--error" : "" %>">
10
10
  <%= form.collection_select(attribute, options, :value, :label, select_options, {id: listname, class: "Polaris-Select__Input"}) %>
11
11
  <div class="Polaris-Select__Content" aria-hidden="true">
12
12
  <span class="Polaris-Select__SelectedOption" id="<%= listname %>_selected_option_label"><%= selected_label || form.object&.send(attribute) %></span>
@@ -24,6 +24,7 @@
24
24
  <div class="Polaris-Select__Backdrop">
25
25
  </div>
26
26
  </div>
27
+ <%= polaris_form_element_errors form, attribute %>
27
28
  </div>
28
29
  <script charset="utf-8">
29
30
  var selectElement = document.querySelector("#<%= listname %>");
@@ -8,10 +8,11 @@
8
8
  </div>
9
9
  </div>
10
10
  <% end %>
11
- <div class="Polaris-TextField">
12
- <%= form.send element_type, att, id: "#{form.object.class.name.tableize.singularize}_#{att}", class: "Polaris-TextField__Input", placeholder: options[:placeholder], value: (options[:value] || form.object&.send(att)), data: options[:data] %>
11
+ <div class="Polaris-TextField <%= (form.object&.errors && form.object&.errors[att.to_sym]&.any?) ? "Polaris-TextField--error" : "" %>">
12
+ <%= form.send element_type, att, id: "#{form.object.class.name.tableize.singularize}_#{att}", class: "Polaris-TextField__Input #{additional_classes}", placeholder: options[:placeholder], value: (options[:value] || form.object&.send(att)), data: options[:data] %>
13
13
  <div class="Polaris-TextField__Backdrop"></div>
14
14
  </div>
15
+ <%= polaris_form_element_errors form, att %>
15
16
  </div>
16
17
  </div>
17
18
  <% end %>
@@ -1,6 +1,12 @@
1
1
  module PolarisViewHelpers
2
2
  module Helper
3
3
 
4
+ # This prevent field_with_error divs from showing up and messing with Polaris styling
5
+ # https://stackoverflow.com/questions/7454682/customizing-field-with-errors/76291804#76291804
6
+ ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
7
+ html_tag
8
+ end
9
+
4
10
  def polaris_css version = '13.9.5'
5
11
  major_version = version.split('.').first.to_i
6
12
  if major_version <= 6
@@ -76,6 +82,20 @@ module PolarisViewHelpers
76
82
  )
77
83
  end
78
84
 
85
+ def polaris_inline_error(form, attribute, error)
86
+ render(
87
+ partial: 'polaris/inline_error',
88
+ locals: { form: form, attribute: attribute, error: error }
89
+ )
90
+ end
91
+
92
+ def polaris_form_element_errors(form, attribute)
93
+ render(
94
+ partial: 'polaris/form_element_errors',
95
+ locals: { form: form, attribute: attribute }
96
+ )
97
+ end
98
+
79
99
  def polaris_page(&block)
80
100
  render(
81
101
  partial: 'polaris/page',
@@ -291,6 +311,9 @@ module PolarisViewHelpers
291
311
  end
292
312
 
293
313
  def polaris_text_field(form, attribute, options = {}, element_type = :text_field, &block)
314
+
315
+ additional_classes = options[:additional_classes] || ""
316
+
294
317
  unless attribute.is_a? Array
295
318
  attribute = [attribute]
296
319
  end
@@ -300,6 +323,7 @@ module PolarisViewHelpers
300
323
  locals: {
301
324
  form: form,
302
325
  attribute: attribute,
326
+ additional_classes: additional_classes,
303
327
  element_type: element_type,
304
328
  options: options,
305
329
  block: block
@@ -1,3 +1,3 @@
1
1
  module PolarisViewHelpers
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polaris_view_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Green
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-07-23 00:00:00.000000000 Z
11
+ date: 2025-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -62,11 +62,13 @@ files:
62
62
  - app/views/polaris/_description_list.html.erb
63
63
  - app/views/polaris/_description_list_item.html.erb
64
64
  - app/views/polaris/_footer_help.html.erb
65
+ - app/views/polaris/_form_element_errors.html.erb
65
66
  - app/views/polaris/_form_layout.html.erb
66
67
  - app/views/polaris/_form_layout_item.html.erb
67
68
  - app/views/polaris/_form_layout_item_select.html.erb
68
69
  - app/views/polaris/_heading.html.erb
69
70
  - app/views/polaris/_icon.html.erb
71
+ - app/views/polaris/_inline_error.html.erb
70
72
  - app/views/polaris/_layout.html.erb
71
73
  - app/views/polaris/_layout_section.html.erb
72
74
  - app/views/polaris/_legacy_card.html.erb