playbook_ui 14.7.0.pre.alpha.PBNTR667railstypeaheadformintegration4454 → 14.7.0.pre.alpha.dependabotnpmandyarnintltelinput24704448

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: 5ba8b6ebdd4078924cdcecd475be6892960449af516b17143f79b6475a4f0162
4
- data.tar.gz: ab99598eb62828f045a9f61622b5b0d036e07a410a410004b9ed0ca29ab1630c
3
+ metadata.gz: af27bbc68c5af9c78ae2a7ea4b8fec2f9dc7226d41a138c38ada6b3cb5e8b03b
4
+ data.tar.gz: 33704917fbbfc70e3ba6f1e5193085237b8ed7fd1c85e776dbbbacd3e3423e90
5
5
  SHA512:
6
- metadata.gz: 644594e1a5ff791f14904f59c7b959d9d22bb22f7ef5c148dd37449608a2b86248cdf452a1a6b3eecf3a826c0867f10709c5464588a61cec763c5fc1bf7acbd2
7
- data.tar.gz: 2c26b39a37968e5cc44bd2bdb135bad81d67c624b9ae3b47bdcb2f58e76efbb965ae6d510bbec45f859c2a0a0401661dd3149a3a748a91a9b613eb98593a4408
6
+ metadata.gz: edebbf85a4e8f8d4b87614225aaf4a0fa565739709ecd8b2b9bbe032e606184e4ef855d34a7e714d8ca5bf0afffa5ed2a5d9ae3f086b001c59c4e0726adaf434
7
+ data.tar.gz: 1ea48f5e83772d3f33682e8456fc1250a3fe4eeaf5d75937fe1d608578f52a53968f2c47976267f3ddbe9a0b7a02d7ee5b5e66d66d7a4ca387cc81a94b620e0d
@@ -23,7 +23,7 @@
23
23
  %>
24
24
 
25
25
  <%= pb_form_with(scope: :example, url: "", method: :get) do |form| %>
26
- <%= form.typeahead :example_typeahead, props: { data: { typeahead_example1: true, user: {} }, label: true, placeholder: "Search for a user" } %>
26
+ <%= form.typeahead :example_user, props: { data: { typeahead_example1: true, user: {} }, placeholder: "Search for a user" } %>
27
27
  <%= form.text_field :example_text_field, props: { label: true } %>
28
28
  <%= form.phone_number_field :example_phone_number_field, props: { label: "Example phone field" } %>
29
29
  <%= form.email_field :example_email_field, props: { label: true } %>
@@ -92,7 +92,7 @@
92
92
  const selectedUserData = JSON.parse(selectedUserJSON)
93
93
 
94
94
  // set the input field's value
95
- event.target.querySelector('input[name=example_typeahead]').value = selectedUserData.login
95
+ event.target.querySelector('input[name=example_user]').value = selectedUserData.login
96
96
 
97
97
  // log the selected option's dataset
98
98
  console.log('The selected user data:')
@@ -1,5 +1,5 @@
1
1
  <%= pb_form_with(scope: :example, url: "", method: :get, loading: true) do |form| %>
2
- <%= form.text_field :example_text_field_loading, props: { label: true } %>
2
+ <%= form.text_field :example_text_field, props: { label: true } %>
3
3
 
4
4
  <%= form.actions do |action| %>
5
5
  <%= action.submit %>
@@ -22,74 +22,23 @@
22
22
  %>
23
23
 
24
24
  <%= pb_form_with(scope: :example, method: :get, url: "", validate: true) do |form| %>
25
- <%= form.typeahead :example_typeahead_validation, props: { data: { typeahead_example2: true, user: {} }, label: true, placeholder: "Search for a user", required: true, validation: { message: "Please select a user." } } %>
26
- <%= form.text_field :example_text_field_validation, props: { label: true, required: true } %>
27
- <%= form.phone_number_field :example_phone_number_field_validation, props: { label: "Example phone field" } %>
28
- <%= form.email_field :example_email_field_validation, props: { label: true, required: true } %>
29
- <%= form.number_field :example_number_field_validation, props: { label: true, required: true } %>
30
- <%= form.search_field :example_project_number_validation, props: { label: true, required: true, validation: { pattern: "[0-9]{2}-[0-9]{5}", message: "Please enter a valid project number (example: 33-12345)." } } %>
31
- <%= form.password_field :example_password_field_validation, props: { label: true, required: true } %>
32
- <%= form.url_field :example_url_field_validation, props: { label: true, required: true } %>
33
- <%= form.text_area :example_text_area_validation, props: { label: true, required: true } %>
34
- <%= form.dropdown_field :example_dropdown_validation, props: { label: true, options: example_dropdown_options, required: true } %>
35
- <%= form.select :example_select_validation, [ ["Yes", 1], ["No", 2] ], props: { label: true, blank_selection: "Select One...", required: true } %>
36
- <%= form.collection_select :example_collection_select_validation, example_collection, :value, :name, props: { label: true, blank_selection: "Select One...", required: true } %>
25
+ <%= form.text_field :example_text_field, props: { label: true, required: true } %>
26
+ <%= form.phone_number_field :example_phone_number_field, props: { label: "Example phone field" } %>
27
+ <%= form.email_field :example_email_field, props: { label: true, required: true } %>
28
+ <%= form.number_field :example_number_field, props: { label: true, required: true } %>
29
+ <%= form.search_field :example_project_number, props: { label: true, required: true, validation: { pattern: "[0-9]{2}-[0-9]{5}", message: "Please enter a valid project number (example: 33-12345)." } } %>
30
+ <%= form.password_field :example_password_field, props: { label: true, required: true } %>
31
+ <%= form.url_field :example_url_field, props: { label: true, required: true } %>
32
+ <%= form.text_area :example_text_area, props: { label: true, required: true } %>
33
+ <%= form.dropdown_field :example_dropdown, props: { label: true, options: example_dropdown_options, required: true } %>
34
+ <%= form.select :example_select, [ ["Yes", 1], ["No", 2] ], props: { label: true, blank_selection: "Select One...", required: true } %>
35
+ <%= form.collection_select :example_collection_select, example_collection, :value, :name, props: { label: true, blank_selection: "Select One...", required: true } %>
37
36
  <%= form.check_box :example_checkbox, props: { text: "Example Checkbox", label: true, required: true } %>
38
37
  <%= form.date_picker :example_date_picker_2, props: { label: true, required: true } %>
39
- <%= form.star_rating_field :example_star_rating_validation, props: { variant: "interactive", label: true, required: true } %>
38
+ <%= form.star_rating_field :example_star_rating, props: { variant: "interactive", label: true, required: true } %>
40
39
 
41
40
  <%= form.actions do |action| %>
42
41
  <%= action.submit %>
43
42
  <%= action.button props: { type: "reset", text: "Cancel", variant: "secondary" } %>
44
43
  <% end %>
45
44
  <% end %>
46
-
47
- <!-- form.typeahead user results example template -->
48
- <template data-typeahead-example-result-option>
49
- <%= pb_rails("user", props: {
50
- name: tag(:slot, name: "name"),
51
- orientation: "horizontal",
52
- align: "left",
53
- avatar_url: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGP6zwAAAgcBApocMXEAAAAASUVORK5CYII=",
54
- avatar: true
55
- }) %>
56
- </template>
57
-
58
- <!-- form.typeahead JS example implementation -->
59
- <%= javascript_tag defer: "defer" do %>
60
- document.addEventListener("pb-typeahead-kit-search", function(event) {
61
- if (!event.target.dataset || !event.target.dataset.typeaheadExample2) return
62
-
63
- fetch(`https://api.github.com/search/users?q=${encodeURIComponent(event.detail.searchingFor)}`)
64
- .then(response => response.json())
65
- .then((result) => {
66
- const resultOptionTemplate = document.querySelector("[data-typeahead-example-result-option]")
67
-
68
- event.detail.setResults((result.items || []).map((user) => {
69
- const wrapper = resultOptionTemplate.content.cloneNode(true)
70
- wrapper.children[0].dataset.user = JSON.stringify(user)
71
- wrapper.querySelector('slot[name="name"]').replaceWith(user.login)
72
- wrapper.querySelector('img').dataset.src = user.avatar_url
73
- return wrapper
74
- }))
75
- })
76
- })
77
-
78
-
79
- document.addEventListener("pb-typeahead-kit-result-option-selected", function(event) {
80
- if (!event.target.dataset.typeaheadExample2) return
81
-
82
- const selectedUserJSON = event.detail.selected.firstElementChild.dataset.user
83
- const selectedUserData = JSON.parse(selectedUserJSON)
84
-
85
- // set the input field's value
86
- event.target.querySelector('input[name=example_typeahead_validation]').value = selectedUserData.login
87
-
88
- // log the selected option's dataset
89
- console.log('The selected user data:')
90
- console.dir(selectedUserData)
91
-
92
- // do even more with the data later - TBD
93
- event.target.dataset.user = selectedUserJSON
94
- })
95
- <% end %>
@@ -4,12 +4,11 @@ import { debounce } from 'lodash'
4
4
  export default class PbTypeahead extends PbEnhancedElement {
5
5
  _searchInput: HTMLInputElement
6
6
  _resultsElement: HTMLElement
7
- _debouncedSearch: () => void
7
+ _debouncedSearch: Function
8
8
  _resultsLoadingIndicator: HTMLElement
9
9
  _resultOptionTemplate: HTMLElement
10
10
  _resultsOptionCache: Map<string, Array<DocumentFragment>>
11
11
  _searchContext: string
12
- _validSelection: boolean
13
12
 
14
13
  static get selector() {
15
14
  return '[data-pb-typeahead-kit]'
@@ -20,7 +19,6 @@ export default class PbTypeahead extends PbEnhancedElement {
20
19
  this.searchInput.addEventListener('focus', () => this.debouncedSearch())
21
20
  this.searchInput.addEventListener('input', () => this.debouncedSearch())
22
21
  this.resultsElement.addEventListener('click', (event: MouseEvent) => this.optionSelected(event))
23
- this.element.closest('form')?.addEventListener('submit', (event) => this.handleFormSubmission(event))
24
22
  }
25
23
 
26
24
  handleKeydown(event: KeyboardEvent) {
@@ -88,9 +86,6 @@ export default class PbTypeahead extends PbEnhancedElement {
88
86
  const resultOption = (event.target as Element).closest('[data-result-option-item]')
89
87
  if (!resultOption) return
90
88
 
91
- this._validSelection = true
92
- this.removeValidationError()
93
-
94
89
  this.resultsCacheClear()
95
90
  this.searchInputClear()
96
91
  this.clearResults()
@@ -98,35 +93,6 @@ export default class PbTypeahead extends PbEnhancedElement {
98
93
  this.element.dispatchEvent(new CustomEvent('pb-typeahead-kit-result-option-selected', { bubbles: true, detail: { selected: resultOption, typeahead: this } }))
99
94
  }
100
95
 
101
- removeValidationError() {
102
- const inputWrapper = this.searchInput.closest('.text_input_wrapper')
103
- if (inputWrapper) {
104
- const errorMessage = inputWrapper.querySelector('.pb_body_kit_negative') as HTMLElement
105
- if (errorMessage) {
106
- errorMessage.style.display = 'none'
107
- }
108
- this.searchInput.classList.remove('error')
109
- }
110
- }
111
-
112
- showValidationError() {
113
- const inputWrapper = this.searchInput.closest('.text_input_wrapper')
114
- if (inputWrapper) {
115
- const errorMessage = inputWrapper.querySelector('.pb_body_kit_negative') as HTMLElement
116
- if (errorMessage) {
117
- errorMessage.style.display = 'block'
118
- }
119
- this.searchInput.classList.add('error')
120
- }
121
- }
122
-
123
- handleFormSubmission(event: Event) {
124
- if (!this._validSelection) {
125
- this.showValidationError()
126
- event.preventDefault()
127
- }
128
- }
129
-
130
96
  clearResults() {
131
97
  this.resultsElement.innerHTML = ''
132
98
  }
@@ -235,7 +201,7 @@ export default class PbTypeahead extends PbEnhancedElement {
235
201
  }
236
202
 
237
203
  toggleResultsLoadingIndicator(visible: boolean) {
238
- let visibilityProperty = '0'
204
+ var visibilityProperty = '0'
239
205
  if (visible) visibilityProperty = '1'
240
206
  this.resultsLoadingIndicator.style.opacity = visibilityProperty
241
207
  }
@@ -17,14 +17,11 @@
17
17
  <%= pb_rails("text_input", props: {
18
18
  type: "search",
19
19
  input_options: object.input_options,
20
+ label: object.label,
20
21
  name: object.name,
21
22
  value: object.value,
22
23
  placeholder: object.placeholder,
23
24
  margin_bottom: "none",
24
- required: object.required,
25
- validation: object.validation,
26
- label: object.label,
27
- id: object.input_options[:id],
28
25
  }) %>
29
26
  <%= pb_rails("list", props: { ordered: false, borderless: false, xpadding: true, role: "status", aria: { live: "polite" }, data: { pb_typeahead_kit_results: true } }) do %>
30
27
  <% end %>
@@ -36,4 +33,4 @@
36
33
  <% end %>
37
34
  </template>
38
35
  <% end %>
39
- <% end %>
36
+ <% end %>
@@ -40,10 +40,6 @@ module Playbook
40
40
  prop :pill_color, type: Playbook::Props::Enum,
41
41
  values: %w[primary neutral success warning error info data_1 data_2 data_3 data_4 data_5 data_6 data_7 data_8 windows siding roofing doors gutters solar insulation accessories],
42
42
  default: "primary"
43
- prop :required, type: Playbook::Props::Boolean,
44
- default: false
45
- prop :validation, type: Playbook::Props::HashProp,
46
- default: {}
47
43
 
48
44
  def classname
49
45
  default_margin_bottom = margin_bottom.present? ? "" : " mb_sm"