playbook_ui 13.25.0 → 13.26.0.pre.alpha.PBNTR291Dropdownrailsv22840

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/index.js +1 -0
  3. data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.scss +14 -0
  4. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_beta.html.erb +33 -0
  5. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_beta.md +24 -0
  6. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_default.md +5 -0
  7. data/app/pb_kits/playbook/pb_advanced_table/docs/example.yml +2 -2
  8. data/app/pb_kits/playbook/pb_advanced_table/index.js +78 -0
  9. data/app/pb_kits/playbook/pb_advanced_table/table_body.rb +4 -2
  10. data/app/pb_kits/playbook/pb_advanced_table/table_row.html.erb +3 -2
  11. data/app/pb_kits/playbook/pb_avatar/Utilities/GetPlacementPropsHelper.tsx +44 -0
  12. data/app/pb_kits/playbook/pb_avatar/_avatar.tsx +86 -21
  13. data/app/pb_kits/playbook/pb_avatar/avatar.html.erb +26 -3
  14. data/app/pb_kits/playbook/pb_avatar/avatar.rb +41 -0
  15. data/app/pb_kits/playbook/pb_avatar/docs/_avatar_badge_component_overlay.html.erb +71 -0
  16. data/app/pb_kits/playbook/pb_avatar/docs/_avatar_badge_component_overlay.jsx +77 -0
  17. data/app/pb_kits/playbook/pb_avatar/docs/_avatar_circle_icon_component_overlay.html.erb +71 -0
  18. data/app/pb_kits/playbook/pb_avatar/docs/_avatar_circle_icon_component_overlay.jsx +77 -0
  19. data/app/pb_kits/playbook/pb_avatar/docs/_avatar_default.jsx +20 -0
  20. data/app/pb_kits/playbook/pb_avatar/docs/example.yml +4 -0
  21. data/app/pb_kits/playbook/pb_avatar/docs/index.js +2 -0
  22. data/app/pb_kits/playbook/pb_bar_graph/_bar_graph.tsx +1 -1
  23. data/app/pb_kits/playbook/pb_body/_body.tsx +1 -1
  24. data/app/pb_kits/playbook/pb_button/_button.scss +1 -1
  25. data/app/pb_kits/playbook/pb_checkbox/_checkbox.scss +49 -0
  26. data/app/pb_kits/playbook/pb_checkbox/_checkbox.tsx +3 -0
  27. data/app/pb_kits/playbook/pb_checkbox/checkbox.rb +2 -1
  28. data/app/pb_kits/playbook/pb_checkbox/checkbox.test.js +14 -0
  29. data/app/pb_kits/playbook/pb_checkbox/docs/_checkbox_disabled.html.erb +23 -0
  30. data/app/pb_kits/playbook/pb_checkbox/docs/_checkbox_disabled.jsx +29 -0
  31. data/app/pb_kits/playbook/pb_checkbox/docs/example.yml +2 -0
  32. data/app/pb_kits/playbook/pb_checkbox/docs/index.js +1 -0
  33. data/app/pb_kits/playbook/pb_currency/docs/_currency_alignment_swift.md +43 -0
  34. data/app/pb_kits/playbook/pb_currency/docs/_currency_props_swift.md +12 -0
  35. data/app/pb_kits/playbook/pb_currency/docs/_currency_size_swift.md +31 -0
  36. data/app/pb_kits/playbook/pb_currency/docs/example.yml +5 -0
  37. data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_on_change.md +3 -1
  38. data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_on_close.md +3 -1
  39. data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_quick_pick_range_limit.md +1 -1
  40. data/app/pb_kits/playbook/pb_date_range_stacked/docs/_date_range_stacked_default_swift.md +14 -0
  41. data/app/pb_kits/playbook/pb_date_range_stacked/docs/_date_range_stacked_props_swift.md +9 -0
  42. data/app/pb_kits/playbook/pb_date_range_stacked/docs/example.yml +4 -0
  43. data/app/pb_kits/playbook/pb_dialog/_dialog.scss +4 -2
  44. data/app/pb_kits/playbook/pb_dropdown/_dropdown.scss +102 -35
  45. data/app/pb_kits/playbook/pb_dropdown/_dropdown.tsx +95 -26
  46. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_default.html.erb +10 -0
  47. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_default.jsx +4 -22
  48. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_default.md +1 -0
  49. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_subcomponent_structure.html.erb +17 -0
  50. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_subcomponent_structure.jsx +42 -0
  51. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_subcomponent_structure.md +7 -0
  52. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_autocomplete.jsx +84 -0
  53. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_autocomplete.md +1 -0
  54. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_autocomplete_and_custom_display.jsx +101 -0
  55. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_autocomplete_and_custom_display.md +1 -0
  56. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_display.html.erb +60 -0
  57. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_display.jsx +6 -4
  58. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_display.md +5 -0
  59. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_options.html.erb +45 -0
  60. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_options.jsx +6 -9
  61. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_options.md +1 -0
  62. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_padding.html.erb +17 -0
  63. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_padding.jsx +48 -0
  64. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_padding.md +1 -0
  65. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_trigger.html.erb +47 -0
  66. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_trigger.jsx +5 -5
  67. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_trigger.md +1 -0
  68. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_external_control.jsx +59 -0
  69. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_hook.jsx +72 -0
  70. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_label.html.erb +10 -0
  71. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_label.jsx +39 -0
  72. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_label.md +1 -0
  73. data/app/pb_kits/playbook/pb_dropdown/docs/example.yml +16 -2
  74. data/app/pb_kits/playbook/pb_dropdown/docs/index.js +7 -0
  75. data/app/pb_kits/playbook/pb_dropdown/dropdown.html.erb +26 -0
  76. data/app/pb_kits/playbook/pb_dropdown/dropdown.rb +20 -0
  77. data/app/pb_kits/playbook/pb_dropdown/dropdown.test.jsx +200 -10
  78. data/app/pb_kits/playbook/pb_dropdown/dropdown_container.html.erb +21 -0
  79. data/app/pb_kits/playbook/pb_dropdown/dropdown_container.rb +19 -0
  80. data/app/pb_kits/playbook/pb_dropdown/dropdown_option.html.erb +27 -0
  81. data/app/pb_kits/playbook/pb_dropdown/dropdown_option.rb +22 -0
  82. data/app/pb_kits/playbook/pb_dropdown/dropdown_trigger.html.erb +43 -0
  83. data/app/pb_kits/playbook/pb_dropdown/dropdown_trigger.rb +30 -0
  84. data/app/pb_kits/playbook/pb_dropdown/hooks/useDropdown.tsx +2 -2
  85. data/app/pb_kits/playbook/pb_dropdown/hooks/useHandleOnKeydown.tsx +14 -9
  86. data/app/pb_kits/playbook/pb_dropdown/index.js +153 -0
  87. data/app/pb_kits/playbook/pb_dropdown/keyboard_accessibility.js +77 -0
  88. data/app/pb_kits/playbook/pb_dropdown/scss_partials/_dropdown_animation.scss +18 -0
  89. data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownContainer.tsx +22 -8
  90. data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownOption.tsx +60 -31
  91. data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownTrigger.tsx +130 -68
  92. data/app/pb_kits/playbook/pb_dropdown/utilities/clickOutsideHelper.tsx +41 -0
  93. data/app/pb_kits/playbook/pb_dropdown/utilities/index.ts +2 -0
  94. data/app/pb_kits/playbook/pb_dropdown/utilities/subComponentHelper.tsx +9 -7
  95. data/app/pb_kits/playbook/pb_loading_inline/_loading_inline.tsx +3 -1
  96. data/app/pb_kits/playbook/pb_loading_inline/docs/_loading_inline_custom.html.erb +13 -0
  97. data/app/pb_kits/playbook/pb_loading_inline/docs/_loading_inline_custom.jsx +26 -0
  98. data/app/pb_kits/playbook/pb_loading_inline/docs/{_loading_inline_light.html.erb → _loading_inline_default.html.erb} +2 -2
  99. data/app/pb_kits/playbook/pb_loading_inline/docs/{_loading_inline_light.jsx → _loading_inline_default.jsx} +2 -2
  100. data/app/pb_kits/playbook/pb_loading_inline/docs/example.yml +4 -2
  101. data/app/pb_kits/playbook/pb_loading_inline/docs/index.js +2 -1
  102. data/app/pb_kits/playbook/pb_loading_inline/loading_inline.html.erb +1 -1
  103. data/app/pb_kits/playbook/pb_loading_inline/loading_inline.rb +1 -0
  104. data/app/pb_kits/playbook/pb_loading_inline/loading_inline.test.js +14 -0
  105. data/app/pb_kits/playbook/pb_progress_simple/docs/_progress_simple_flex.html.erb +3 -0
  106. data/app/pb_kits/playbook/pb_progress_simple/docs/_progress_simple_flex.jsx +16 -0
  107. data/app/pb_kits/playbook/pb_progress_simple/docs/_progress_simple_flex.md +1 -0
  108. data/app/pb_kits/playbook/pb_progress_simple/docs/example.yml +2 -0
  109. data/app/pb_kits/playbook/pb_progress_simple/docs/index.js +1 -0
  110. data/app/pb_kits/playbook/pb_progress_simple/progress_simple.rb +1 -1
  111. data/app/pb_kits/playbook/pb_radio/_radio.scss +35 -0
  112. data/app/pb_kits/playbook/pb_radio/_radio.tsx +3 -0
  113. data/app/pb_kits/playbook/pb_radio/docs/_radio_alignment.jsx +4 -1
  114. data/app/pb_kits/playbook/pb_radio/docs/_radio_default.jsx +4 -1
  115. data/app/pb_kits/playbook/pb_radio/docs/_radio_disabled.html.erb +26 -0
  116. data/app/pb_kits/playbook/pb_radio/docs/_radio_disabled.jsx +31 -0
  117. data/app/pb_kits/playbook/pb_radio/docs/_radio_error.jsx +2 -1
  118. data/app/pb_kits/playbook/pb_radio/docs/example.yml +2 -0
  119. data/app/pb_kits/playbook/pb_radio/docs/index.js +1 -0
  120. data/app/pb_kits/playbook/pb_radio/radio.rb +5 -0
  121. data/app/pb_kits/playbook/pb_radio/radio.test.js +17 -0
  122. data/app/pb_kits/playbook/pb_section_separator/_section_separator.scss +6 -2
  123. data/app/pb_kits/playbook/pb_section_separator/_section_separator_mixin.scss +11 -1
  124. data/app/pb_kits/playbook/pb_tooltip/_tooltip.tsx +1 -1
  125. data/app/pb_kits/playbook/playbook-rails.js +6 -0
  126. data/dist/menu.yml +1 -1
  127. data/dist/playbook-rails.js +6 -6
  128. data/lib/playbook/version.rb +2 -2
  129. metadata +65 -8
  130. data/app/pb_kits/playbook/pb_advanced_table/docs/_description.md +0 -1
@@ -0,0 +1,77 @@
1
+ const OPTION_SELECTOR = "[data-dropdown-option-label]";
2
+ export class PbDropdownKeyboard {
3
+ constructor(dropdown) {
4
+ this.dropdown = dropdown;
5
+ this.dropdownElement = dropdown.element;
6
+ this.options = Array.from(
7
+ this.dropdownElement.querySelectorAll(OPTION_SELECTOR)
8
+ );
9
+ this.focusedOptionIndex = -1;
10
+ this.init();
11
+ }
12
+
13
+ init() {
14
+ this.dropdownElement.addEventListener(
15
+ "keydown",
16
+ this.handleKeyDown.bind(this)
17
+ );
18
+ }
19
+
20
+ handleKeyDown(event) {
21
+ switch (event.key) {
22
+ case "ArrowDown":
23
+ event.preventDefault();
24
+ if (!this.dropdown.target.classList.contains("open")) {
25
+ this.dropdown.showElement(this.dropdown.target);
26
+ this.dropdown.updateArrowDisplay(true);
27
+ }
28
+ this.moveFocus(1);
29
+ break;
30
+ case "ArrowUp":
31
+ event.preventDefault();
32
+ this.moveFocus(-1);
33
+ break;
34
+ case "Enter":
35
+ event.preventDefault();
36
+ if (this.focusedOptionIndex !== -1) {
37
+ this.selectOption();
38
+ } else {
39
+ if (!this.dropdown.target.classList.contains("open")) {
40
+ this.dropdown.showElement(this.dropdown.target);
41
+ this.dropdown.updateArrowDisplay(true);
42
+ }
43
+ }
44
+ break;
45
+ case "Escape":
46
+ this.dropdown.hideElement(this.dropdown.target);
47
+ break;
48
+ case "Tab":
49
+ this.dropdown.hideElement(this.dropdown.target);
50
+ this.dropdown.updateArrowDisplay(false);
51
+ this.resetFocus();
52
+ break;
53
+ default:
54
+ break;
55
+ }
56
+ }
57
+
58
+ moveFocus(direction) {
59
+ if (this.focusedOptionIndex !== -1) {
60
+ this.options[this.focusedOptionIndex].classList.remove(
61
+ "pb_dropdown_option_focused"
62
+ );
63
+ }
64
+ this.focusedOptionIndex =
65
+ (this.focusedOptionIndex + direction + this.options.length) %
66
+ this.options.length;
67
+ this.options[this.focusedOptionIndex].classList.add(
68
+ "pb_dropdown_option_focused"
69
+ );
70
+ }
71
+
72
+ selectOption() {
73
+ const option = this.options[this.focusedOptionIndex];
74
+ this.dropdown.onOptionSelected(option.dataset.dropdownOptionLabel, option);
75
+ this.dropdown.hideElement(this.dropdown.target);
76
+ }
77
+ }
@@ -0,0 +1,18 @@
1
+ @keyframes fadeIn {
2
+ from {
3
+ opacity: 0;
4
+ }
5
+
6
+ to {
7
+ opacity: 1;
8
+ }
9
+ }
10
+ @keyframes fadeOut {
11
+ from {
12
+ opacity: 1;
13
+ }
14
+
15
+ to {
16
+ opacity: 0;
17
+ }
18
+ }
@@ -4,6 +4,7 @@ import {
4
4
  buildAriaProps,
5
5
  buildCss,
6
6
  buildDataProps,
7
+ buildHtmlProps
7
8
  } from "../../utilities/props";
8
9
  import { globalProps } from "../../utilities/globalProps";
9
10
 
@@ -16,9 +17,11 @@ import Body from "../../pb_body/_body";
16
17
 
17
18
  type DropdownContainerProps = {
18
19
  aria?: { [key: string]: string };
19
- className?: string;
20
20
  children?: React.ReactChild[] | React.ReactChild;
21
+ className?: string;
22
+ dark?: boolean;
21
23
  data?: { [key: string]: string };
24
+ htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
22
25
  id?: string;
23
26
  searchbar?: boolean;
24
27
  };
@@ -26,24 +29,29 @@ type DropdownContainerProps = {
26
29
  const DropdownContainer = (props: DropdownContainerProps) => {
27
30
  const {
28
31
  aria = {},
29
- className,
30
32
  children,
33
+ className,
34
+ dark = false,
31
35
  data = {},
36
+ htmlOptions = {},
32
37
  id,
33
38
  searchbar = false,
34
39
  } = props;
35
40
 
36
41
  const {
37
- isDropDownClosed,
38
- handleChange,
39
- filterItem,
42
+ dropdownContainerRef,
40
43
  filteredOptions,
44
+ filterItem,
45
+ handleChange,
41
46
  inputRef,
47
+ isDropDownClosed,
42
48
  setFocusedOptionIndex,
49
+ triggerRef
43
50
  } = useContext(DropdownContext);
44
51
 
45
52
  const ariaProps = buildAriaProps(aria);
46
53
  const dataProps = buildDataProps(data);
54
+ const htmlProps = buildHtmlProps(htmlOptions);
47
55
  const classes = classnames(
48
56
  buildCss("pb_dropdown_container"),
49
57
  `${isDropDownClosed ? "close" : "open"}`,
@@ -54,12 +62,16 @@ const DropdownContainer = (props: DropdownContainerProps) => {
54
62
  return (
55
63
  <div {...ariaProps}
56
64
  {...dataProps}
65
+ {...htmlProps}
57
66
  className={classes}
58
67
  id={id}
59
68
  onMouseEnter={() => setFocusedOptionIndex(-1)}
69
+ ref={dropdownContainerRef}
70
+ style={triggerRef ? {} : { position: "absolute"}}
60
71
  >
61
72
  {searchbar && (
62
- <TextInput paddingTop="xs"
73
+ <TextInput dark={dark}
74
+ paddingTop="xs"
63
75
  paddingX="xs"
64
76
  >
65
77
  <input
@@ -70,9 +82,10 @@ const DropdownContainer = (props: DropdownContainerProps) => {
70
82
  />
71
83
  </TextInput>
72
84
  )}
73
- <List>{
85
+ <List dark={dark}>
86
+ {
74
87
  filteredOptions?.length === 0 ? (
75
- <ListItem
88
+ <ListItem dark={dark}
76
89
  display="flex"
77
90
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
78
91
  // @ts-ignore
@@ -80,6 +93,7 @@ const DropdownContainer = (props: DropdownContainerProps) => {
80
93
  padding="xs"
81
94
  >
82
95
  <Body color="light"
96
+ dark={dark}
83
97
  text="no option"
84
98
  />
85
99
  </ListItem>
@@ -4,8 +4,9 @@ import {
4
4
  buildAriaProps,
5
5
  buildCss,
6
6
  buildDataProps,
7
+ buildHtmlProps,
7
8
  } from "../../utilities/props";
8
- import { globalProps } from "../../utilities/globalProps";
9
+ import { globalProps, GlobalProps } from "../../utilities/globalProps";
9
10
 
10
11
  import DropdownContext from "../context";
11
12
 
@@ -16,71 +17,99 @@ import { GenericObject } from "../../types";
16
17
 
17
18
  type DropdownOptionProps = {
18
19
  aria?: { [key: string]: string };
19
- className?: string;
20
20
  children?: React.ReactChild[] | React.ReactChild;
21
+ className?: string;
22
+ dark?: boolean;
21
23
  data?: { [key: string]: string };
24
+ htmlOptions?: { [key: string]: string | number | boolean | (() => void) };
22
25
  id?: string;
23
- option?: GenericObject;
24
26
  key?: string;
25
- };
27
+ option?: GenericObject;
28
+ padding?: string;
29
+ } & GlobalProps;
26
30
 
27
31
  const DropdownOption = (props: DropdownOptionProps) => {
28
- const { aria = {}, className, children, data = {}, id, option, key } = props;
32
+ const {
33
+ aria = {},
34
+ children,
35
+ className,
36
+ dark = false,
37
+ data = {},
38
+ htmlOptions = {},
39
+ id,
40
+ key,
41
+ option,
42
+ padding = "xs",
43
+ } = props;
29
44
 
30
- const { handleOptionClick, selected, filterItem, filteredOptions, focusedOptionIndex } =
31
- useContext(DropdownContext);
45
+ const {
46
+ filteredOptions,
47
+ filterItem,
48
+ focusedOptionIndex,
49
+ handleOptionClick,
50
+ selected,
51
+ } = useContext(DropdownContext);
32
52
 
33
- const isItemMatchingFilter = (option: GenericObject) =>
34
- option?.label.toLowerCase().includes(filterItem.toLowerCase());
53
+ const isItemMatchingFilter = (option: GenericObject) => {
54
+ const label = typeof option.label === 'string' ? option.label.toLowerCase() : option.label;
55
+ return String(label).toLowerCase().includes(filterItem.toLowerCase());
56
+ }
35
57
 
36
58
  if (!isItemMatchingFilter(option)) {
37
59
  return null;
38
60
  }
39
- const isFocused = focusedOptionIndex >= 0 && filteredOptions[focusedOptionIndex].label === option.label
40
- const focusedClass = isFocused && "dropdown_option_focused"
61
+ const isFocused =
62
+ focusedOptionIndex >= 0 &&
63
+ filteredOptions[focusedOptionIndex].label === option.label;
64
+ const focusedClass = isFocused && "focused";
41
65
 
42
66
  const selectedClass = `${
43
67
  selected.label === option.label
44
- ? "dropdown_option_selected"
45
- : "dropdown_option_list"
46
- }`
68
+ ? "selected"
69
+ : "list"
70
+ }`;
47
71
  const ariaProps = buildAriaProps(aria);
48
72
  const dataProps = buildDataProps(data);
73
+ const htmlProps = buildHtmlProps(htmlOptions);
49
74
  const classes = classnames(
50
- buildCss("pb_dropdown_option"),
51
- selectedClass,
52
- focusedClass,
53
- globalProps(props),
75
+ buildCss(
76
+ "pb_dropdown_option",
77
+ selectedClass,
78
+ focusedClass,
79
+ ),
80
+ globalProps(props, {padding}),
54
81
  className
55
82
  );
56
83
 
57
84
  return (
58
- <div {...ariaProps}
59
- {...dataProps}
60
- className={classes}
61
- id={id}
85
+ <div
86
+ {...ariaProps}
87
+ {...dataProps}
88
+ {...htmlProps}
89
+ className={classes}
90
+ id={id}
62
91
  key={key}
92
+ onClick= {() => handleOptionClick(option)}
63
93
  >
64
94
  <ListItem
65
95
  cursor="pointer"
96
+ dark={dark}
66
97
  data-name={option.value}
67
- htmlOptions={{ onClick: () => handleOptionClick(option) }}
68
98
  key={option.label}
69
- padding="xs"
99
+ padding="none"
70
100
  >
71
101
  <Flex
72
102
  align="center"
73
- className="dropdown_option"
103
+ className="dropdown_option_wrapper"
74
104
  justify="between"
75
105
  paddingX="sm"
76
106
  paddingY="xxs"
77
107
  >
78
- {
79
- children ? (
80
- children
81
- ) : (
82
- <Body text={option.label}/>
83
- )
108
+ {children ?
109
+ children :
110
+ <Body dark={dark}
111
+ text={option.label}
112
+ />
84
113
  }
85
114
  </Flex>
86
115
  </ListItem>
@@ -4,6 +4,7 @@ import {
4
4
  buildAriaProps,
5
5
  buildCss,
6
6
  buildDataProps,
7
+ buildHtmlProps
7
8
  } from "../../utilities/props";
8
9
  import { globalProps } from "../../utilities/globalProps";
9
10
  import { useHandleOnKeyDown } from "../hooks/useHandleOnKeydown";
@@ -20,107 +21,168 @@ type DropdownTriggerProps = {
20
21
  children?: React.ReactChild[] | React.ReactChild;
21
22
  className?: string;
22
23
  customDisplay?: React.ReactChild[] | React.ReactChild;
24
+ dark?: boolean;
23
25
  data?: { [key: string]: string };
26
+ htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
24
27
  id?: string;
28
+ placeholder?: string;
25
29
  };
26
30
 
27
31
  const DropdownTrigger = (props: DropdownTriggerProps) => {
28
- const { aria = {}, className, children, customDisplay, data = {}, id } = props;
32
+ const {
33
+ aria = {},
34
+ children,
35
+ className,
36
+ customDisplay,
37
+ dark = false,
38
+ data = {},
39
+ htmlOptions = {},
40
+ id,
41
+ placeholder,
42
+ } = props;
29
43
 
30
44
  const {
31
45
  autocomplete,
32
- handleWrapperClick,
33
- selected,
34
46
  filterItem,
35
47
  handleChange,
36
- toggleDropdown,
37
- isDropDownClosed,
48
+ handleWrapperClick,
38
49
  inputRef,
50
+ inputWrapperRef,
51
+ isDropDownClosed,
39
52
  isInputFocused,
40
- setIsInputFocused
53
+ selected,
54
+ setIsInputFocused,
55
+ toggleDropdown,
56
+ triggerRef,
41
57
  } = useContext(DropdownContext);
42
-
58
+
43
59
  const handleKeyDown = useHandleOnKeyDown();
44
60
 
45
61
  const ariaProps = buildAriaProps(aria);
46
62
  const dataProps = buildDataProps(data);
63
+ const htmlProps = buildHtmlProps(htmlOptions);
47
64
  const classes = classnames(
48
65
  buildCss("pb_dropdown_trigger"),
49
66
  globalProps(props),
50
67
  className
51
68
  );
52
69
 
70
+ const triggerWrapperClasses = buildCss(
71
+ "dropdown_trigger_wrapper",
72
+ isInputFocused && "focus",
73
+ !autocomplete && "select_only"
74
+ );
75
+
76
+ const customDisplayPlaceholder = selected.label ? (
77
+ <b>{selected.label}</b>
78
+ ) : autocomplete ? (
79
+ ""
80
+ ) : placeholder ? (
81
+ placeholder
82
+ ) : (
83
+ "Select..."
84
+ );
85
+
86
+ const defaultDisplayPlaceholder = selected.label
87
+ ? selected.label
88
+ : autocomplete
89
+ ? ""
90
+ : placeholder
91
+ ? placeholder
92
+ : "Select...";
93
+
53
94
  return (
54
95
  <div {...ariaProps}
55
96
  {...dataProps}
97
+ {...htmlProps}
56
98
  className={classes}
57
99
  id={id}
58
100
  >
59
- {children ? (
60
- <div
61
- onClick={() => toggleDropdown()}
62
- style={{ display: "inline-block" }}
63
- >
64
- {children}
65
- </div>
66
- ) : (
67
- <>
68
- <Flex align="center"
69
- borderRadius="lg"
70
- className={`dropdown_trigger_wrapper ${isInputFocused && 'dropdown_trigger_wrapper_focus'}`}
71
- cursor="pointer"
72
- htmlOptions={{
73
- onClick: () => handleWrapperClick(),
74
- onKeyDown: handleKeyDown,
75
- tabIndex:"0",
76
- }}
77
- justify="between"
78
- paddingX="sm"
79
- paddingY="xs"
80
- >
81
- <FlexItem>
82
- <Flex align="center">
101
+ {
102
+ !triggerRef && (
103
+ children ? (
104
+ <div
105
+ onClick={() => toggleDropdown()}
106
+ onKeyDown= {handleKeyDown}
107
+ ref={inputWrapperRef}
108
+ style={{ display: "inline-block" }}
109
+ tabIndex= {0}
110
+ >
111
+ {children}
112
+ </div>
113
+ ) : (
114
+ <>
115
+ <Flex
116
+ align="center"
117
+ borderRadius="lg"
118
+ className={triggerWrapperClasses}
119
+ cursor={`${autocomplete ? "text" : "pointer"}`}
120
+ htmlOptions={{
121
+ onClick: () => handleWrapperClick(),
122
+ onKeyDown: handleKeyDown,
123
+ tabIndex: "0",
124
+ ref:inputWrapperRef
125
+ }}
126
+ justify="between"
127
+ paddingX="sm"
128
+ paddingY="xs"
129
+ >
130
+ <FlexItem>
131
+ <Flex align="center">
83
132
  {customDisplay ? (
84
133
  <Flex align="center">
85
- {customDisplay}
86
- <Body paddingLeft={`${selected.label ? "xs" : "none"}`}>
87
- {selected.label ? <b>{selected.label}</b> : autocomplete ? "" : "Select..." }
88
- </Body>
134
+ {customDisplay}
135
+ <Body dark={dark}
136
+ paddingLeft={`${selected.label ? "xs" : "none"}`}
137
+ >
138
+ {customDisplayPlaceholder}
139
+ </Body>
89
140
  </Flex>
90
- ) : (
91
- <Body text={selected.label ? selected.label : autocomplete ? "" : "Select..."} />
92
- )
93
- }
94
- {
95
- autocomplete && (
96
- <input
97
- className="dropdown_input"
98
- onChange={handleChange}
99
- onClick={() => toggleDropdown()}
100
- onFocus={() => setIsInputFocused(true)}
101
- onKeyDown={handleKeyDown}
102
- placeholder={selected.label ? "" : "Select..."}
103
- ref={inputRef}
104
- value={filterItem}
105
- />
106
- )
107
- }
108
-
109
- </Flex>
110
- </FlexItem>
111
- <FlexItem>
112
- <Body display="flex"
113
- key={`${isDropDownClosed ? "chevron-down" : 'chevron-up'}`}
114
- >
115
- <Icon cursor="pointer"
116
- icon={`${isDropDownClosed ? "chevron-down" : 'chevron-up'}`}
117
- size="sm"
141
+ ) : (
142
+ <Body dark={dark}
143
+ text={defaultDisplayPlaceholder}
144
+ />
145
+ )}
146
+ {autocomplete && (
147
+ <input
148
+ className="dropdown_input"
149
+ onChange={handleChange}
150
+ onClick={() => toggleDropdown()}
151
+ onFocus={() => setIsInputFocused(true)}
152
+ onKeyDown={handleKeyDown}
153
+ placeholder={
154
+ selected.label
155
+ ? ""
156
+ : placeholder
157
+ ? placeholder
158
+ : "Select..."
159
+ }
160
+ ref={inputRef}
161
+ value={filterItem}
162
+ />
163
+ )}
164
+ </Flex>
165
+ </FlexItem>
166
+ <Body
167
+ dark={dark}
168
+ display="flex"
169
+ htmlOptions={{
170
+ onClick: (e: Event) => {e.stopPropagation();handleWrapperClick()}
171
+ }}
172
+ key={`${isDropDownClosed ? "chevron-down" : "chevron-up"}`}
173
+ >
174
+ <Icon
175
+ cursor="pointer"
176
+ dark={dark}
177
+ icon={`${isDropDownClosed ? "chevron-down" : "chevron-up"}`}
178
+ size="sm"
118
179
  />
119
- </Body>
120
- </FlexItem>
121
- </Flex>
122
- </>
123
- )}
180
+ </Body>
181
+ </Flex>
182
+ </>
183
+ )
184
+ )
185
+ }
124
186
  </div>
125
187
  );
126
188
  };
@@ -0,0 +1,41 @@
1
+ type HandleClickOutsideType = {
2
+ inputWrapperRef?: React.RefObject<HTMLDivElement>;
3
+ dropdownContainerRef?: React.RefObject<HTMLDivElement>;
4
+ setIsDropDownClosed?: (value: boolean) => void;
5
+ setFocusedOptionIndex?: (value: number) => void;
6
+ setIsInputFocused?: (value: boolean) => void;
7
+ };
8
+
9
+ export const handleClickOutside =
10
+ ({
11
+ inputWrapperRef,
12
+ dropdownContainerRef,
13
+ setIsDropDownClosed,
14
+ setFocusedOptionIndex,
15
+ setIsInputFocused,
16
+ }: HandleClickOutsideType) =>
17
+ (e: MouseEvent) => {
18
+ let targetElement = e.target as HTMLElement;
19
+ let shouldClose = true;
20
+
21
+ //Only needed for when useDropdown hook used with external trigger
22
+ while (targetElement && shouldClose) {
23
+ if (
24
+ targetElement.getAttribute("data-dropdown") === "pb-dropdown-trigger"
25
+ ) {
26
+ shouldClose = false;
27
+ }
28
+ targetElement = targetElement.parentElement as HTMLElement;
29
+ }
30
+ if (
31
+ inputWrapperRef.current &&
32
+ !inputWrapperRef.current.contains((e.target as HTMLElement)) &&
33
+ dropdownContainerRef.current &&
34
+ !dropdownContainerRef.current.contains((e.target as HTMLElement)) &&
35
+ shouldClose
36
+ ) {
37
+ setIsDropDownClosed(true);
38
+ setFocusedOptionIndex(-1);
39
+ setIsInputFocused(false);
40
+ }
41
+ };
@@ -0,0 +1,2 @@
1
+ export { separateChildComponents, prepareSubcomponents } from './subComponentHelper';
2
+ export { handleClickOutside } from './clickOutsideHelper';
@@ -4,11 +4,12 @@ import DropdownContainer from "../subcomponents/DropdownContainer";
4
4
 
5
5
  type PrepareComponentsProps = {
6
6
  children: React.ReactChild[] | React.ReactChild;
7
- hasTriggerSubcomponent: boolean;
8
- hasContainerSubcomponent: boolean;
9
- trigger: React.ReactChild;
10
7
  container: React.ReactChild;
8
+ dark?: boolean;
9
+ hasContainerSubcomponent: boolean;
10
+ hasTriggerSubcomponent: boolean;
11
11
  otherChildren: React.ReactChild[];
12
+ trigger: React.ReactChild;
12
13
  };
13
14
 
14
15
  export const separateChildComponents = (children: React.ReactChild[] | React.ReactChild | ReactElement[]) => {
@@ -36,19 +37,20 @@ export const prepareSubcomponents = ({
36
37
  trigger,
37
38
  container,
38
39
  otherChildren,
40
+ dark
39
41
  }: PrepareComponentsProps) => {
40
42
  const componentsToRender = [];
41
43
 
42
44
  if (!hasTriggerSubcomponent && !hasContainerSubcomponent) {
43
- componentsToRender.push(<DropdownTrigger />);
44
- componentsToRender.push(<DropdownContainer>{children}</DropdownContainer>);
45
+ componentsToRender.push(<DropdownTrigger dark={dark}/>);
46
+ componentsToRender.push(<DropdownContainer dark={dark}>{children}</DropdownContainer>);
45
47
  } else if (!hasTriggerSubcomponent && hasContainerSubcomponent) {
46
- componentsToRender.push(<DropdownTrigger />);
48
+ componentsToRender.push(<DropdownTrigger dark={dark}/>);
47
49
  componentsToRender.push(children);
48
50
  } else if (hasTriggerSubcomponent && !hasContainerSubcomponent) {
49
51
  componentsToRender.push(trigger);
50
52
  componentsToRender.push(
51
- <DropdownContainer>{otherChildren}</DropdownContainer>
53
+ <DropdownContainer dark={dark}>{otherChildren}</DropdownContainer>
52
54
  );
53
55
  } else {
54
56
  componentsToRender.push(trigger);
@@ -14,6 +14,7 @@ type LoadingInlineProps = {
14
14
  data?: { [key: string]: string },
15
15
  htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
16
16
  id?: string,
17
+ text?: string,
17
18
  }
18
19
 
19
20
  const LoadingInline = (props: LoadingInlineProps) => {
@@ -24,6 +25,7 @@ const LoadingInline = (props: LoadingInlineProps) => {
24
25
  data = {},
25
26
  htmlOptions = {},
26
27
  id,
28
+ text = ' Loading',
27
29
  } = props
28
30
 
29
31
  const ariaProps = buildAriaProps(aria)
@@ -50,7 +52,7 @@ const LoadingInline = (props: LoadingInlineProps) => {
50
52
  icon="spinner"
51
53
  pulse
52
54
  />
53
- {' Loading'}
55
+ {text}
54
56
  </Body>
55
57
  </div>
56
58
  )