playbook_ui 14.20.0.pre.alpha.PLAY21817891 → 14.20.0.pre.alpha.PLAY22297977

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 (26) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/pb_dropdown/dropdown.test.jsx +108 -2
  3. data/app/pb_kits/playbook/pb_phone_number_input/_phone_number_input.tsx +4 -0
  4. data/app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_exclude_countries.html.erb +4 -0
  5. data/app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_exclude_countries.jsx +15 -0
  6. data/app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_exclude_countries.md +1 -0
  7. data/app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_only_countries.jsx +1 -1
  8. data/app/pb_kits/playbook/pb_phone_number_input/docs/example.yml +4 -3
  9. data/app/pb_kits/playbook/pb_phone_number_input/docs/index.js +1 -0
  10. data/app/pb_kits/playbook/pb_phone_number_input/phone_number_input.rb +3 -0
  11. data/app/pb_kits/playbook/pb_popover/index.ts +9 -4
  12. data/app/pb_kits/playbook/pb_select/docs/_select_custom_select_subheaders.html.erb +12 -0
  13. data/app/pb_kits/playbook/pb_select/docs/_select_custom_select_subheaders.jsx +31 -0
  14. data/app/pb_kits/playbook/pb_select/docs/_select_custom_select_subheaders.md +1 -0
  15. data/app/pb_kits/playbook/pb_select/docs/example.yml +2 -0
  16. data/app/pb_kits/playbook/pb_select/docs/index.js +1 -0
  17. data/dist/chunks/{_typeahead-BmOWdDtp.js → _typeahead-VzsSrRRE.js} +2 -2
  18. data/dist/chunks/{_weekday_stacked-CvcuQyr9.js → _weekday_stacked-CJXn2tIy.js} +1 -1
  19. data/dist/chunks/{lib-D5R1BjUn.js → lib-DidmRoMy.js} +1 -1
  20. data/dist/chunks/{pb_form_validation-BZ2AVAi_.js → pb_form_validation-pZDU9eKo.js} +1 -1
  21. data/dist/chunks/vendor.js +1 -1
  22. data/dist/playbook-doc.js +2 -2
  23. data/dist/playbook-rails-react-bindings.js +1 -1
  24. data/dist/playbook-rails.js +1 -1
  25. data/lib/playbook/version.rb +1 -1
  26. metadata +12 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5a669085171e48d532ab250fafc5318cfd95de42e5fde3532fce1f00466de61
4
- data.tar.gz: 966679c3c529eda79c5e1151c97930649ff3df364c66ff7ad9e6f586a49f951b
3
+ metadata.gz: 568382ec2065d6118e310b6422043ba768ccd7b21cfbaeabdc236ec3b78c9a74
4
+ data.tar.gz: 135cc4f942f1458295d3d86e26e6689d12694440bcce0399b215046575f0e6ee
5
5
  SHA512:
6
- metadata.gz: bdbf9b7a3bf06917c740253861ec71609c3c3407312e8706897fc1bd2dc2952cbeeed819ec449a93b0f261c6af7a163c0e07aaf63a47a24cbf2e03fda0e6a053
7
- data.tar.gz: 3ffacae8137dce92ae4f612cd7bd5fb08f7985c2bc85f664f666697fb5961c0a41c1caf5b49fac84525b1c938f7250a5f7d441a6ac7def209ac09f6ff885426d
6
+ metadata.gz: a905f1115cdf1922566c222365d7cbca6b09d2bdf39b2e7ba536bb057d3e040f643731819b82920ed78b4095ce3983cf7086a184d92f49e696abf615e39e2b40
7
+ data.tar.gz: 0fe50c5c469fba1187b0bb367f8c8130ace090e5cba6b28fbfbff44c43a3b7d66670db6852c496ea6b20617fad43dd3c0450745544fd70332d28439dfed0671d
@@ -1,5 +1,5 @@
1
1
  import React from "react"
2
- import { render, screen } from "../utilities/test-utils"
2
+ import { render, screen, fireEvent } from "../utilities/test-utils"
3
3
 
4
4
  import { Dropdown, Icon, IconCircle } from 'playbook-ui'
5
5
 
@@ -263,4 +263,110 @@ test("searchbar prop to render TextInput in container", () => {
263
263
  const kit = screen.getByTestId(testId)
264
264
  const searchbar = kit.querySelector('.pb_text_input_kit')
265
265
  expect(searchbar).toBeInTheDocument()
266
- })
266
+ })
267
+
268
+ test("MultiSelect prop to allow multiple selections + add correct Form Pills", () => {
269
+ render(
270
+ <Dropdown
271
+ data={{ testid: testId }}
272
+ multiSelect
273
+ options={options}
274
+ />
275
+ );
276
+
277
+ const kit = screen.getByTestId(testId);
278
+ const option = Array.from(kit.querySelectorAll(".pb_dropdown_option_list"));
279
+ fireEvent.click(option[0]); // Select first option
280
+ fireEvent.click(option[1]); // Select second option
281
+ const formPills = kit.querySelectorAll(".pb_form_pill_kit_primary");
282
+ expect(formPills.length).toBe(2);
283
+ expect(formPills[0]).toHaveTextContent("United States");
284
+ expect(formPills[1]).toHaveTextContent("Canada");
285
+ });
286
+
287
+ test("hides each selected option from the dropdown", () => {
288
+
289
+ render(
290
+ <Dropdown
291
+ data={{ testid: testId }}
292
+ multiSelect
293
+ options={options}
294
+ />
295
+ );
296
+
297
+ const kit = screen.getByTestId(testId);
298
+ const option = Array.from(kit.querySelectorAll(".pb_dropdown_option_list"));
299
+ const firstOpt = options[0].label
300
+ fireEvent.click(option[0]);
301
+ const option2 = Array.from(kit.querySelectorAll(".pb_dropdown_option_list"));
302
+ expect(option2[0]).not.toHaveTextContent(firstOpt)
303
+ })
304
+
305
+ test("renders form pills inside trigger", () => {
306
+ render(
307
+ <Dropdown
308
+ data={{ testid: testId }}
309
+ multiSelect
310
+ options={options}
311
+ />
312
+ );
313
+
314
+ const kit = screen.getByTestId(testId)
315
+ const option = kit.querySelector('.pb_dropdown_option_list')
316
+ fireEvent.click(option)
317
+ const formPill = kit.querySelector(".pb_form_pill_kit_primary")
318
+ expect(formPill).toBeInTheDocument()
319
+ })
320
+
321
+ test("multiSelect and autocomplete to work together", () => {
322
+ render (
323
+ <Dropdown
324
+ autocomplete
325
+ data={{ testid: testId }}
326
+ multiSelect
327
+ options={options}
328
+ />
329
+ )
330
+
331
+ const kit = screen.getByTestId(testId)
332
+ const input = kit.querySelector('.dropdown_input')
333
+ expect(input).toBeInTheDocument()
334
+ const option = kit.querySelector('.pb_dropdown_option_list')
335
+ fireEvent.click(option)
336
+ const formPill = kit.querySelector(".pb_form_pill_kit_primary")
337
+ expect(formPill).toBeInTheDocument()
338
+ })
339
+
340
+ test("renders form pills with size and color", () => {
341
+ render(
342
+ <Dropdown
343
+ data={{ testid: testId }}
344
+ formPillProps={{ size: "small", color: "neutral" }}
345
+ multiSelect
346
+ options={options}
347
+ />
348
+ );
349
+
350
+ const kit = screen.getByTestId(testId)
351
+ const option = kit.querySelector('.pb_dropdown_option_list')
352
+ fireEvent.click(option)
353
+ const formPill = kit.querySelector(".pb_form_pill_kit_neutral")
354
+ expect(formPill).toBeInTheDocument()
355
+ expect(formPill).toHaveClass("small")
356
+ })
357
+
358
+ test("defaultValue works with multiSelect", () => {
359
+ render(
360
+ <Dropdown
361
+ data={{ testid: testId }}
362
+ defaultValue={[options[0], options[2]]}
363
+ multiSelect
364
+ options={options}
365
+ />
366
+ )
367
+ const kit = screen.getByTestId(testId)
368
+ expect(kit.querySelectorAll(".pb_form_pill_kit_primary")).toHaveLength(2)
369
+ const option2 = Array.from(kit.querySelectorAll(".pb_dropdown_option_list"));
370
+ const firstOpt = options[0].label
371
+ expect(option2[0]).not.toHaveTextContent(firstOpt)
372
+ })
@@ -33,6 +33,7 @@ type PhoneNumberInputProps = {
33
33
  onChange?: (e: React.FormEvent<HTMLInputElement>) => void,
34
34
  onValidate?: Callback<boolean, void>,
35
35
  onlyCountries: string[],
36
+ excludeCountries: string[],
36
37
  preferredCountries?: string[],
37
38
  required?: boolean,
38
39
  value?: string,
@@ -88,6 +89,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.MutableRefOb
88
89
  },
89
90
  onValidate = () => null,
90
91
  onlyCountries = [],
92
+ excludeCountries = [],
91
93
  required = false,
92
94
  preferredCountries = [],
93
95
  value = "",
@@ -234,6 +236,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.MutableRefOb
234
236
  const fallbackCountry =
235
237
  preferredCountries.length > 0 ? preferredCountries[0] :
236
238
  onlyCountries.length > 0 ? onlyCountries.sort()[0] :
239
+ excludeCountries.length > 0 ? excludeCountries.sort()[0] :
237
240
  "af";
238
241
 
239
242
  useEffect(() => {
@@ -244,6 +247,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.MutableRefOb
244
247
  autoInsertDialCode: false,
245
248
  initialCountry: initialCountry || fallbackCountry,
246
249
  onlyCountries,
250
+ excludeCountries,
247
251
  countrySearch: countrySearch,
248
252
  fixDropdownWidth: false,
249
253
  formatAsYouType: formatAsYouType,
@@ -0,0 +1,4 @@
1
+ <%= pb_rails("phone_number_input", props: {
2
+ initial_country: 'gb',
3
+ exclude_countries: ['us', 'br']
4
+ }) %>
@@ -0,0 +1,15 @@
1
+ import React from 'react'
2
+ import PhoneNumberInput from '../../pb_phone_number_input/_phone_number_input'
3
+
4
+ const PhoneNumberInputExcludeCountries = (props) => (
5
+ <>
6
+ <PhoneNumberInput
7
+ excludeCountries={['us', 'br']}
8
+ id='exclude'
9
+ initialCountry='gb'
10
+ {...props}
11
+ />
12
+ </>
13
+ )
14
+
15
+ export default PhoneNumberInputExcludeCountries
@@ -0,0 +1 @@
1
+ Excluding countries removes the selected countries from the dropdown.
@@ -6,7 +6,7 @@ const PhoneNumberInputOnlyCountries = (props) => (
6
6
  <PhoneNumberInput
7
7
  id='only'
8
8
  onlyCountries={['us', 'br']}
9
- {...props}
9
+ {...props}
10
10
  />
11
11
  </>
12
12
  )
@@ -4,7 +4,8 @@ examples:
4
4
  - phone_number_input_default: Default
5
5
  - phone_number_input_preferred_countries: Preferred Countries
6
6
  - phone_number_input_initial_country: Initial Country
7
- - phone_number_input_only_countries: Limited Countries
7
+ - phone_number_input_only_countries: Only Countries
8
+ - phone_number_input_exclude_countries: Exclude Countries
8
9
  - phone_number_input_validation: Form Validation
9
10
  - phone_number_input_clear_field: Clearing the Input Field
10
11
  - phone_number_input_access_input_element: Accessing the Input Element
@@ -15,9 +16,9 @@ examples:
15
16
  - phone_number_input_default: Default
16
17
  - phone_number_input_preferred_countries: Preferred Countries
17
18
  - phone_number_input_initial_country: Initial Country
18
- - phone_number_input_only_countries: Limited Countries
19
+ - phone_number_input_only_countries: Only Countries
20
+ - phone_number_input_exclude_countries: Exclude Countries
19
21
  - phone_number_input_validation: Form Validation
20
22
  - phone_number_input_format: Format as You Type
21
23
  - phone_number_input_hidden_inputs: Hidden Inputs
22
24
  - phone_number_input_country_search: Country Search
23
-
@@ -2,6 +2,7 @@ export { default as PhoneNumberInputDefault } from './_phone_number_input_defaul
2
2
  export { default as PhoneNumberInputPreferredCountries } from './_phone_number_input_preferred_countries'
3
3
  export { default as PhoneNumberInputInitialCountry } from './_phone_number_input_initial_country'
4
4
  export { default as PhoneNumberInputOnlyCountries } from './_phone_number_input_only_countries'
5
+ export { default as PhoneNumberInputExcludeCountries } from './_phone_number_input_exclude_countries'
5
6
  export { default as PhoneNumberInputValidation } from './_phone_number_input_validation'
6
7
  export { default as PhoneNumberInputClearField } from './_phone_number_input_clear_field'
7
8
  export { default as PhoneNumberInputAccessInputElement } from './_phone_number_input_access_input_element'
@@ -15,6 +15,8 @@ module Playbook
15
15
  default: ""
16
16
  prop :only_countries, type: Playbook::Props::Array,
17
17
  default: []
18
+ prop :exclude_countries, type: Playbook::Props::Array,
19
+ default: []
18
20
  prop :preferred_countries, type: Playbook::Props::Array,
19
21
  default: []
20
22
  prop :error, type: Playbook::Props::String,
@@ -44,6 +46,7 @@ module Playbook
44
46
  label: label,
45
47
  name: name,
46
48
  onlyCountries: only_countries,
49
+ excludeCountries: exclude_countries,
47
50
  preferredCountries: preferred_countries,
48
51
  required: required,
49
52
  value: value,
@@ -13,19 +13,24 @@ export default class PbPopover extends PbEnhancedElement {
13
13
  }
14
14
 
15
15
  moveTooltip() {
16
- let container: HTMLElement | null;
16
+ let container: HTMLElement | null = document.querySelector('body');
17
17
 
18
18
  if (this.appendTo === "parent") {
19
- container = this.element.parentElement;
19
+ container = this.element.parentElement && this.element.parentElement
20
20
  } else if (this.appendTo) {
21
- container = document.querySelector(this.appendTo);
21
+ container = document.querySelector(this.appendTo)
22
22
  }
23
23
 
24
- (container || document.body).appendChild(this.tooltip);
24
+ container.appendChild(this.tooltip);
25
25
  }
26
26
 
27
27
  connect() {
28
+ if (!this.triggerElement || !this.tooltip) {
29
+ console.log('Popover requires both trigger and tooltip elements to be defined.')
30
+ return
31
+ }
28
32
  this.moveTooltip()
33
+
29
34
  this.popper = createPopper (this.triggerElement, this.tooltip, {
30
35
  placement: this.position as Placement,
31
36
  strategy: 'fixed',
@@ -0,0 +1,12 @@
1
+ <%= pb_rails("select", props: { label: "Favorite Animal" }) do %>
2
+ <select name="animal" id="animal">
3
+ <optgroup label="Mammal">
4
+ <option value="1">Cat</option>
5
+ <option value="2">Dog</option>
6
+ </optgroup>
7
+ <optgroup label="Amphibian">
8
+ <option value="3">Frog</option>
9
+ <option value="4">Salamander</option>
10
+ </optgroup>
11
+ </select>
12
+ <% end %>
@@ -0,0 +1,31 @@
1
+ import React from 'react'
2
+
3
+ import Select from '../_select'
4
+
5
+ const SelectCustomSelectSubheaders = (props) => {
6
+ return (
7
+ <div>
8
+ <Select
9
+ label="Favorite Animal"
10
+ {...props}
11
+ >
12
+ <select
13
+ id="animal"
14
+ name="animal"
15
+ {...props}
16
+ >
17
+ <optgroup label="Mammal">
18
+ <option value="1">{'Cat'}</option>
19
+ <option value="2">{'Dog'}</option>
20
+ </optgroup>
21
+ <optgroup label="Amphibian">
22
+ <option value="3">{'Frog'}</option>
23
+ <option value="4">{'Salamander'}</option>
24
+ </optgroup>
25
+ </select>
26
+ </Select>
27
+ </div>
28
+ )
29
+ }
30
+
31
+ export default SelectCustomSelectSubheaders
@@ -0,0 +1 @@
1
+ To create a select with non-selectable subheaders, use a Custom Select component to render a native `<select>` containing `<optgroup>` elements. The [optgroup HTML element](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/optgroup) groups related options under a non-selectable label in the dropdown.
@@ -8,6 +8,7 @@ examples:
8
8
  - select_required: Required Select Field
9
9
  - select_value_text_same: Equal option value and value text
10
10
  - select_custom_select: Custom Select
11
+ - select_custom_select_subheaders: Custom Select Subheaders
11
12
  - select_error: Select w/ Error
12
13
  - select_inline: Select Inline
13
14
  - select_inline_show_arrow: Select Inline (Always Show Arrow)
@@ -25,6 +26,7 @@ examples:
25
26
  - select_required: Required Select Field
26
27
  - select_value_text_same: Equal option value and value text
27
28
  - select_custom_select: Custom Select
29
+ - select_custom_select_subheaders: Custom Select Subheaders
28
30
  - select_error: Select w/ Error
29
31
  - select_inline: Select Inline
30
32
  - select_inline_show_arrow: Select Inline (Always Show Arrow)
@@ -11,3 +11,4 @@ export { default as SelectInlineShowArrow } from './_select_inline_show_arrow.js
11
11
  export { default as SelectInlineCompact } from './_select_inline_compact.jsx'
12
12
  export { default as SelectMultiple } from './_select_multiple.jsx'
13
13
  export { default as SelectReactHook } from './_select_react_hook.jsx'
14
+ export { default as SelectCustomSelectSubheaders } from './_select_custom_select_subheaders.jsx'