playbook_ui 13.25.0.pre.alpha.barchartfix2766 → 13.26.0.pre.alpha.jasoncypretpatch12816
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/index.js +1 -0
- data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.scss +14 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_beta.html.erb +33 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_beta.md +24 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_default.md +5 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/example.yml +2 -2
- data/app/pb_kits/playbook/pb_advanced_table/index.js +78 -0
- data/app/pb_kits/playbook/pb_advanced_table/table_body.rb +4 -2
- data/app/pb_kits/playbook/pb_advanced_table/table_row.html.erb +3 -2
- data/app/pb_kits/playbook/pb_avatar/Utilities/GetPlacementPropsHelper.tsx +44 -0
- data/app/pb_kits/playbook/pb_avatar/_avatar.tsx +86 -21
- data/app/pb_kits/playbook/pb_avatar/avatar.html.erb +26 -3
- data/app/pb_kits/playbook/pb_avatar/avatar.rb +41 -0
- data/app/pb_kits/playbook/pb_avatar/docs/_avatar_badge_component_overlay.html.erb +71 -0
- data/app/pb_kits/playbook/pb_avatar/docs/_avatar_badge_component_overlay.jsx +77 -0
- data/app/pb_kits/playbook/pb_avatar/docs/_avatar_circle_icon_component_overlay.html.erb +71 -0
- data/app/pb_kits/playbook/pb_avatar/docs/_avatar_circle_icon_component_overlay.jsx +77 -0
- data/app/pb_kits/playbook/pb_avatar/docs/_avatar_default.jsx +20 -0
- data/app/pb_kits/playbook/pb_avatar/docs/example.yml +4 -0
- data/app/pb_kits/playbook/pb_avatar/docs/index.js +2 -0
- data/app/pb_kits/playbook/pb_button/_button_mixins.scss +1 -0
- data/app/pb_kits/playbook/pb_checkbox/_checkbox.scss +49 -0
- data/app/pb_kits/playbook/pb_checkbox/_checkbox.tsx +3 -0
- data/app/pb_kits/playbook/pb_checkbox/checkbox.rb +2 -1
- data/app/pb_kits/playbook/pb_checkbox/checkbox.test.js +14 -0
- data/app/pb_kits/playbook/pb_checkbox/docs/_checkbox_disabled.html.erb +23 -0
- data/app/pb_kits/playbook/pb_checkbox/docs/_checkbox_disabled.jsx +29 -0
- data/app/pb_kits/playbook/pb_checkbox/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_checkbox/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_on_change.md +3 -1
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_on_close.md +3 -1
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_quick_pick_range_limit.md +1 -1
- data/app/pb_kits/playbook/pb_dropdown/_dropdown.scss +92 -31
- data/app/pb_kits/playbook/pb_dropdown/_dropdown.tsx +60 -21
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_default.jsx +2 -20
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_default.md +1 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_subcomponent_structure.jsx +42 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_subcomponent_structure.md +7 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_autocomplete.jsx +1 -4
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_autocomplete_and_custom_display.jsx +0 -1
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_display.jsx +1 -1
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_display.md +3 -1
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_options.jsx +1 -4
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_options.md +1 -1
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_padding.jsx +1 -4
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_external_control.jsx +59 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_hook.jsx +72 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_label.jsx +39 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_label.md +1 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/example.yml +6 -2
- data/app/pb_kits/playbook/pb_dropdown/docs/index.js +5 -1
- data/app/pb_kits/playbook/pb_dropdown/dropdown.test.jsx +200 -10
- data/app/pb_kits/playbook/pb_dropdown/hooks/useDropdown.tsx +2 -2
- data/app/pb_kits/playbook/pb_dropdown/hooks/useHandleOnKeydown.tsx +4 -4
- data/app/pb_kits/playbook/pb_dropdown/scss_partials/_dropdown_animation.scss +18 -0
- data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownContainer.tsx +17 -8
- data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownOption.tsx +25 -15
- data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownTrigger.tsx +96 -78
- data/app/pb_kits/playbook/pb_dropdown/utilities/clickOutsideHelper.tsx +41 -0
- data/app/pb_kits/playbook/pb_dropdown/utilities/index.ts +2 -0
- data/app/pb_kits/playbook/pb_dropdown/utilities/subComponentHelper.tsx +9 -7
- data/app/pb_kits/playbook/pb_loading_inline/_loading_inline.tsx +3 -1
- data/app/pb_kits/playbook/pb_loading_inline/docs/_loading_inline_custom.html.erb +13 -0
- data/app/pb_kits/playbook/pb_loading_inline/docs/_loading_inline_custom.jsx +26 -0
- data/app/pb_kits/playbook/pb_loading_inline/docs/{_loading_inline_light.html.erb → _loading_inline_default.html.erb} +2 -2
- data/app/pb_kits/playbook/pb_loading_inline/docs/{_loading_inline_light.jsx → _loading_inline_default.jsx} +2 -2
- data/app/pb_kits/playbook/pb_loading_inline/docs/example.yml +4 -2
- data/app/pb_kits/playbook/pb_loading_inline/docs/index.js +2 -1
- data/app/pb_kits/playbook/pb_loading_inline/loading_inline.html.erb +1 -1
- data/app/pb_kits/playbook/pb_loading_inline/loading_inline.rb +1 -0
- data/app/pb_kits/playbook/pb_loading_inline/loading_inline.test.js +14 -0
- data/app/pb_kits/playbook/pb_progress_simple/docs/_progress_simple_flex.html.erb +3 -0
- data/app/pb_kits/playbook/pb_progress_simple/docs/_progress_simple_flex.jsx +16 -0
- data/app/pb_kits/playbook/pb_progress_simple/docs/_progress_simple_flex.md +1 -0
- data/app/pb_kits/playbook/pb_progress_simple/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_progress_simple/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_progress_simple/progress_simple.rb +1 -1
- data/app/pb_kits/playbook/pb_radio/_radio.scss +35 -0
- data/app/pb_kits/playbook/pb_radio/_radio.tsx +3 -0
- data/app/pb_kits/playbook/pb_radio/docs/_radio_alignment.jsx +4 -1
- data/app/pb_kits/playbook/pb_radio/docs/_radio_default.jsx +4 -1
- data/app/pb_kits/playbook/pb_radio/docs/_radio_disabled.html.erb +26 -0
- data/app/pb_kits/playbook/pb_radio/docs/_radio_disabled.jsx +31 -0
- data/app/pb_kits/playbook/pb_radio/docs/_radio_error.jsx +2 -1
- data/app/pb_kits/playbook/pb_radio/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_radio/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_radio/radio.rb +5 -0
- data/app/pb_kits/playbook/pb_radio/radio.test.js +17 -0
- data/app/pb_kits/playbook/playbook-rails.js +3 -0
- data/dist/menu.yml +1 -1
- data/dist/playbook-rails.js +6 -6
- data/lib/playbook/version.rb +2 -2
- metadata +30 -5
- data/app/pb_kits/playbook/pb_advanced_table/docs/_description.md +0 -1
@@ -1,17 +1,207 @@
|
|
1
|
-
import
|
1
|
+
import React from "react"
|
2
|
+
import { render, screen } from "../utilities/test-utils"
|
2
3
|
|
3
|
-
import { Dropdown } from '../'
|
4
|
+
import { Dropdown, Icon } from '../'
|
4
5
|
|
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
6
|
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
const testId = 'dropdown'
|
8
|
+
|
9
|
+
const options = [
|
10
|
+
{
|
11
|
+
label: "United States",
|
12
|
+
value: "United States",
|
13
|
+
areaCode: "+1",
|
14
|
+
icon: "🇺🇸",
|
15
|
+
id: "United-states"
|
16
|
+
},
|
17
|
+
{
|
18
|
+
label: "Canada",
|
19
|
+
value: "Canada",
|
20
|
+
areaCode: "+1",
|
21
|
+
icon: "🇨🇦",
|
22
|
+
id: "canada"
|
23
|
+
},
|
24
|
+
{
|
25
|
+
label: "Pakistan",
|
26
|
+
value: "Pakistan",
|
27
|
+
areaCode: "+92",
|
28
|
+
icon: "🇵🇰",
|
29
|
+
id: "pakistan"
|
13
30
|
}
|
31
|
+
];
|
32
|
+
|
33
|
+
const DefaultDropdownKit = () => {
|
34
|
+
return (
|
35
|
+
<Dropdown
|
36
|
+
data={{ testid: testId }}
|
37
|
+
options={options}
|
38
|
+
>
|
39
|
+
{options.map((option) => (
|
40
|
+
<Dropdown.Option key={option.id}
|
41
|
+
option={option}
|
42
|
+
/>
|
43
|
+
))}
|
44
|
+
</Dropdown>
|
45
|
+
)
|
46
|
+
}
|
14
47
|
|
15
|
-
|
48
|
+
test('generated default kit and classname', () => {
|
49
|
+
render(<DefaultDropdownKit/>)
|
50
|
+
|
51
|
+
const kit = screen.getByTestId(testId)
|
16
52
|
expect(kit).toBeInTheDocument()
|
53
|
+
expect(kit).toHaveClass('pb_dropdown')
|
54
|
+
})
|
55
|
+
|
56
|
+
test('generated default Trigger and Container when none passed in', () => {
|
57
|
+
render(<DefaultDropdownKit/>)
|
58
|
+
|
59
|
+
const kit = screen.getByTestId(testId)
|
60
|
+
|
61
|
+
const trigger = kit.querySelector('.pb_dropdown_trigger')
|
62
|
+
expect(trigger).toBeInTheDocument()
|
63
|
+
|
64
|
+
const container = kit.querySelector('.pb_dropdown_container')
|
65
|
+
expect(container).toBeInTheDocument()
|
66
|
+
|
67
|
+
const defaultTrigger = kit.querySelector('.dropdown_trigger_wrapper_select_only')
|
68
|
+
expect(defaultTrigger).toBeInTheDocument()
|
69
|
+
})
|
70
|
+
|
71
|
+
test('generated Options', () => {
|
72
|
+
render(<DefaultDropdownKit/>)
|
73
|
+
|
74
|
+
const kit = screen.getByTestId(testId)
|
75
|
+
const option = kit.querySelector('.pb_dropdown_option_list')
|
76
|
+
expect(option).toBeInTheDocument()
|
77
|
+
})
|
78
|
+
|
79
|
+
test('generated customDisplay for trigger', () => {
|
80
|
+
render (
|
81
|
+
<Dropdown
|
82
|
+
data={{ testid: testId }}
|
83
|
+
options={options}
|
84
|
+
>
|
85
|
+
<Dropdown.Trigger
|
86
|
+
customDisplay={<Icon icon="flag" />}
|
87
|
+
/>
|
88
|
+
{options.map((option) => (
|
89
|
+
<Dropdown.Option key={option.id}
|
90
|
+
option={option}
|
91
|
+
/>
|
92
|
+
))}
|
93
|
+
</Dropdown>
|
94
|
+
)
|
95
|
+
|
96
|
+
const kit = screen.getByTestId(testId)
|
97
|
+
const trigger = kit.querySelector('.pb_dropdown_trigger')
|
98
|
+
const customDisplay = trigger.querySelector('.fa-flag.pb_icon_kit.fa-fw')
|
99
|
+
expect(customDisplay).toBeInTheDocument()
|
17
100
|
})
|
101
|
+
|
102
|
+
test('generated placeholder prop', () => {
|
103
|
+
render (
|
104
|
+
<Dropdown
|
105
|
+
data={{ testid: testId }}
|
106
|
+
options={options}
|
107
|
+
>
|
108
|
+
<Dropdown.Trigger
|
109
|
+
placeholder="Select a country"
|
110
|
+
/>
|
111
|
+
{options.map((option) => (
|
112
|
+
<Dropdown.Option key={option.id}
|
113
|
+
option={option}
|
114
|
+
/>
|
115
|
+
))}
|
116
|
+
</Dropdown>
|
117
|
+
)
|
118
|
+
|
119
|
+
const kit = screen.getByTestId(testId)
|
120
|
+
const trigger = kit.querySelector('.pb_dropdown_trigger')
|
121
|
+
expect(trigger).toHaveTextContent('Select a country')
|
122
|
+
|
123
|
+
})
|
124
|
+
|
125
|
+
test('generated label prop', () => {
|
126
|
+
render (
|
127
|
+
<Dropdown
|
128
|
+
data={{ testid: testId }}
|
129
|
+
label="Countries"
|
130
|
+
options={options}
|
131
|
+
>
|
132
|
+
{options.map((option) => (
|
133
|
+
<Dropdown.Option key={option.id}
|
134
|
+
option={option}
|
135
|
+
/>
|
136
|
+
))}
|
137
|
+
</Dropdown>
|
138
|
+
)
|
139
|
+
|
140
|
+
const kit = screen.getByTestId(testId)
|
141
|
+
const label = kit.querySelector('.pb_caption_kit_md')
|
142
|
+
expect(label).toHaveTextContent('Countries')
|
143
|
+
})
|
144
|
+
|
145
|
+
test('generated custom option', () => {
|
146
|
+
render (
|
147
|
+
<Dropdown
|
148
|
+
data={{ testid: testId }}
|
149
|
+
options={options}
|
150
|
+
>
|
151
|
+
{options.map((option) => (
|
152
|
+
<Dropdown.Option key={option.id}
|
153
|
+
option={option}
|
154
|
+
>
|
155
|
+
<Icon icon={option.icon} />
|
156
|
+
</Dropdown.Option>
|
157
|
+
))}
|
158
|
+
</Dropdown>
|
159
|
+
)
|
160
|
+
|
161
|
+
const kit = screen.getByTestId(testId)
|
162
|
+
const customOption = kit.querySelector('.pb_icon_kit_emoji')
|
163
|
+
expect(customOption).toBeInTheDocument()
|
164
|
+
})
|
165
|
+
|
166
|
+
test('generated custom Trigger', () => {
|
167
|
+
render (
|
168
|
+
<Dropdown
|
169
|
+
data={{ testid: testId }}
|
170
|
+
options={options}
|
171
|
+
>
|
172
|
+
<Dropdown.Trigger>
|
173
|
+
<Icon icon="home" />
|
174
|
+
</Dropdown.Trigger>
|
175
|
+
{options.map((option) => (
|
176
|
+
<Dropdown.Option key={option.id}
|
177
|
+
option={option}
|
178
|
+
/>
|
179
|
+
))}
|
180
|
+
</Dropdown>
|
181
|
+
)
|
182
|
+
|
183
|
+
const kit = screen.getByTestId(testId)
|
184
|
+
const trigger = kit.querySelector('.pb_dropdown_trigger')
|
185
|
+
const customTrigger = trigger.querySelector('.fa-home.pb_icon_kit.fa-fw')
|
186
|
+
expect(customTrigger).toBeInTheDocument()
|
187
|
+
})
|
188
|
+
|
189
|
+
test('selected option on click', () => {
|
190
|
+
render (
|
191
|
+
<Dropdown
|
192
|
+
data={{ testid: testId }}
|
193
|
+
options={options}
|
194
|
+
>
|
195
|
+
{options.map((option) => (
|
196
|
+
<Dropdown.Option key={option.id}
|
197
|
+
option={option}
|
198
|
+
/>
|
199
|
+
))}
|
200
|
+
</Dropdown>
|
201
|
+
)
|
202
|
+
|
203
|
+
const kit = screen.getByTestId(testId)
|
204
|
+
const option = kit.querySelector('.pb_dropdown_option_list')
|
205
|
+
option.click()
|
206
|
+
expect(option).toHaveClass('pb_dropdown_option_selected p_xs')
|
207
|
+
})
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import {useState} from 'react';
|
2
2
|
|
3
3
|
|
4
|
-
const useDropdown = (initial=true) => {
|
4
|
+
const useDropdown = (initial= true) => {
|
5
5
|
|
6
6
|
const [isDropDownClosed, setIsDropDownClosed] = useState(initial);
|
7
7
|
|
8
|
-
const toggleDropdown = () => setIsDropDownClosed(!
|
8
|
+
const toggleDropdown = () => setIsDropDownClosed((prev) => !prev);
|
9
9
|
|
10
10
|
return [
|
11
11
|
isDropDownClosed,
|
@@ -6,13 +6,13 @@ export const useHandleOnKeyDown = () => {
|
|
6
6
|
|
7
7
|
const {
|
8
8
|
autocomplete,
|
9
|
-
focusedOptionIndex,
|
10
9
|
filteredOptions,
|
11
|
-
|
12
|
-
handleOptionClick,
|
13
|
-
setIsDropDownClosed,
|
10
|
+
focusedOptionIndex,
|
14
11
|
handleBackspace,
|
12
|
+
handleOptionClick,
|
15
13
|
selected,
|
14
|
+
setFocusedOptionIndex,
|
15
|
+
setIsDropDownClosed,
|
16
16
|
}= useContext(DropdownContext)
|
17
17
|
|
18
18
|
return (e: React.KeyboardEvent) => {
|
@@ -17,8 +17,9 @@ import Body from "../../pb_body/_body";
|
|
17
17
|
|
18
18
|
type DropdownContainerProps = {
|
19
19
|
aria?: { [key: string]: string };
|
20
|
-
className?: string;
|
21
20
|
children?: React.ReactChild[] | React.ReactChild;
|
21
|
+
className?: string;
|
22
|
+
dark?: boolean;
|
22
23
|
data?: { [key: string]: string };
|
23
24
|
htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
|
24
25
|
id?: string;
|
@@ -28,8 +29,9 @@ type DropdownContainerProps = {
|
|
28
29
|
const DropdownContainer = (props: DropdownContainerProps) => {
|
29
30
|
const {
|
30
31
|
aria = {},
|
31
|
-
className,
|
32
32
|
children,
|
33
|
+
className,
|
34
|
+
dark = false,
|
33
35
|
data = {},
|
34
36
|
htmlOptions = {},
|
35
37
|
id,
|
@@ -37,12 +39,14 @@ const DropdownContainer = (props: DropdownContainerProps) => {
|
|
37
39
|
} = props;
|
38
40
|
|
39
41
|
const {
|
40
|
-
|
41
|
-
handleChange,
|
42
|
-
filterItem,
|
42
|
+
dropdownContainerRef,
|
43
43
|
filteredOptions,
|
44
|
+
filterItem,
|
45
|
+
handleChange,
|
44
46
|
inputRef,
|
47
|
+
isDropDownClosed,
|
45
48
|
setFocusedOptionIndex,
|
49
|
+
triggerRef
|
46
50
|
} = useContext(DropdownContext);
|
47
51
|
|
48
52
|
const ariaProps = buildAriaProps(aria);
|
@@ -62,9 +66,12 @@ const DropdownContainer = (props: DropdownContainerProps) => {
|
|
62
66
|
className={classes}
|
63
67
|
id={id}
|
64
68
|
onMouseEnter={() => setFocusedOptionIndex(-1)}
|
69
|
+
ref={dropdownContainerRef}
|
70
|
+
style={triggerRef ? {} : { position: "absolute"}}
|
65
71
|
>
|
66
72
|
{searchbar && (
|
67
|
-
<TextInput
|
73
|
+
<TextInput dark={dark}
|
74
|
+
paddingTop="xs"
|
68
75
|
paddingX="xs"
|
69
76
|
>
|
70
77
|
<input
|
@@ -75,9 +82,10 @@ const DropdownContainer = (props: DropdownContainerProps) => {
|
|
75
82
|
/>
|
76
83
|
</TextInput>
|
77
84
|
)}
|
78
|
-
<List>
|
85
|
+
<List dark={dark}>
|
86
|
+
{
|
79
87
|
filteredOptions?.length === 0 ? (
|
80
|
-
<ListItem
|
88
|
+
<ListItem dark={dark}
|
81
89
|
display="flex"
|
82
90
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
83
91
|
// @ts-ignore
|
@@ -85,6 +93,7 @@ const DropdownContainer = (props: DropdownContainerProps) => {
|
|
85
93
|
padding="xs"
|
86
94
|
>
|
87
95
|
<Body color="light"
|
96
|
+
dark={dark}
|
88
97
|
text="no option"
|
89
98
|
/>
|
90
99
|
</ListItem>
|
@@ -17,35 +17,37 @@ import { GenericObject } from "../../types";
|
|
17
17
|
|
18
18
|
type DropdownOptionProps = {
|
19
19
|
aria?: { [key: string]: string };
|
20
|
-
className?: string;
|
21
20
|
children?: React.ReactChild[] | React.ReactChild;
|
21
|
+
className?: string;
|
22
|
+
dark?: boolean;
|
22
23
|
data?: { [key: string]: string };
|
23
24
|
htmlOptions?: { [key: string]: string | number | boolean | (() => void) };
|
24
25
|
id?: string;
|
25
|
-
option?: GenericObject;
|
26
26
|
key?: string;
|
27
|
+
option?: GenericObject;
|
27
28
|
padding?: string;
|
28
29
|
} & GlobalProps;
|
29
30
|
|
30
31
|
const DropdownOption = (props: DropdownOptionProps) => {
|
31
32
|
const {
|
32
33
|
aria = {},
|
33
|
-
className,
|
34
34
|
children,
|
35
|
+
className,
|
36
|
+
dark = false,
|
35
37
|
data = {},
|
36
38
|
htmlOptions = {},
|
37
39
|
id,
|
38
|
-
option,
|
39
40
|
key,
|
41
|
+
option,
|
40
42
|
padding = "xs",
|
41
43
|
} = props;
|
42
44
|
|
43
45
|
const {
|
44
|
-
handleOptionClick,
|
45
|
-
selected,
|
46
|
-
filterItem,
|
47
46
|
filteredOptions,
|
47
|
+
filterItem,
|
48
48
|
focusedOptionIndex,
|
49
|
+
handleOptionClick,
|
50
|
+
selected,
|
49
51
|
} = useContext(DropdownContext);
|
50
52
|
|
51
53
|
const isItemMatchingFilter = (option: GenericObject) =>
|
@@ -57,20 +59,22 @@ const DropdownOption = (props: DropdownOptionProps) => {
|
|
57
59
|
const isFocused =
|
58
60
|
focusedOptionIndex >= 0 &&
|
59
61
|
filteredOptions[focusedOptionIndex].label === option.label;
|
60
|
-
const focusedClass = isFocused && "
|
62
|
+
const focusedClass = isFocused && "focused";
|
61
63
|
|
62
64
|
const selectedClass = `${
|
63
65
|
selected.label === option.label
|
64
|
-
? "
|
65
|
-
: "
|
66
|
+
? "selected"
|
67
|
+
: "list"
|
66
68
|
}`;
|
67
69
|
const ariaProps = buildAriaProps(aria);
|
68
70
|
const dataProps = buildDataProps(data);
|
69
71
|
const htmlProps = buildHtmlProps(htmlOptions);
|
70
72
|
const classes = classnames(
|
71
|
-
buildCss(
|
72
|
-
|
73
|
-
|
73
|
+
buildCss(
|
74
|
+
"pb_dropdown_option",
|
75
|
+
selectedClass,
|
76
|
+
focusedClass,
|
77
|
+
),
|
74
78
|
globalProps(props, {padding}),
|
75
79
|
className
|
76
80
|
);
|
@@ -87,18 +91,24 @@ const DropdownOption = (props: DropdownOptionProps) => {
|
|
87
91
|
>
|
88
92
|
<ListItem
|
89
93
|
cursor="pointer"
|
94
|
+
dark={dark}
|
90
95
|
data-name={option.value}
|
91
96
|
key={option.label}
|
92
97
|
padding="none"
|
93
98
|
>
|
94
99
|
<Flex
|
95
100
|
align="center"
|
96
|
-
className="
|
101
|
+
className="dropdown_option_wrapper"
|
97
102
|
justify="between"
|
98
103
|
paddingX="sm"
|
99
104
|
paddingY="xxs"
|
100
105
|
>
|
101
|
-
{children ?
|
106
|
+
{children ?
|
107
|
+
children :
|
108
|
+
<Body dark={dark}
|
109
|
+
text={option.label}
|
110
|
+
/>
|
111
|
+
}
|
102
112
|
</Flex>
|
103
113
|
</ListItem>
|
104
114
|
</div>
|
@@ -21,6 +21,7 @@ type DropdownTriggerProps = {
|
|
21
21
|
children?: React.ReactChild[] | React.ReactChild;
|
22
22
|
className?: string;
|
23
23
|
customDisplay?: React.ReactChild[] | React.ReactChild;
|
24
|
+
dark?: boolean;
|
24
25
|
data?: { [key: string]: string };
|
25
26
|
htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
|
26
27
|
id?: string;
|
@@ -30,9 +31,10 @@ type DropdownTriggerProps = {
|
|
30
31
|
const DropdownTrigger = (props: DropdownTriggerProps) => {
|
31
32
|
const {
|
32
33
|
aria = {},
|
33
|
-
className,
|
34
34
|
children,
|
35
|
+
className,
|
35
36
|
customDisplay,
|
37
|
+
dark = false,
|
36
38
|
data = {},
|
37
39
|
htmlOptions = {},
|
38
40
|
id,
|
@@ -41,15 +43,17 @@ const DropdownTrigger = (props: DropdownTriggerProps) => {
|
|
41
43
|
|
42
44
|
const {
|
43
45
|
autocomplete,
|
44
|
-
handleWrapperClick,
|
45
|
-
selected,
|
46
46
|
filterItem,
|
47
47
|
handleChange,
|
48
|
-
|
49
|
-
isDropDownClosed,
|
48
|
+
handleWrapperClick,
|
50
49
|
inputRef,
|
50
|
+
inputWrapperRef,
|
51
|
+
isDropDownClosed,
|
51
52
|
isInputFocused,
|
53
|
+
selected,
|
52
54
|
setIsInputFocused,
|
55
|
+
toggleDropdown,
|
56
|
+
triggerRef,
|
53
57
|
} = useContext(DropdownContext);
|
54
58
|
|
55
59
|
const handleKeyDown = useHandleOnKeyDown();
|
@@ -63,9 +67,11 @@ const DropdownTrigger = (props: DropdownTriggerProps) => {
|
|
63
67
|
className
|
64
68
|
);
|
65
69
|
|
66
|
-
const triggerWrapperClasses =
|
67
|
-
|
68
|
-
|
70
|
+
const triggerWrapperClasses = buildCss(
|
71
|
+
"dropdown_trigger_wrapper",
|
72
|
+
isInputFocused && "focus",
|
73
|
+
!autocomplete && "select_only"
|
74
|
+
);
|
69
75
|
|
70
76
|
const customDisplayPlaceholder = selected.label ? (
|
71
77
|
<b>{selected.label}</b>
|
@@ -92,79 +98,91 @@ const DropdownTrigger = (props: DropdownTriggerProps) => {
|
|
92
98
|
className={classes}
|
93
99
|
id={id}
|
94
100
|
>
|
95
|
-
{
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
tabIndex: "0",
|
115
|
-
}}
|
116
|
-
justify="between"
|
117
|
-
paddingX="sm"
|
118
|
-
paddingY="xs"
|
119
|
-
>
|
120
|
-
<FlexItem>
|
121
|
-
<Flex align="center">
|
122
|
-
{customDisplay ? (
|
123
|
-
<Flex align="center">
|
124
|
-
{customDisplay}
|
125
|
-
<Body paddingLeft={`${selected.label ? "xs" : "none"}`}>
|
126
|
-
{customDisplayPlaceholder}
|
127
|
-
</Body>
|
128
|
-
</Flex>
|
129
|
-
) : (
|
130
|
-
<Body text={defaultDisplayPlaceholder} />
|
131
|
-
)}
|
132
|
-
{autocomplete && (
|
133
|
-
<input
|
134
|
-
className="dropdown_input"
|
135
|
-
onChange={handleChange}
|
136
|
-
onClick={() => toggleDropdown()}
|
137
|
-
onFocus={() => setIsInputFocused(true)}
|
138
|
-
onKeyDown={handleKeyDown}
|
139
|
-
placeholder={
|
140
|
-
selected.label
|
141
|
-
? ""
|
142
|
-
: placeholder
|
143
|
-
? placeholder
|
144
|
-
: "Select..."
|
145
|
-
}
|
146
|
-
ref={inputRef}
|
147
|
-
value={filterItem}
|
148
|
-
/>
|
149
|
-
)}
|
150
|
-
</Flex>
|
151
|
-
</FlexItem>
|
152
|
-
<Body
|
153
|
-
display="flex"
|
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"}`}
|
154
120
|
htmlOptions={{
|
155
|
-
onClick: (
|
121
|
+
onClick: () => handleWrapperClick(),
|
122
|
+
onKeyDown: handleKeyDown,
|
123
|
+
tabIndex: "0",
|
124
|
+
ref:inputWrapperRef
|
156
125
|
}}
|
157
|
-
|
126
|
+
justify="between"
|
127
|
+
paddingX="sm"
|
128
|
+
paddingY="xs"
|
158
129
|
>
|
159
|
-
<
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
130
|
+
<FlexItem>
|
131
|
+
<Flex align="center">
|
132
|
+
{customDisplay ? (
|
133
|
+
<Flex align="center">
|
134
|
+
{customDisplay}
|
135
|
+
<Body dark={dark}
|
136
|
+
paddingLeft={`${selected.label ? "xs" : "none"}`}
|
137
|
+
>
|
138
|
+
{customDisplayPlaceholder}
|
139
|
+
</Body>
|
140
|
+
</Flex>
|
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"
|
179
|
+
/>
|
180
|
+
</Body>
|
181
|
+
</Flex>
|
182
|
+
</>
|
183
|
+
)
|
184
|
+
)
|
185
|
+
}
|
168
186
|
</div>
|
169
187
|
);
|
170
188
|
};
|