playbook_ui 14.14.0.pre.alpha.PBNTR890typeahead6394 → 14.14.0.pre.alpha.PBNTR894allowingcurrencyzero6405

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: 85ec8319ef8383dcbd45605b1c431293afbf510fc625b115b815c820a0f74597
4
- data.tar.gz: c2a828a83f9bf40c4eb691d765dfc4319bbffbbbbad2a2c8b28e3d22b4dc3797
3
+ metadata.gz: 9405959f28812ce17068b3a42e1c9207630234c73aa817005655afd22d708561
4
+ data.tar.gz: 0f3dfd8437117adbf036fe2e692265a6506e99b3755f69eef8a858715661e241
5
5
  SHA512:
6
- metadata.gz: ae4c18ecdc0fad76efba409c039b5c8ecc55f50ce0cf9041a3ce1285683abf50cec01ae9687331d104a2b4fd0d508adeeef0d55996e71ff8038d4c951f55d6de
7
- data.tar.gz: f9fa664003f3b446c12e4a4eb6763a0c163068230954422c10cf03747ed2c303c4ef6cde080df056c707c17dbe462fb0bc0958ddd4a7cf56dfe08ab130e25017
6
+ metadata.gz: d8075de7716d49fc0be0bda75d1be63bdaa3f9a07a8da9df1a3260d1327a8f43d1ebd948ec491c0aedf1404c971f157d6fa6b9d5bdafb79354f5cece6b2e01bd
7
+ data.tar.gz: 8b499830a6806d063e75e4e18f82f564dff2e1453f06a9834970ae4bbea6f8f3956c79676d4223faf8bf428675f8a852b26e283625d3eb1156ae98a181670ec7
@@ -17,7 +17,7 @@ const formatCurrencyDefaultValue = (value: string): string => {
17
17
 
18
18
  // Parse the numeric value as a float to handle decimals
19
19
  const dollars = parseFloat(numericValue)
20
- if (isNaN(dollars) || dollars === 0) return ''
20
+ if (isNaN(dollars)) return ''
21
21
 
22
22
  // Format as currency
23
23
  return new Intl.NumberFormat('en-US', {
@@ -30,10 +30,9 @@ const formatCurrencyDefaultValue = (value: string): string => {
30
30
  const formatCurrency = (value: string): string => {
31
31
  const numericValue = value.replace(/[^0-9]/g, '').slice(0, 15)
32
32
 
33
- if (!numericValue) return ''
33
+ if (!numericValue || numericValue === "00") return ''
34
34
 
35
35
  const dollars = parseFloat((parseInt(numericValue) / 100).toFixed(2))
36
- if (dollars === 0) return ''
37
36
 
38
37
  return new Intl.NumberFormat('en-US', {
39
38
  style: 'currency',
@@ -1,4 +1,4 @@
1
- import React, { useState, useEffect} from 'react'
1
+ import React from 'react'
2
2
  import Select from 'react-select'
3
3
  import AsyncSelect from 'react-select/async'
4
4
  import CreateableSelect from 'react-select/creatable'
@@ -45,12 +45,8 @@ type TypeaheadProps = {
45
45
  getOptionLabel?: string | (() => string),
46
46
  getOptionValue?: string | (() => string),
47
47
  name?: string,
48
- options?: Array<{ label: string; value?: string }>,
49
48
  marginBottom?: "none" | "xxs" | "xs" | "sm" | "md" | "lg" | "xl",
50
49
  pillColor?: "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",
51
- optionsByContext?: Record<string, Array<{ label: string; value?: string }>>
52
- searchContextSelector?: string,
53
- clearOnContextChange?: boolean,
54
50
  } & GlobalProps
55
51
 
56
52
  export type SelectValueType = {
@@ -85,9 +81,6 @@ const Typeahead = ({
85
81
  loadOptions = noop,
86
82
  marginBottom = "sm",
87
83
  pillColor,
88
- optionsByContext = {},
89
- searchContextSelector,
90
- clearOnContextChange = false,
91
84
  ...props
92
85
  }: TypeaheadProps) => {
93
86
  const selectProps = {
@@ -122,32 +115,6 @@ const Typeahead = ({
122
115
  ...props,
123
116
  }
124
117
 
125
- const [contextValue, setContextValue] = useState("")
126
-
127
- useEffect(() => {
128
- if (searchContextSelector) {
129
- const searchContextElement = document.getElementById(searchContextSelector)
130
-
131
- setContextValue((searchContextElement as HTMLInputElement)?.value)
132
- const handleContextChange = (e: Event) => {
133
- const target = e.target as HTMLInputElement;
134
- setContextValue(target.value);
135
- if (clearOnContextChange) document.dispatchEvent(new CustomEvent(`pb-typeahead-kit-${selectProps.id}:clear`))
136
- }
137
-
138
- if (searchContextElement) searchContextElement.addEventListener('change', handleContextChange)
139
-
140
- return () => {
141
- if (searchContextElement) searchContextElement.removeEventListener('change', handleContextChange)
142
- }
143
- }
144
- }, [searchContextSelector])
145
-
146
- const contextArray = optionsByContext[contextValue]
147
- if (Array.isArray(contextArray) && contextArray.length > 0) {
148
- selectProps.options = contextArray
149
- }
150
-
151
118
  const Tag = (
152
119
  createable
153
120
  ? (async ? AsyncCreateableSelect : CreateableSelect)
@@ -12,8 +12,6 @@ examples:
12
12
  - typeahead_margin_bottom: Margin Bottom
13
13
  - typeahead_with_pills_color: With Pills (Custom Color)
14
14
  - typeahead_truncated_text: Truncated Text
15
- - typeahead_dynamic_options: Dynamic Options
16
- - typeahead_dynamic_options_pure_rails: Dynamic Options (Pure Rails)
17
15
 
18
16
  react:
19
17
  - typeahead_default: Default
@@ -20,34 +20,6 @@ export default class PbTypeahead extends PbEnhancedElement {
20
20
  this.searchInput.addEventListener('focus', () => this.debouncedSearch())
21
21
  this.searchInput.addEventListener('input', () => this.debouncedSearch())
22
22
  this.resultsElement.addEventListener('click', (event: MouseEvent) => this.optionSelected(event))
23
-
24
- if (this.clearOnContextChange && this.searchContextElement) {
25
- this.searchContextElement.addEventListener('change', () => {
26
- this.searchInputClear()
27
- this.resultsCacheClear()
28
- this.clearResults()
29
- })
30
- }
31
- }
32
-
33
- get optionsByContext() {
34
- return (this.element as HTMLElement).dataset.pbTypeaheadKitOptionsByContext
35
- ? JSON.parse((this.element as HTMLElement).dataset.pbTypeaheadKitOptionsByContext)
36
- : null
37
- }
38
-
39
- get searchContextElement() {
40
- const selector = (this.element as HTMLElement).dataset.pbTypeaheadKitSearchContextSelector
41
- if (!selector) return null
42
-
43
- const found = this.element.parentNode?.querySelector(`#${selector}`)
44
- || this.element.closest(selector)
45
-
46
- return found || null
47
- }
48
-
49
- get clearOnContextChange() {
50
- return (this.element as HTMLElement).dataset.pbTypeaheadKitClearOnContextChange === 'true'
51
23
  }
52
24
 
53
25
  handleKeydown(event: KeyboardEvent) {
@@ -68,32 +40,14 @@ export default class PbTypeahead extends PbEnhancedElement {
68
40
 
69
41
  const searchTerm = this.searchTerm
70
42
  const searchContext = this.searchContext
71
-
72
- if (this.optionsByContext && Object.keys(this.optionsByContext).length > 0) {
73
- const contextArray = this.optionsByContext[searchContext] || []
74
-
75
- const filteredResults = contextArray.filter((obj: { label: string, value: string }) => {
76
- return obj.label
77
- && obj.label.toLowerCase().includes(searchTerm.toLowerCase())
78
- })
79
-
80
- const optionFragments = filteredResults.map((obj: { label: string, value: string }) => {
81
- const singleOption = document.createDocumentFragment()
82
- singleOption.appendChild(document.createTextNode(obj.label))
83
- return singleOption
84
- })
85
-
86
- this.resultsCacheUpdate(searchTerm, searchContext, optionFragments)
87
- } else {
88
- const search = {
89
- searchingFor: searchTerm,
90
- searchingContext: searchContext,
91
- setResults: (results: Array<DocumentFragment>) => {
92
- this.resultsCacheUpdate(searchTerm, searchContext, results)
93
- },
94
- }
95
- this.element.dispatchEvent(new CustomEvent('pb-typeahead-kit-search', { bubbles: true, detail: search }))
43
+ const search = {
44
+ searchingFor: searchTerm,
45
+ searchingContext: searchContext,
46
+ setResults: (results: Array<DocumentFragment>) => {
47
+ this.resultsCacheUpdate(searchTerm, searchContext, results)
48
+ },
96
49
  }
50
+ this.element.dispatchEvent(new CustomEvent('pb-typeahead-kit-search', { bubbles: true, detail: search }))
97
51
  }
98
52
 
99
53
  resultsCacheUpdate(searchTerm: string, searchContext: string, results: Array<DocumentFragment>) {
@@ -133,15 +87,11 @@ export default class PbTypeahead extends PbEnhancedElement {
133
87
  const resultOption = (event.target as Element).closest('[data-result-option-item]')
134
88
  if (!resultOption) return
135
89
 
136
- const selectedText = resultOption.textContent.trim()
137
-
138
90
  this._validSelection = true
139
91
  this.removeValidationError()
140
92
 
141
- if (this.searchContextElement) this.searchInput.value = selectedText
142
-
143
93
  this.resultsCacheClear()
144
- if (!this.searchContextElement) this.searchInputClear()
94
+ this.searchInputClear()
145
95
  this.clearResults()
146
96
 
147
97
  this.element.dispatchEvent(new CustomEvent('pb-typeahead-kit-result-option-selected', { bubbles: true, detail: { selected: resultOption, typeahead: this } }))
@@ -223,9 +173,6 @@ export default class PbTypeahead extends PbEnhancedElement {
223
173
  this.element.parentNode.querySelector(selector) ||
224
174
  this.element.closest(selector)
225
175
  ) as HTMLInputElement).value
226
- else if (this.searchContextElement) {
227
- return (this.searchContextElement as HTMLInputElement).value
228
- }
229
176
 
230
177
  return null
231
178
  }
@@ -44,12 +44,6 @@ module Playbook
44
44
  default: false
45
45
  prop :validation, type: Playbook::Props::HashProp,
46
46
  default: {}
47
- prop :clear_on_context_change, type: Playbook::Props::Boolean,
48
- default: true
49
- prop :options_by_context, type: Playbook::Props::HashProp,
50
- default: {}
51
- prop :search_context_selector, type: Playbook::Props::String,
52
- default: nil
53
47
 
54
48
  def classname
55
49
  default_margin_bottom = margin_bottom.present? ? "" : " mb_sm"
@@ -64,10 +58,7 @@ module Playbook
64
58
  Hash(values[:data]).merge(
65
59
  pb_typeahead_kit: true,
66
60
  pb_typeahead_kit_search_term_minimum_length: search_term_minimum_length,
67
- pb_typeahead_kit_search_debounce_timeout: search_debounce_timeout,
68
- pb_typeahead_kit_clear_on_context_change: clear_on_context_change,
69
- pb_typeahead_kit_search_context_selector: search_context_selector,
70
- pb_typeahead_kit_options_by_context: options_by_context.to_json
61
+ pb_typeahead_kit_search_debounce_timeout: search_debounce_timeout
71
62
  )
72
63
  end
73
64
 
@@ -94,9 +85,6 @@ module Playbook
94
85
  placeholder: placeholder,
95
86
  plusIcon: plus_icon,
96
87
  truncate: truncate,
97
- searchContextSelector: search_context_selector,
98
- optionsByContext: options_by_context,
99
- clearOnContextChange: clear_on_context_change,
100
88
  }
101
89
 
102
90
  base_options[:getOptionLabel] = get_option_label if get_option_label.present?