playbook_ui 14.14.0.pre.alpha.play1853typeaheadreacthookform6480 → 14.14.0.pre.alpha.play1868dependencyremovallodash6286

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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/pb_card/_card.tsx +2 -1
  3. data/app/pb_kits/playbook/pb_currency/_currency.tsx +31 -46
  4. data/app/pb_kits/playbook/pb_currency/currency.html.erb +8 -15
  5. data/app/pb_kits/playbook/pb_currency/currency.rb +2 -17
  6. data/app/pb_kits/playbook/pb_currency/docs/example.yml +0 -2
  7. data/app/pb_kits/playbook/pb_currency/docs/index.js +1 -2
  8. data/app/pb_kits/playbook/pb_drawer/_drawer.scss +8 -32
  9. data/app/pb_kits/playbook/pb_drawer/docs/_drawer_default.html.erb +1 -20
  10. data/app/pb_kits/playbook/pb_drawer/docs/example.yml +0 -5
  11. data/app/pb_kits/playbook/pb_drawer/drawer.html.erb +12 -20
  12. data/app/pb_kits/playbook/pb_drawer/drawer.rb +1 -49
  13. data/app/pb_kits/playbook/pb_filter/Filter/CurrentFilters.tsx +4 -4
  14. data/app/pb_kits/playbook/pb_filter/Filter/FilterSingle.tsx +2 -2
  15. data/app/pb_kits/playbook/pb_form/docs/_form_form_with_validate.html.erb +1 -1
  16. data/app/pb_kits/playbook/pb_overlay/_overlay.scss +0 -13
  17. data/app/pb_kits/playbook/pb_overlay/_overlay.tsx +1 -7
  18. data/app/pb_kits/playbook/pb_overlay/docs/example.yml +0 -3
  19. data/app/pb_kits/playbook/pb_overlay/docs/index.js +0 -1
  20. data/app/pb_kits/playbook/pb_overlay/overlay.html.erb +3 -5
  21. data/app/pb_kits/playbook/pb_overlay/overlay.rb +1 -16
  22. data/app/pb_kits/playbook/pb_overlay/overlay.test.jsx +0 -12
  23. data/app/pb_kits/playbook/pb_select/select.rb +0 -8
  24. data/app/pb_kits/playbook/pb_tooltip/_tooltip.scss +3 -0
  25. data/app/pb_kits/playbook/pb_tooltip/docs/example.yml +0 -2
  26. data/app/pb_kits/playbook/pb_tooltip/index.js +1 -1
  27. data/app/pb_kits/playbook/pb_tooltip/tooltip.rb +2 -10
  28. data/app/pb_kits/playbook/pb_treemap_chart/_treemap_chart.tsx +5 -4
  29. data/app/pb_kits/playbook/pb_typeahead/_typeahead.tsx +6 -50
  30. data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_with_pills_async_custom_options.jsx +1 -1
  31. data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_with_pills_async_users.jsx +1 -1
  32. data/app/pb_kits/playbook/pb_typeahead/docs/example.yml +0 -3
  33. data/app/pb_kits/playbook/pb_typeahead/docs/index.js +0 -1
  34. data/app/pb_kits/playbook/pb_typeahead/index.ts +8 -61
  35. data/app/pb_kits/playbook/pb_typeahead/typeahead.rb +1 -13
  36. data/app/pb_kits/playbook/utilities/object.ts +82 -1
  37. data/dist/chunks/_typeahead-CHxdYnAw.js +36 -0
  38. data/dist/chunks/_weekday_stacked-D2tZHCNS.js +45 -0
  39. data/dist/chunks/{lib-Dmay5Z6U.js → lib-CrrD678a.js} +2 -2
  40. data/dist/chunks/{pb_form_validation-DdP7BnVX.js → pb_form_validation-BbWhQeoO.js} +1 -1
  41. data/dist/chunks/vendor.js +1 -1
  42. data/dist/menu.yml +2 -2
  43. data/dist/playbook-doc.js +1 -1
  44. data/dist/playbook-rails-react-bindings.js +1 -1
  45. data/dist/playbook-rails.js +1 -1
  46. data/dist/playbook.css +1 -1
  47. data/lib/playbook/version.rb +1 -1
  48. metadata +6 -36
  49. data/app/pb_kits/playbook/pb_currency/docs/_currency_null_display.html.erb +0 -22
  50. data/app/pb_kits/playbook/pb_currency/docs/_currency_null_display.jsx +0 -34
  51. data/app/pb_kits/playbook/pb_currency/docs/_currency_null_display_rails.md +0 -1
  52. data/app/pb_kits/playbook/pb_currency/docs/_currency_null_display_react.md +0 -1
  53. data/app/pb_kits/playbook/pb_drawer/docs/_drawer_behavior.html.erb +0 -8
  54. data/app/pb_kits/playbook/pb_drawer/docs/_drawer_borders.html.erb +0 -33
  55. data/app/pb_kits/playbook/pb_drawer/docs/_drawer_breakpoints.html.erb +0 -0
  56. data/app/pb_kits/playbook/pb_drawer/docs/_drawer_menu.html.erb +0 -24
  57. data/app/pb_kits/playbook/pb_drawer/docs/_drawer_overlay.html.erb +0 -21
  58. data/app/pb_kits/playbook/pb_drawer/docs/_drawer_overlay.md +0 -1
  59. data/app/pb_kits/playbook/pb_drawer/docs/_drawer_sizes.html.erb +0 -49
  60. data/app/pb_kits/playbook/pb_drawer/index.js +0 -257
  61. data/app/pb_kits/playbook/pb_overlay/docs/_overlay_hide_scroll_bar.html.erb +0 -11
  62. data/app/pb_kits/playbook/pb_overlay/docs/_overlay_hide_scroll_bar.jsx +0 -37
  63. data/app/pb_kits/playbook/pb_overlay/docs/_overlay_hide_scroll_bar_rails.md +0 -1
  64. data/app/pb_kits/playbook/pb_overlay/docs/_overlay_hide_scroll_bar_react.md +0 -1
  65. data/app/pb_kits/playbook/pb_overlay/docs/_overlay_vertical_dynamic_multi_directional.html.erb +0 -11
  66. data/app/pb_kits/playbook/pb_overlay/docs/_overlay_vertical_dynamic_multi_directional.md +0 -1
  67. data/app/pb_kits/playbook/pb_overlay/index.js +0 -61
  68. data/app/pb_kits/playbook/pb_select/index.js +0 -38
  69. data/app/pb_kits/playbook/pb_tooltip/docs/_tooltip_delay_rails.html.erb +0 -39
  70. data/app/pb_kits/playbook/pb_tooltip/docs/_tooltip_delay_rails.md +0 -3
  71. data/app/pb_kits/playbook/pb_tooltip/docs/_tooltip_interaction.html.erb +0 -26
  72. data/app/pb_kits/playbook/pb_tooltip/floating_ui.js +0 -282
  73. data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_dynamic_options.html.erb +0 -45
  74. data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_dynamic_options.md +0 -5
  75. data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_dynamic_options_pure_rails.html.erb +0 -33
  76. data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_dynamic_options_pure_rails.md +0 -3
  77. data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_react_hook.jsx +0 -66
  78. data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_react_hook.md +0 -1
  79. data/dist/chunks/_typeahead-UlgRmF4g.js +0 -36
  80. data/dist/chunks/_weekday_stacked-BNybn-aH.js +0 -45
@@ -141,6 +141,7 @@ $tooltip_shadow: rgba(60, 106, 172, 0.18);
141
141
 
142
142
  &[data-popper-placement="right"] {
143
143
  box-shadow: -8px 0 28px 0 $tooltip_shadow;
144
+ margin: 0 0 0 $space_sm;
144
145
  .arrow {
145
146
  left: -18px;
146
147
  right: auto;
@@ -155,6 +156,7 @@ $tooltip_shadow: rgba(60, 106, 172, 0.18);
155
156
 
156
157
  &[data-popper-placement="bottom"] {
157
158
  box-shadow: 0 -12px 28px 0 $tooltip_shadow;
159
+ margin: $space_sm 0 0 0;
158
160
  .arrow {
159
161
  top: -18px;
160
162
  margin-bottom: 0;
@@ -167,6 +169,7 @@ $tooltip_shadow: rgba(60, 106, 172, 0.18);
167
169
 
168
170
  &[data-popper-placement="left"] {
169
171
  box-shadow: 8px 0 28px 0 $tooltip_shadow;
172
+ margin: 0 $space_sm 0 0;
170
173
  .arrow {
171
174
  margin-bottom: 0;
172
175
  right: -18px;
@@ -2,10 +2,8 @@ examples:
2
2
 
3
3
  rails:
4
4
  - tooltip_default: Default
5
- - tooltip_interaction: Content Interaction
6
5
  - tooltip_selectors: Using Common Selectors
7
6
  - tooltip_with_icon_circle: Icon Circle Tooltip
8
- - tooltip_delay_rails: Delay
9
7
  - tooltip_show_tooltip: Show Tooltip
10
8
 
11
9
  react:
@@ -11,7 +11,7 @@ const TOOLTIP_TIMEOUT = 250
11
11
 
12
12
  export default class PbTooltip extends PbEnhancedElement {
13
13
  static get selector() {
14
- return '[data-pb-tooltip-kit="true"][data-pb-tooltip-interaction="false"]:not([data-pb-tooltip-delay-open]):not([data-pb-tooltip-delay-close])'
14
+ return '[data-pb-tooltip-kit]'
15
15
  }
16
16
 
17
17
  connect() {
@@ -7,10 +7,6 @@ module Playbook
7
7
  prop :trigger_element_selector
8
8
  prop :trigger_element_id, deprecated: true
9
9
  prop :tooltip_id
10
- prop :interaction, type: Playbook::Props::Boolean,
11
- default: false
12
- prop :delay_open
13
- prop :delay_close
14
10
  prop :dark, type: Playbook::Props::Boolean,
15
11
  default: false
16
12
  prop :trigger_method, type: Playbook::Props::Enum,
@@ -22,19 +18,15 @@ module Playbook
22
18
  end
23
19
 
24
20
  def data
25
- data = Hash(values[:data]).merge(
21
+ Hash(values[:data]).merge(
26
22
  pb_tooltip_kit: true,
27
23
  pb_tooltip_position: position,
28
24
  pb_tooltip_trigger_element_selector: trigger_element_selector,
29
25
  pb_tooltip_trigger_element_id: trigger_element_id,
30
26
  pb_tooltip_tooltip_id: tooltip_id,
31
27
  pb_tooltip_show_tooltip: true,
32
- pb_tooltip_trigger_method: trigger_method,
33
- pb_tooltip_interaction: interaction
28
+ pb_tooltip_trigger_method: trigger_method
34
29
  )
35
- data = data.merge(pb_tooltip_delay_open: delay_open) if delay_open
36
- data = data.merge(pb_tooltip_delay_close: delay_close) if delay_close
37
- data
38
30
  end
39
31
 
40
32
  private
@@ -10,7 +10,8 @@ import { highchartsTheme } from "../pb_dashboard/pbChartsLightTheme";
10
10
  import { highchartsDarkTheme } from "../pb_dashboard/pbChartsDarkTheme";
11
11
  import mapColors from "../pb_dashboard/pbChartsColorsHelper";
12
12
  import treemap from 'highcharts/modules/treemap'
13
- import { merge } from 'lodash'
13
+ import { merge} from '../utilities/object'
14
+
14
15
 
15
16
  type TreemapChartProps = {
16
17
  chartData: {
@@ -53,7 +54,7 @@ const TreemapChart = ({
53
54
  type = "treemap",
54
55
  ...props
55
56
  }: TreemapChartProps): React.ReactElement => {
56
-
57
+
57
58
  const ariaProps = buildAriaProps(aria)
58
59
  const dataProps = buildDataProps(data)
59
60
  const htmlProps = buildHtmlProps(htmlOptions)
@@ -62,9 +63,9 @@ const TreemapChart = ({
62
63
  dark
63
64
  ? Highcharts.setOptions(highchartsDarkTheme)
64
65
  : Highcharts.setOptions(highchartsTheme);
65
- };
66
+ };
66
67
  treemap(Highcharts)
67
- setupTheme();
68
+ setupTheme();
68
69
 
69
70
  const staticOptions = {
70
71
  title: {
@@ -1,9 +1,10 @@
1
- import React, { useState, useEffect, forwardRef} 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'
5
5
  import AsyncCreateableSelect from 'react-select/async-creatable'
6
- import { get, isString, uniqueId } from 'lodash'
6
+ import { get, isString, uniqueId } from '../utilities/object'
7
+
7
8
  import { globalProps, GlobalProps } from '../utilities/globalProps'
8
9
  import classnames from 'classnames'
9
10
 
@@ -45,13 +46,8 @@ type TypeaheadProps = {
45
46
  getOptionLabel?: string | (() => string),
46
47
  getOptionValue?: string | (() => string),
47
48
  name?: string,
48
- options?: Array<{ label: string; value?: string }>,
49
49
  marginBottom?: "none" | "xxs" | "xs" | "sm" | "md" | "lg" | "xl",
50
50
  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
- onChange?: any,
52
- optionsByContext?: Record<string, Array<{ label: string; value?: string }>>
53
- searchContextSelector?: string,
54
- clearOnContextChange?: boolean,
55
51
  } & GlobalProps
56
52
 
57
53
  export type SelectValueType = {
@@ -71,7 +67,8 @@ type TagOnChangeValues = {
71
67
  * @constant {React.ReactComponent} Typeahead
72
68
  * @param {TypeaheadProps} props - props as described at https://react-select.com/props
73
69
  */
74
- const Typeahead = forwardRef<HTMLInputElement, TypeaheadProps>(({
70
+
71
+ const Typeahead = ({
75
72
  async,
76
73
  className,
77
74
  components = {},
@@ -82,14 +79,9 @@ const Typeahead = forwardRef<HTMLInputElement, TypeaheadProps>(({
82
79
  getOptionValue,
83
80
  htmlOptions = {},
84
81
  id,
85
- name,
86
82
  loadOptions = noop,
87
83
  marginBottom = "sm",
88
84
  pillColor,
89
- onChange,
90
- optionsByContext = {},
91
- searchContextSelector,
92
- clearOnContextChange = false,
93
85
  ...props
94
86
  }: TypeaheadProps) => {
95
87
  const selectProps = {
@@ -124,32 +116,6 @@ const Typeahead = forwardRef<HTMLInputElement, TypeaheadProps>(({
124
116
  ...props,
125
117
  }
126
118
 
127
- const [contextValue, setContextValue] = useState("")
128
-
129
- useEffect(() => {
130
- if (searchContextSelector) {
131
- const searchContextElement = document.getElementById(searchContextSelector)
132
-
133
- setContextValue((searchContextElement as HTMLInputElement)?.value)
134
- const handleContextChange = (e: Event) => {
135
- const target = e.target as HTMLInputElement;
136
- setContextValue(target.value);
137
- if (clearOnContextChange) document.dispatchEvent(new CustomEvent(`pb-typeahead-kit-${selectProps.id}:clear`))
138
- }
139
-
140
- if (searchContextElement) searchContextElement.addEventListener('change', handleContextChange)
141
-
142
- return () => {
143
- if (searchContextElement) searchContextElement.removeEventListener('change', handleContextChange)
144
- }
145
- }
146
- }, [searchContextSelector])
147
-
148
- const contextArray = optionsByContext[contextValue]
149
- if (Array.isArray(contextArray) && contextArray.length > 0) {
150
- selectProps.options = contextArray
151
- }
152
-
153
119
  const Tag = (
154
120
  createable
155
121
  ? (async ? AsyncCreateableSelect : CreateableSelect)
@@ -157,15 +123,6 @@ const Typeahead = forwardRef<HTMLInputElement, TypeaheadProps>(({
157
123
  )
158
124
 
159
125
  const handleOnChange = (_data: SelectValueType, { action, option, removedValue }: TagOnChangeValues) => {
160
- if (onChange) {
161
- const isReactHookForm = onChange.toString().includes("target")
162
- if (isReactHookForm) {
163
- onChange({ target: { name, value: _data } })
164
- } else {
165
- onChange(_data)
166
- }
167
- }
168
-
169
126
  if (action === 'select-option') {
170
127
  if (selectProps.onMultiValueClick) selectProps.onMultiValueClick(option)
171
128
  const multiValueClearEvent = new CustomEvent(`pb-typeahead-kit-${selectProps.id}-result-option-select`, { detail: option ? option : _data })
@@ -209,11 +166,10 @@ const Typeahead = forwardRef<HTMLInputElement, TypeaheadProps>(({
209
166
  />
210
167
  </div>
211
168
  )
212
- })
169
+ }
213
170
 
214
171
  Object.keys(kitComponents).forEach((k) => {
215
172
  (Typeahead as GenericObject)[k] = (kitComponents as {[key: string]: unknown})[k]
216
173
  })
217
174
 
218
- Typeahead.displayName = 'Typeahead'
219
175
  export default Typeahead
@@ -49,7 +49,7 @@ const TypeaheadWithPillsAsyncCustomOptions = (props) => {
49
49
  * @summary - for doc example purposes only
50
50
  */
51
51
  const handleOnMultiValueClick = (value) => {
52
- alert(`You added the user: "${value.label}"`)
52
+ alert(`You removed the user: "${value.label}"`)
53
53
  }
54
54
 
55
55
  return (
@@ -56,7 +56,7 @@ const TypeaheadWithPillsAsyncUsers = (props) => {
56
56
  * @summary - for doc example purposes only
57
57
  */
58
58
  const handleOnMultiValueClick = (value) => {
59
- alert(`You added the user: "${value.label}"`)
59
+ alert(`You removed the user: "${value.label}"`)
60
60
  }
61
61
 
62
62
  return (
@@ -12,12 +12,9 @@ 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
- - typeahead_react_hook: React Hook
21
18
  - typeahead_with_highlight: With Highlight
22
19
  - typeahead_with_pills: With Pills
23
20
  - typeahead_with_pills_async: With Pills (Async Data)
@@ -13,4 +13,3 @@ export { default as TypeaheadCustomMenuList } from './_typeahead_custom_menu_lis
13
13
  export { default as TypeaheadMarginBottom } from './_typeahead_margin_bottom.jsx'
14
14
  export { default as TypeaheadWithPillsColor } from './_typeahead_with_pills_color.jsx'
15
15
  export { default as TypeaheadTruncatedText } from './_typeahead_truncated_text.jsx'
16
- export { default as TypeaheadReactHook } from './_typeahead_react_hook.jsx'
@@ -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?
@@ -1,3 +1,84 @@
1
1
  /* 🛠️ Any commonly used lodash functions can be added here. 🤙 */
2
2
 
3
- export const isEmpty = (obj: Record<string, unknown>): boolean => Object.keys(obj).length < 1
3
+ export const isEmpty = (obj: any) => [Object, Array].includes((obj || {}).constructor) && !Object.entries((obj || {})).length;
4
+
5
+ export const get = <T, R = any>(obj: T, path: string, defaultValue?: R): R | any => {
6
+ const travel = (regexp: RegExp): any =>
7
+ String.prototype.split
8
+ .call(path, regexp)
9
+ .filter(Boolean)
10
+ .reduce((res: any, key: string) => (res !== null && res !== undefined ? res[key] : res), obj)
11
+ const result = travel(/[,[\]]+?/) || travel(/[,[\].]+?/)
12
+ return result === undefined || result === obj ? defaultValue : result
13
+ }
14
+
15
+ export const map = <T, U>(
16
+ collection: T[] | Record<string, T> | null | undefined,
17
+ iteratee: (value: any, key: string, collection: T[] | Record<string, T>) => U
18
+ ): U[] => {
19
+ if (!collection) return []
20
+ const coerce = (val: any) => {
21
+ if (val === true) return val
22
+ if (
23
+ typeof val === "number" ||
24
+ typeof val === "string" ||
25
+ typeof val === "boolean" ||
26
+ val === null
27
+ )
28
+ return String(val)
29
+ return val
30
+ }
31
+ return Array.isArray(collection)
32
+ ? collection.map((v, i) => iteratee(coerce(v), String(i), collection))
33
+ : Object.keys(collection).map(key => iteratee(coerce(collection[key]), key, collection))
34
+ }
35
+
36
+ export const isString = (str: unknown): str is string =>
37
+ str != null && typeof (str as any).valueOf() === "string"
38
+
39
+ export const omitBy = <T extends Record<string, any>>(
40
+ obj: T,
41
+ predicate: (value: T[keyof T], key: string) => boolean
42
+ ): Partial<T> => {
43
+ if (obj === null || typeof obj !== 'object') return {} as Partial<T>
44
+ return Object.keys(obj).reduce((result, key) => {
45
+ const typedKey = key as keyof T
46
+ if (!predicate(obj[typedKey], key)) {
47
+ result[typedKey] = obj[typedKey]
48
+ }
49
+ return result
50
+ }, {} as Partial<T>)
51
+ }
52
+
53
+ export const uniqueId: (prefix?: string) => string = (() => {
54
+ let counter = 0
55
+ return (prefix = '') => `${prefix}${++counter}`
56
+ })()
57
+
58
+ type PlainObject = { [key: string]: any }
59
+
60
+ const isObject = (item: any): item is PlainObject =>
61
+ item !== null && typeof item === 'object'
62
+
63
+ export const merge = <T extends PlainObject>(
64
+ target: T,
65
+ ...sources: PlainObject[]
66
+ ): T => {
67
+ if (!sources.length) return target
68
+ const source = sources.shift()!
69
+ if (isObject(target) && isObject(source)) {
70
+ Object.keys(source).forEach((key: string) => {
71
+ const typedKey = key as keyof T
72
+ const srcValue = source[key]
73
+ if (isObject(srcValue)) {
74
+ if (!target[typedKey]) {
75
+ target[typedKey] = (Array.isArray(srcValue) ? [] : {}) as unknown as T[typeof typedKey]
76
+ }
77
+ merge(target[typedKey], srcValue)
78
+ } else {
79
+ target[typedKey] = srcValue
80
+ }
81
+ })
82
+ }
83
+ return merge(target, ...sources)
84
+ }