playbook_ui 13.24.0.pre.alpha.play1305drycontenttag2689 → 13.25.0.pre.alpha.PLAY761globalpaddingpropsbuttons2713

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/_playbook.scss +2 -0
  3. data/app/pb_kits/playbook/index.js +1 -0
  4. data/app/pb_kits/playbook/pb_advanced_table/advanced_table.html.erb +14 -10
  5. data/app/pb_kits/playbook/pb_advanced_table/table_body.html.erb +9 -5
  6. data/app/pb_kits/playbook/pb_advanced_table/table_header.html.erb +6 -2
  7. data/app/pb_kits/playbook/pb_advanced_table/table_row.html.erb +6 -2
  8. data/app/pb_kits/playbook/pb_avatar_action_button/avatar_action_button.html.erb +6 -1
  9. data/app/pb_kits/playbook/pb_background/_background.tsx +7 -5
  10. data/app/pb_kits/playbook/pb_background/background.html.erb +10 -2
  11. data/app/pb_kits/playbook/pb_badge/badge.html.erb +6 -1
  12. data/app/pb_kits/playbook/pb_body/body.html.erb +6 -1
  13. data/app/pb_kits/playbook/pb_bread_crumbs/bread_crumb_item.html.erb +6 -1
  14. data/app/pb_kits/playbook/pb_bread_crumbs/bread_crumbs.html.erb +7 -2
  15. data/app/pb_kits/playbook/pb_button/_button.scss +1 -1
  16. data/app/pb_kits/playbook/pb_button/button.html.erb +1 -1
  17. data/app/pb_kits/playbook/pb_button_toolbar/button_toolbar.html.erb +7 -2
  18. data/app/pb_kits/playbook/pb_caption/caption.html.erb +6 -1
  19. data/app/pb_kits/playbook/pb_card/card.html.erb +7 -1
  20. data/app/pb_kits/playbook/pb_card/card_body.html.erb +6 -1
  21. data/app/pb_kits/playbook/pb_card/card_header.html.erb +6 -1
  22. data/app/pb_kits/playbook/pb_checkbox/checkbox.html.erb +6 -1
  23. data/app/pb_kits/playbook/pb_circle_icon_button/circle_icon_button.html.erb +6 -1
  24. data/app/pb_kits/playbook/pb_collapsible/collapsible.html.erb +6 -1
  25. data/app/pb_kits/playbook/pb_collapsible/collapsible_content.html.erb +6 -1
  26. data/app/pb_kits/playbook/pb_collapsible/collapsible_main.html.erb +6 -1
  27. data/app/pb_kits/playbook/pb_contact/contact.html.erb +6 -1
  28. data/app/pb_kits/playbook/pb_currency/currency.html.erb +6 -1
  29. data/app/pb_kits/playbook/pb_dashboard_value/dashboard_value.html.erb +6 -1
  30. data/app/pb_kits/playbook/pb_date/date.html.erb +6 -1
  31. data/app/pb_kits/playbook/pb_date_picker/date_picker.html.erb +4 -1
  32. data/app/pb_kits/playbook/pb_date_range_inline/date_range_inline.html.erb +5 -1
  33. data/app/pb_kits/playbook/pb_date_range_stacked/date_range_stacked.html.erb +5 -1
  34. data/app/pb_kits/playbook/pb_date_stacked/date_stacked.html.erb +5 -1
  35. data/app/pb_kits/playbook/pb_date_time/date_time.html.erb +6 -1
  36. data/app/pb_kits/playbook/pb_date_time_stacked/date_time_stacked.html.erb +7 -1
  37. data/app/pb_kits/playbook/pb_date_year_stacked/date_year_stacked.html.erb +5 -1
  38. data/app/pb_kits/playbook/pb_detail/detail.html.erb +6 -1
  39. data/app/pb_kits/playbook/pb_dialog/dialog.html.erb +6 -1
  40. data/app/pb_kits/playbook/pb_dialog/dialog_body.html.erb +7 -2
  41. data/app/pb_kits/playbook/pb_dialog/dialog_footer.html.erb +5 -1
  42. data/app/pb_kits/playbook/pb_dialog/dialog_header.html.erb +4 -1
  43. data/app/pb_kits/playbook/pb_dialog/docs/example.yml +1 -1
  44. data/app/pb_kits/playbook/pb_dropdown/_dropdown.scss +98 -0
  45. data/app/pb_kits/playbook/pb_dropdown/_dropdown.tsx +186 -0
  46. data/app/pb_kits/playbook/pb_dropdown/context/index.tsx +5 -0
  47. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_default.jsx +50 -0
  48. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_display.jsx +102 -0
  49. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_options.jsx +66 -0
  50. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_trigger.jsx +77 -0
  51. data/app/pb_kits/playbook/pb_dropdown/docs/example.yml +9 -0
  52. data/app/pb_kits/playbook/pb_dropdown/docs/index.js +4 -0
  53. data/app/pb_kits/playbook/pb_dropdown/dropdown.test.jsx +17 -0
  54. data/app/pb_kits/playbook/pb_dropdown/hooks/useDropdown.tsx +17 -0
  55. data/app/pb_kits/playbook/pb_dropdown/hooks/useHandleOnKeydown.tsx +56 -0
  56. data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownContainer.tsx +95 -0
  57. data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownOption.tsx +91 -0
  58. data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownTrigger.tsx +128 -0
  59. data/app/pb_kits/playbook/pb_dropdown/utilities/subComponentHelper.tsx +59 -0
  60. data/app/pb_kits/playbook/pb_file_upload/file_upload.html.erb +6 -1
  61. data/app/pb_kits/playbook/pb_filter/filter.html.erb +5 -1
  62. data/app/pb_kits/playbook/pb_fixed_confirmation_toast/fixed_confirmation_toast.html.erb +6 -1
  63. data/app/pb_kits/playbook/pb_flex/flex.html.erb +5 -1
  64. data/app/pb_kits/playbook/pb_flex/flex_item.html.erb +4 -1
  65. data/app/pb_kits/playbook/pb_form_group/form_group.html.erb +6 -1
  66. data/app/pb_kits/playbook/pb_form_pill/form_pill.html.erb +1 -1
  67. data/app/pb_kits/playbook/pb_hashtag/hashtag.html.erb +6 -1
  68. data/app/pb_kits/playbook/pb_highlight/highlight.html.erb +5 -1
  69. data/app/pb_kits/playbook/pb_home_address_street/home_address_street.html.erb +5 -1
  70. data/app/pb_kits/playbook/pb_icon_circle/_icon_circle.scss +1 -1
  71. data/app/pb_kits/playbook/pb_icon_circle/_icon_circle.tsx +1 -1
  72. data/app/pb_kits/playbook/pb_icon_circle/icon_circle.html.erb +7 -2
  73. data/app/pb_kits/playbook/pb_icon_circle/icon_circle.rb +1 -1
  74. data/app/pb_kits/playbook/pb_icon_circle/icon_circle.test.js +3 -3
  75. data/app/pb_kits/playbook/pb_icon_stat_value/icon_stat_value.html.erb +6 -1
  76. data/app/pb_kits/playbook/pb_icon_value/icon_value.html.erb +6 -1
  77. data/app/pb_kits/playbook/pb_label_pill/label_pill.html.erb +6 -1
  78. data/app/pb_kits/playbook/pb_label_value/label_value.html.erb +6 -1
  79. data/app/pb_kits/playbook/pb_layout/body.html.erb +5 -1
  80. data/app/pb_kits/playbook/pb_layout/footer.html.erb +5 -1
  81. data/app/pb_kits/playbook/pb_layout/header.html.erb +5 -1
  82. data/app/pb_kits/playbook/pb_layout/item.html.erb +5 -1
  83. data/app/pb_kits/playbook/pb_layout/layout.html.erb +5 -1
  84. data/app/pb_kits/playbook/pb_layout/sidebar.html.erb +5 -1
  85. data/app/pb_kits/playbook/pb_list/_list_item.tsx +2 -2
  86. data/app/pb_kits/playbook/pb_list/item.html.erb +8 -3
  87. data/app/pb_kits/playbook/pb_list/list.html.erb +5 -1
  88. data/app/pb_kits/playbook/pb_loading_inline/loading_inline.html.erb +6 -1
  89. data/app/pb_kits/playbook/pb_message/message.html.erb +6 -1
  90. data/app/pb_kits/playbook/pb_message/message_mention.html.erb +6 -1
  91. data/app/pb_kits/playbook/pb_multi_level_select/multi_level_select.html.erb +6 -1
  92. data/app/pb_kits/playbook/pb_multiple_users/multiple_users.html.erb +6 -1
  93. data/app/pb_kits/playbook/pb_multiple_users_stacked/multiple_users_stacked.html.erb +6 -1
  94. data/app/pb_kits/playbook/pb_nav/item.html.erb +10 -2
  95. data/app/pb_kits/playbook/pb_nav/nav.html.erb +6 -1
  96. data/app/pb_kits/playbook/pb_online_status/online_status.html.erb +4 -1
  97. data/app/pb_kits/playbook/pb_pagination/pagination.html.erb +6 -1
  98. data/app/pb_kits/playbook/pb_person/person.html.erb +12 -7
  99. data/app/pb_kits/playbook/pb_person_contact/person_contact.html.erb +6 -1
  100. data/app/pb_kits/playbook/pb_pill/pill.html.erb +6 -1
  101. data/app/pb_kits/playbook/pb_popover/popover.html.erb +6 -1
  102. data/app/pb_kits/playbook/pb_progress_pills/progress_pills.html.erb +4 -1
  103. data/app/pb_kits/playbook/pb_progress_simple/progress_simple.html.erb +6 -4
  104. data/app/pb_kits/playbook/pb_progress_step/progress_step.html.erb +5 -1
  105. data/app/pb_kits/playbook/pb_progress_step/progress_step_item.html.erb +5 -1
  106. data/app/pb_kits/playbook/pb_radio/radio.html.erb +6 -1
  107. data/app/pb_kits/playbook/pb_section_separator/section_separator.html.erb +6 -1
  108. data/app/pb_kits/playbook/pb_select/select.html.erb +5 -1
  109. data/app/pb_kits/playbook/pb_selectable_card/selectable_card.html.erb +5 -1
  110. data/app/pb_kits/playbook/pb_selectable_card_icon/selectable_card_icon.html.erb +4 -1
  111. data/app/pb_kits/playbook/pb_selectable_icon/selectable_icon.html.erb +5 -1
  112. data/app/pb_kits/playbook/pb_selectable_list/selectable_list.html.erb +6 -1
  113. data/app/pb_kits/playbook/pb_selectable_list/selectable_list_item.html.erb +6 -1
  114. data/app/pb_kits/playbook/pb_source/source.html.erb +5 -1
  115. data/app/pb_kits/playbook/pb_source/source.test.js +2 -2
  116. data/app/pb_kits/playbook/pb_star_rating/star_rating.html.erb +5 -1
  117. data/app/pb_kits/playbook/pb_stat_change/stat_change.html.erb +5 -1
  118. data/app/pb_kits/playbook/pb_stat_value/stat_value.html.erb +5 -1
  119. data/app/pb_kits/playbook/pb_table/table.html.erb +5 -1
  120. data/app/pb_kits/playbook/pb_table/table_body.html.erb +16 -6
  121. data/app/pb_kits/playbook/pb_table/table_cell.html.erb +16 -6
  122. data/app/pb_kits/playbook/pb_table/table_head.html.erb +16 -6
  123. data/app/pb_kits/playbook/pb_table/table_header.html.erb +11 -3
  124. data/app/pb_kits/playbook/pb_table/table_row.html.erb +16 -6
  125. data/app/pb_kits/playbook/pb_text_input/text_input.html.erb +5 -1
  126. data/app/pb_kits/playbook/pb_textarea/textarea.html.erb +5 -1
  127. data/app/pb_kits/playbook/pb_time/time.html.erb +5 -1
  128. data/app/pb_kits/playbook/pb_time_range_inline/time_range_inline.html.erb +5 -1
  129. data/app/pb_kits/playbook/pb_time_stacked/time_stacked.html.erb +5 -1
  130. data/app/pb_kits/playbook/pb_timeline/item.html.erb +7 -3
  131. data/app/pb_kits/playbook/pb_timeline/timeline.html.erb +5 -1
  132. data/app/pb_kits/playbook/pb_timestamp/timestamp.html.erb +6 -1
  133. data/app/pb_kits/playbook/pb_title/title.html.erb +6 -3
  134. data/app/pb_kits/playbook/pb_title_count/title_count.html.erb +6 -1
  135. data/app/pb_kits/playbook/pb_title_detail/title_detail.html.erb +5 -1
  136. data/app/pb_kits/playbook/pb_toggle/toggle.html.erb +6 -1
  137. data/app/pb_kits/playbook/pb_tooltip/tooltip.html.erb +5 -1
  138. data/app/pb_kits/playbook/pb_user/user.html.erb +6 -1
  139. data/app/pb_kits/playbook/pb_user_badge/user_badge.html.erb +6 -1
  140. data/app/pb_kits/playbook/pb_weekday_stacked/weekday_stacked.html.erb +6 -1
  141. data/app/pb_kits/playbook/playbook-doc.js +2 -0
  142. data/dist/menu.yml +5 -1
  143. data/dist/playbook-rails.js +5 -5
  144. data/lib/playbook/version.rb +2 -2
  145. metadata +19 -3
  146. /data/app/pb_kits/playbook/pb_dialog/docs/{_dialog_props_table.md → _dialog_props_swift.md} +0 -0
@@ -0,0 +1,98 @@
1
+ @import "../tokens/colors";
2
+ @import "../tokens/spacing";
3
+ @import "../tokens/typography";
4
+ @import "../tokens/border_radius";
5
+ @import "../tokens/shadows";
6
+ @import "../tokens/positioning";
7
+ @import "../pb_body/body_mixins";
8
+
9
+ .pb_dropdown {
10
+ .dropdown_wrapper {
11
+ position: relative;
12
+ .dropdown_trigger_wrapper {
13
+ @include pb_body;
14
+ border: 1px solid $border_light;
15
+ background-color: $white;
16
+ box-shadow: inset 0 -11px 20px rgba($primary, 0.05);
17
+ @media (hover: hover) {
18
+ &:hover,
19
+ &:active,
20
+ &:focus {
21
+ background-color: $focus_input_light;
22
+ }
23
+ input {
24
+ background-color: $focus_input_light;
25
+ }
26
+ }
27
+
28
+ .dropdown_input {
29
+ @include pb_body;
30
+ border: unset;
31
+ border-radius: $border_rad_heavier;
32
+ padding: 0;
33
+
34
+ &:focus-visible {
35
+ outline: none;
36
+ }
37
+ }
38
+ &:focus {
39
+ box-shadow: 0px 0px 0 1px $primary;
40
+ outline: unset;
41
+ transition: box-shadow 0.15s ease-in-out;
42
+ }
43
+ }
44
+
45
+ .dropdown_trigger_wrapper_focus {
46
+ box-shadow: 0px 0px 0 1px $primary;
47
+ transition: box-shadow .10s ease-in-out;
48
+ }
49
+
50
+ .pb_dropdown_container {
51
+ background-color: $white;
52
+ overflow: hidden;
53
+ box-shadow: $shadow_deep;
54
+ border-radius: $border_rad_heavier;
55
+ border: 1px solid $border_light;
56
+ margin-top: $space_xs;
57
+ position: absolute;
58
+ z-index: $z_1;
59
+ width: 100%;
60
+ transition: opacity 0.25s ease-in-out;
61
+
62
+ .pb_dropdown_option {
63
+ :hover {
64
+ background-color: $border_light;
65
+ }
66
+ }
67
+
68
+ .dropdown_option_focused {
69
+ background-color: $border_light;
70
+ }
71
+
72
+ .dropdown_option {
73
+ width: 100%;
74
+ }
75
+
76
+ .dropdown_option_list {
77
+ border-bottom: 1px solid $border_light;
78
+ }
79
+ .dropdown_option_selected {
80
+ background-color: $primary;
81
+ [class^="pb_body"],
82
+ [class^="pb_title_kit"] {
83
+ color: $white !important;
84
+ }
85
+ :hover {
86
+ background-color: unset;
87
+ }
88
+ }
89
+ }
90
+ .close {
91
+ display: none;
92
+ }
93
+
94
+ .open {
95
+ display: block;
96
+ }
97
+ }
98
+ }
@@ -0,0 +1,186 @@
1
+ import React, { useState, useRef, useEffect, ReactElement } from "react";
2
+ import classnames from "classnames";
3
+ import { buildAriaProps, buildCss, buildDataProps } from "../utilities/props";
4
+ import { globalProps } from "../utilities/globalProps";
5
+
6
+ import Body from "../pb_body/_body";
7
+
8
+ import DropdownContainer from "./subcomponents/DropdownContainer";
9
+ import DropdownOption from "./subcomponents/DropdownOption";
10
+ import DropdownTrigger from "./subcomponents/DropdownTrigger";
11
+ import DropdownContext from "./context";
12
+ import useDropdown from "./hooks/useDropdown";
13
+
14
+ import {
15
+ separateChildComponents,
16
+ prepareSubcomponents,
17
+ } from "./utilities/subComponentHelper";
18
+ import { GenericObject } from "../types";
19
+
20
+ type DropdownProps = {
21
+ aria?: { [key: string]: string };
22
+ autocomplete?: boolean;
23
+ className?: string;
24
+ data?: { [key: string]: string };
25
+ id?: string;
26
+ children?: React.ReactChild[] | React.ReactChild | ReactElement[];
27
+ options: GenericObject;
28
+ onSelect?: (arg: GenericObject) => null;
29
+ };
30
+
31
+ const Dropdown = (props: DropdownProps) => {
32
+ const {
33
+ aria = {},
34
+ autocomplete = false,
35
+ children,
36
+ className,
37
+ data = {},
38
+ id,
39
+ options,
40
+ onSelect,
41
+ } = props;
42
+
43
+ const ariaProps = buildAriaProps(aria);
44
+ const dataProps = buildDataProps(data);
45
+ const classes = classnames(
46
+ buildCss("pb_dropdown"),
47
+ globalProps(props),
48
+ className
49
+ );
50
+
51
+ const [isDropDownClosed, setIsDropDownClosed, toggleDropdown] = useDropdown();
52
+
53
+ const [filterItem, setFilterItem] = useState("");
54
+ const [selected, setSelected] = useState({});
55
+ const [isInputFocused, setIsInputFocused] = useState(false);
56
+ const [hasTriggerSubcomponent, setHasTriggerSubcomponent] = useState(true);
57
+ const [hasContainerSubcomponent, setHasContainerSubcomponent] =
58
+ useState(true);
59
+
60
+ //state for keyboard events
61
+ const [focusedOptionIndex, setFocusedOptionIndex] = useState(-1);
62
+
63
+ const dropdownRef = useRef(null);
64
+ const inputRef = useRef(null);
65
+
66
+ const { trigger, container, otherChildren } =
67
+ separateChildComponents(children);
68
+
69
+ // useEffect to handle clicks outside the dropdown
70
+ useEffect(() => {
71
+ const handleClickOutside = (e: MouseEvent) => {
72
+ if (dropdownRef.current && !dropdownRef.current.contains(e.target)) {
73
+ setIsDropDownClosed(true);
74
+ setIsInputFocused(false);
75
+ }
76
+ };
77
+ window.addEventListener("click", handleClickOutside);
78
+ return () => {
79
+ window.removeEventListener("click", handleClickOutside);
80
+ };
81
+ }, []);
82
+
83
+ useEffect(() => {
84
+ setHasTriggerSubcomponent(!!trigger);
85
+ setHasContainerSubcomponent(!!container);
86
+ }, []);
87
+
88
+ const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
89
+ setFilterItem(e.target.value);
90
+ setIsDropDownClosed(false);
91
+ };
92
+
93
+ const handleOptionClick = (selectedItem: GenericObject) => {
94
+ setSelected(selectedItem);
95
+ setFilterItem("");
96
+ setIsDropDownClosed(true);
97
+ onSelect(selectedItem);
98
+ };
99
+
100
+ const handleWrapperClick = () => {
101
+ autocomplete && inputRef.current.focus();
102
+ toggleDropdown();
103
+ };
104
+
105
+ const handleBackspace = () => {
106
+ setSelected({});
107
+ onSelect(null);
108
+ setFocusedOptionIndex(-1);
109
+ };
110
+
111
+ const filteredOptions = options?.filter((option: GenericObject) =>
112
+ option.label.toLowerCase().includes(filterItem.toLowerCase())
113
+ );
114
+
115
+ const componentsToRender = prepareSubcomponents({
116
+ children,
117
+ hasTriggerSubcomponent,
118
+ hasContainerSubcomponent,
119
+ trigger,
120
+ container,
121
+ otherChildren,
122
+ });
123
+
124
+ return (
125
+ <div {...ariaProps}
126
+ {...dataProps}
127
+ className={classes}
128
+ id={id}
129
+ >
130
+ <DropdownContext.Provider
131
+ value={{
132
+ autocomplete,
133
+ filteredOptions,
134
+ filterItem,
135
+ focusedOptionIndex,
136
+ handleBackspace,
137
+ handleChange,
138
+ handleOptionClick,
139
+ handleWrapperClick,
140
+ inputRef,
141
+ isDropDownClosed,
142
+ isInputFocused,
143
+ options,
144
+ selected,
145
+ setFocusedOptionIndex,
146
+ setIsDropDownClosed,
147
+ setIsInputFocused,
148
+ setSelected,
149
+ toggleDropdown,
150
+ }}
151
+ >
152
+ <div className="dropdown_wrapper"
153
+ ref={dropdownRef}
154
+ >
155
+ {children ? (
156
+ <>
157
+ {componentsToRender.map((component, index) => (
158
+ <React.Fragment key={index}>{component}</React.Fragment>
159
+ ))}
160
+ </>
161
+ ) : (
162
+ <>
163
+ <DropdownTrigger />
164
+ <DropdownContainer>
165
+ {options &&
166
+ options?.map((option: GenericObject) => (
167
+ <Dropdown.Option key={option.id}
168
+ option={option}
169
+ >
170
+ <Body text={option.label} />
171
+ </Dropdown.Option>
172
+ ))}
173
+ </DropdownContainer>
174
+ </>
175
+ )}
176
+ </div>
177
+ </DropdownContext.Provider>
178
+ </div>
179
+ );
180
+ };
181
+
182
+ Dropdown.Option = DropdownOption;
183
+ Dropdown.Trigger = DropdownTrigger;
184
+ Dropdown.Container = DropdownContainer;
185
+
186
+ export default Dropdown;
@@ -0,0 +1,5 @@
1
+ import { createContext } from "react";
2
+
3
+ const DropdownContext = createContext<any>({});
4
+
5
+ export default DropdownContext;
@@ -0,0 +1,50 @@
1
+ import React, { useState } from 'react'
2
+ import { Dropdown } from '../../'
3
+
4
+ const DropdownDefault = (props) => {
5
+ // eslint-disable-next-line no-unused-vars
6
+ const [selectedOption, setSelectedOption] = useState();
7
+
8
+ const options = [
9
+ {
10
+ label: "United States",
11
+ value: "United States",
12
+ areaCode: "+1",
13
+ icon: "🇺🇸",
14
+ id: "United-states"
15
+ },
16
+ {
17
+ label: "Ukraine",
18
+ value: "Ukraine",
19
+ areaCode: "+380",
20
+ icon: "🇺🇦",
21
+ id: "ukraine"
22
+ },
23
+ {
24
+ label: "Pakistan",
25
+ value: "Pakistan",
26
+ areaCode: "+92",
27
+ icon: "🇵🇰",
28
+ id: "pakistan"
29
+ }
30
+ ];
31
+
32
+
33
+ return (
34
+ <div>
35
+ <Dropdown
36
+ onSelect={(selectedItem) => setSelectedOption(selectedItem)}
37
+ options={options}
38
+ {...props}
39
+ >
40
+ {options.map((option) => (
41
+ <Dropdown.Option key={option.id}
42
+ option={option}
43
+ />
44
+ ))}
45
+ </Dropdown>
46
+ </div>
47
+ )
48
+ }
49
+
50
+ export default DropdownDefault
@@ -0,0 +1,102 @@
1
+ import React, { useState } from 'react'
2
+ import { Dropdown, User, FlexItem, Badge, Avatar } from '../../'
3
+
4
+ const DropdownWithCustomDisplay = (props) => {
5
+ const [selectedOption, setSelectedOption] = useState();
6
+
7
+ const options = [
8
+ {
9
+ label: "Jasper Furniss",
10
+ value: "Jasper Furniss",
11
+ territory: "PHL",
12
+ title: "Senior UX Engineer",
13
+ id: "jasper-furniss",
14
+ status: "Offline"
15
+ },
16
+ {
17
+ label: "Ramon Ruiz",
18
+ value: "Ramon Ruiz",
19
+ territory: "PHL",
20
+ title: "Senior UX Desinger",
21
+ id: "ramon-ruiz",
22
+ status: "Away"
23
+ },
24
+ {
25
+ label: "Jason Cypret",
26
+ value: "Jason Cypret",
27
+ territory: "PHL",
28
+ title: "VP of User Experience",
29
+ id: "jason-cypret",
30
+ status: "Online"
31
+ },
32
+ {
33
+ label: "Courtney Long",
34
+ value: "Courtney Long",
35
+ territory: "PHL",
36
+ title: "UX Design Mentor",
37
+ id: "courtney-long",
38
+ status: "Online"
39
+ }
40
+ ];
41
+
42
+ const customDisplay = () => {
43
+ return (
44
+ <>
45
+ {
46
+ selectedOption && (
47
+ <Avatar
48
+ name={selectedOption.label}
49
+ size="xs"
50
+ />
51
+ )
52
+ }
53
+ </>
54
+ )
55
+ };
56
+
57
+
58
+ return (
59
+ <div>
60
+ <Dropdown
61
+ onSelect={(selectedItem) => setSelectedOption(selectedItem)}
62
+ options={options}
63
+ {...props}
64
+ >
65
+ <Dropdown.Trigger customDisplay={customDisplay()}/>
66
+ {options.map((option) => (
67
+ <Dropdown.Option key={option.id}
68
+ option={option}
69
+ >
70
+ <>
71
+ <FlexItem>
72
+ <User
73
+ align="left"
74
+ avatar
75
+ name={option.label}
76
+ orientation="horizontal"
77
+ territory={option.territory}
78
+ title={option.title}
79
+ />
80
+ </FlexItem>
81
+ <FlexItem>
82
+ <Badge
83
+ rounded
84
+ text={option.status}
85
+ variant={`${
86
+ option.status === "Offline"
87
+ ? "neutral"
88
+ : option.status === "Online"
89
+ ? "success"
90
+ : "warning"
91
+ }`}
92
+ />
93
+ </FlexItem>
94
+ </>
95
+ </Dropdown.Option>
96
+ ))}
97
+ </Dropdown>
98
+ </div>
99
+ )
100
+ }
101
+
102
+ export default DropdownWithCustomDisplay
@@ -0,0 +1,66 @@
1
+ import React, { useState } from 'react'
2
+ import { Dropdown, Icon, Body, FlexItem, Flex } from '../..'
3
+
4
+ const DropdownWithCustomOptions = (props) => {
5
+ // eslint-disable-next-line no-unused-vars
6
+ const [selectedOption, setSelectedOption] = useState();
7
+
8
+ const options = [
9
+ {
10
+ label: "United States",
11
+ value: "United States",
12
+ areaCode: "+1",
13
+ icon: "🇺🇸",
14
+ id: "United-states"
15
+ },
16
+ {
17
+ label: "Ukraine",
18
+ value: "Ukraine",
19
+ areaCode: "+380",
20
+ icon: "🇺🇦",
21
+ id: "ukraine"
22
+ },
23
+ {
24
+ label: "Pakistan",
25
+ value: "Pakistan",
26
+ areaCode: "+92",
27
+ icon: "🇵🇰",
28
+ id: "pakistan"
29
+ }
30
+ ];
31
+
32
+
33
+ return (
34
+ <div>
35
+ <Dropdown
36
+ onSelect={(selectedItem) => setSelectedOption(selectedItem)}
37
+ options={options}
38
+ {...props}
39
+ >
40
+ {options.map((option) => (
41
+ <Dropdown.Option key={option.id}
42
+ option={option}
43
+ >
44
+ <>
45
+ <FlexItem>
46
+ <Flex>
47
+ <Icon icon={option.icon}
48
+ paddingRight="xs"
49
+ />
50
+ <Body text={option.label} />
51
+ </Flex>
52
+ </FlexItem>
53
+ <FlexItem>
54
+ <Body color="light"
55
+ text={option.areaCode}
56
+ />
57
+ </FlexItem>
58
+ </>
59
+ </Dropdown.Option>
60
+ ))}
61
+ </Dropdown>
62
+ </div>
63
+ )
64
+ }
65
+
66
+ export default DropdownWithCustomOptions
@@ -0,0 +1,77 @@
1
+ import React, { useState } from 'react'
2
+ import { Dropdown, Icon, Body, FlexItem, Flex, IconCircle } from '../..'
3
+
4
+ const DropdownWithCustomTrigger = (props) => {
5
+
6
+ const [selectedOption, setSelectedOption] = useState();
7
+
8
+ const options = [
9
+ {
10
+ label: "United States",
11
+ value: "United States",
12
+ areaCode: "+1",
13
+ icon: "🇺🇸",
14
+ id: "United-states"
15
+ },
16
+ {
17
+ label: "Ukraine",
18
+ value: "Ukraine",
19
+ areaCode: "+380",
20
+ icon: "🇺🇦",
21
+ id: "ukraine"
22
+ },
23
+ {
24
+ label: "Pakistan",
25
+ value: "Pakistan",
26
+ areaCode: "+92",
27
+ icon: "🇵🇰",
28
+ id: "pakistan"
29
+ }
30
+ ];
31
+
32
+
33
+ return (
34
+ <div>
35
+ <Dropdown
36
+ onSelect={(selectedItem) => setSelectedOption(selectedItem)}
37
+ options={options}
38
+ {...props}
39
+ >
40
+ <Dropdown.Trigger>
41
+ <div key={selectedOption ? selectedOption.icon : "flag"}>
42
+ <IconCircle
43
+ cursor="pointer"
44
+ icon={selectedOption ? selectedOption.icon : "flag"}
45
+ variant="royal"
46
+ />
47
+ </div>
48
+ </Dropdown.Trigger>
49
+ <Dropdown.Container maxWidth="xs">
50
+ {options.map((option) => (
51
+ <Dropdown.Option key={option.id}
52
+ option={option}
53
+ >
54
+ <>
55
+ <FlexItem>
56
+ <Flex>
57
+ <Icon icon={option.icon}
58
+ paddingRight="xs"
59
+ />
60
+ <Body text={option.label} />
61
+ </Flex>
62
+ </FlexItem>
63
+ <FlexItem>
64
+ <Body color="light"
65
+ text={option.areaCode}
66
+ />
67
+ </FlexItem>
68
+ </>
69
+ </Dropdown.Option>
70
+ ))}
71
+ </Dropdown.Container>
72
+ </Dropdown>
73
+ </div>
74
+ )
75
+ }
76
+
77
+ export default DropdownWithCustomTrigger
@@ -0,0 +1,9 @@
1
+ examples:
2
+
3
+
4
+ react:
5
+ - dropdown_default: Default
6
+ - dropdown_with_custom_options: Custom Options
7
+ - dropdown_with_custom_display: Custom Display
8
+ - dropdown_with_custom_trigger: Custom Trigger
9
+
@@ -0,0 +1,4 @@
1
+ export { default as DropdownDefault } from './_dropdown_default.jsx'
2
+ export { default as DropdownWithCustomDisplay } from './_dropdown_with_custom_display.jsx'
3
+ export { default as DropdownWithCustomOptions } from './_dropdown_with_custom_options.jsx'
4
+ export { default as DropdownWithCustomTrigger } from './_dropdown_with_custom_trigger.jsx'
@@ -0,0 +1,17 @@
1
+ import { renderKit } from '../utilities/test-utils'
2
+
3
+ import { Dropdown } from '../'
4
+
5
+ /* See these resources for more testing info:
6
+ - https://github.com/testing-library/jest-dom#usage for useage and examples
7
+ - https://jestjs.io/docs/en/using-matchers
8
+ */
9
+
10
+ test('generated scaffold test - update me', () => {
11
+ const props = {
12
+ data: { testid: 'default' }
13
+ }
14
+
15
+ const kit = renderKit(Dropdown , props)
16
+ expect(kit).toBeInTheDocument()
17
+ })
@@ -0,0 +1,17 @@
1
+ import {useState} from 'react';
2
+
3
+
4
+ const useDropdown = (initial=true) => {
5
+
6
+ const [isDropDownClosed, setIsDropDownClosed] = useState(initial);
7
+
8
+ const toggleDropdown = () => setIsDropDownClosed(!isDropDownClosed);
9
+
10
+ return [
11
+ isDropDownClosed,
12
+ setIsDropDownClosed as any,
13
+ toggleDropdown
14
+ ]
15
+ }
16
+
17
+ export default useDropdown
@@ -0,0 +1,56 @@
1
+ import React, { useContext } from "react";
2
+ import DropdownContext from "../context";
3
+
4
+
5
+ export const useHandleOnKeyDown = () => {
6
+
7
+ const {
8
+ autocomplete,
9
+ focusedOptionIndex,
10
+ filteredOptions,
11
+ setFocusedOptionIndex,
12
+ handleOptionClick,
13
+ setIsDropDownClosed,
14
+ handleBackspace,
15
+ selected
16
+ }= useContext(DropdownContext)
17
+
18
+ return (e: React.KeyboardEvent) => {
19
+ switch (e.key) {
20
+ case "Backspace":
21
+ case "Delete":
22
+ if (autocomplete) {
23
+ handleBackspace();
24
+ }
25
+ break;
26
+ case "ArrowDown": {
27
+ e.preventDefault();
28
+ setIsDropDownClosed(false);
29
+ const nextIndex = (focusedOptionIndex + 1) % filteredOptions.length;
30
+ setFocusedOptionIndex(nextIndex);
31
+ break;
32
+ }
33
+ case "ArrowUp": {
34
+ e.preventDefault();
35
+ const nextIndexUp =
36
+ (focusedOptionIndex - 1 + filteredOptions.length) %
37
+ filteredOptions.length;
38
+ setFocusedOptionIndex(nextIndexUp);
39
+ break;
40
+ }
41
+ case "Enter":
42
+ if (focusedOptionIndex !== -1) {
43
+ e.preventDefault();
44
+ handleOptionClick(filteredOptions[focusedOptionIndex]);
45
+ setFocusedOptionIndex(-1)
46
+ }
47
+ break;
48
+ default:
49
+ if (selected && selected.label) {
50
+ e.preventDefault();
51
+ handleBackspace();
52
+ }
53
+ break;
54
+ }
55
+ }
56
+ };