playbook_ui 13.25.0.pre.alpha.barchartfix2766 → 13.26.0
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_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_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/dist/playbook-rails.js +3 -3
- data/lib/playbook/version.rb +1 -1
- metadata +21 -5
@@ -0,0 +1 @@
|
|
1
|
+
The Dropdown kit accepts an `options` array and renders each object from that array as a selectable option within a dropdown container. `options` is a required prop and must be an array of objects. Each object can contain as many key/value pairs as needed but MUST contain 'label' and 'value' as the only required items within each object.
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
import { Dropdown } from '../..'
|
3
|
+
|
4
|
+
const DropdownSubcomponentStructure = (props) => {
|
5
|
+
|
6
|
+
|
7
|
+
const options = [
|
8
|
+
{
|
9
|
+
label: "United States",
|
10
|
+
value: "United States",
|
11
|
+
},
|
12
|
+
{
|
13
|
+
label: "Canada",
|
14
|
+
value: "Canada",
|
15
|
+
},
|
16
|
+
{
|
17
|
+
label: "Pakistan",
|
18
|
+
value: "Pakistan",
|
19
|
+
}
|
20
|
+
];
|
21
|
+
|
22
|
+
|
23
|
+
return (
|
24
|
+
<div>
|
25
|
+
<Dropdown
|
26
|
+
options={options}
|
27
|
+
{...props}
|
28
|
+
>
|
29
|
+
<Dropdown.Trigger/>
|
30
|
+
<Dropdown.Container>
|
31
|
+
{options.map((option) => (
|
32
|
+
<Dropdown.Option key={option.id}
|
33
|
+
option={option}
|
34
|
+
/>
|
35
|
+
))}
|
36
|
+
</Dropdown.Container>
|
37
|
+
</Dropdown>
|
38
|
+
</div>
|
39
|
+
)
|
40
|
+
}
|
41
|
+
|
42
|
+
export default DropdownSubcomponentStructure
|
@@ -0,0 +1,7 @@
|
|
1
|
+
The dropdown comes with the following subcomponents that can be used to achieve various levels of customization:
|
2
|
+
|
3
|
+
`Dropdown. Trigger`
|
4
|
+
`Dropdown.Container`
|
5
|
+
`Dropdown.Option`
|
6
|
+
|
7
|
+
See the code snippet below for a visual on how to use the kit with subcomponents. Each subcomponent allows for GlobalProps in addition to any subcomponent specfic props.
|
@@ -1,9 +1,7 @@
|
|
1
|
-
import React
|
1
|
+
import React from 'react'
|
2
2
|
import { Dropdown, User, Badge, FlexItem } from '../..'
|
3
3
|
|
4
4
|
const DropdownWithAutocomplete = (props) => {
|
5
|
-
// eslint-disable-next-line no-unused-vars
|
6
|
-
const [selectedOption, setSelectedOption] = useState();
|
7
5
|
|
8
6
|
const options = [
|
9
7
|
{
|
@@ -44,7 +42,6 @@ const DropdownWithAutocomplete = (props) => {
|
|
44
42
|
return (
|
45
43
|
<div>
|
46
44
|
<Dropdown autocomplete
|
47
|
-
onSelect={(selectedItem) => setSelectedOption(selectedItem)}
|
48
45
|
options={options}
|
49
46
|
{...props}
|
50
47
|
>
|
data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_autocomplete_and_custom_display.jsx
CHANGED
@@ -2,7 +2,6 @@ import React, { useState } from 'react'
|
|
2
2
|
import { Dropdown, User, Badge, FlexItem, Avatar } from '../..'
|
3
3
|
|
4
4
|
const DropdownWithAutocompleteAndCustomDisplay = (props) => {
|
5
|
-
// eslint-disable-next-line no-unused-vars
|
6
5
|
const [selectedOption, setSelectedOption] = useState();
|
7
6
|
|
8
7
|
const options = [
|
@@ -1,3 +1,5 @@
|
|
1
1
|
The `customDisplay` prop can be used to customize the display of the selected item by allowing devs to pass in a component that will be rendered to the left of the default text-based display. In this example the Avatar kit is being used.
|
2
2
|
|
3
|
-
The `placeholder` prop can also be used to customize the placeholder text for the default Trigger.
|
3
|
+
The `placeholder` prop can also be used to customize the placeholder text for the default Trigger.
|
4
|
+
|
5
|
+
The `onSelect` prop is a function that gives the dev one argument: the selected option. In this example we are using the `onSelect` to set a state with the selected option and using it to customize the `customDisplay`.
|
@@ -1,9 +1,7 @@
|
|
1
|
-
import React
|
1
|
+
import React from 'react'
|
2
2
|
import { Dropdown, Icon, Body, FlexItem, Flex } from '../..'
|
3
3
|
|
4
4
|
const DropdownWithCustomOptions = (props) => {
|
5
|
-
// eslint-disable-next-line no-unused-vars
|
6
|
-
const [selectedOption, setSelectedOption] = useState();
|
7
5
|
|
8
6
|
const options = [
|
9
7
|
{
|
@@ -33,7 +31,6 @@ const DropdownWithCustomOptions = (props) => {
|
|
33
31
|
return (
|
34
32
|
<div>
|
35
33
|
<Dropdown
|
36
|
-
onSelect={(selectedItem) => setSelectedOption(selectedItem)}
|
37
34
|
options={options}
|
38
35
|
{...props}
|
39
36
|
>
|
@@ -1 +1 @@
|
|
1
|
-
The Dropdown also allows for custom options that can be passed in as children to the `Dropdown.Option` subcomponent. If no children are passed
|
1
|
+
The Dropdown also allows for custom options that can be passed in as children to the `Dropdown.Option` subcomponent. If no children are passed to `Dropdown.Option`, the kit will render each option as text within a Body kit by default.
|
@@ -1,9 +1,7 @@
|
|
1
|
-
import React
|
1
|
+
import React from 'react'
|
2
2
|
import { Dropdown } from '../..'
|
3
3
|
|
4
4
|
const DropdownWithCustomPadding = (props) => {
|
5
|
-
// eslint-disable-next-line no-unused-vars
|
6
|
-
const [selectedOption, setSelectedOption] = useState();
|
7
5
|
|
8
6
|
const options = [
|
9
7
|
{
|
@@ -33,7 +31,6 @@ const [selectedOption, setSelectedOption] = useState();
|
|
33
31
|
return (
|
34
32
|
<div>
|
35
33
|
<Dropdown
|
36
|
-
onSelect={(selectedItem) => setSelectedOption(selectedItem)}
|
37
34
|
options={options}
|
38
35
|
{...props}
|
39
36
|
>
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
import { Dropdown, useDropdown, Button } from '../../'
|
3
|
+
|
4
|
+
const DropdownWithExternalControl = (props) => {
|
5
|
+
const [isDropDownClosed, setIsDropdownClosed] = useDropdown(true);
|
6
|
+
|
7
|
+
const options = [
|
8
|
+
{
|
9
|
+
label: "United States",
|
10
|
+
value: "United States",
|
11
|
+
areaCode: "+1",
|
12
|
+
icon: "🇺🇸",
|
13
|
+
id: "United-states"
|
14
|
+
},
|
15
|
+
{
|
16
|
+
label: "Canada",
|
17
|
+
value: "Canada",
|
18
|
+
areaCode: "+1",
|
19
|
+
icon: "🇨🇦",
|
20
|
+
id: "canada"
|
21
|
+
},
|
22
|
+
{
|
23
|
+
label: "Pakistan",
|
24
|
+
value: "Pakistan",
|
25
|
+
areaCode: "+92",
|
26
|
+
icon: "🇵🇰",
|
27
|
+
id: "pakistan"
|
28
|
+
}
|
29
|
+
];
|
30
|
+
|
31
|
+
return (
|
32
|
+
<div>
|
33
|
+
<Button
|
34
|
+
data={{dropdown:'pb-dropdown-trigger'}}
|
35
|
+
marginBottom='sm'
|
36
|
+
onClick={() => setIsDropdownClosed(!isDropDownClosed)}
|
37
|
+
padding="none"
|
38
|
+
tabIndex={0}
|
39
|
+
variant="link"
|
40
|
+
>
|
41
|
+
{isDropDownClosed ? "Open Dropdown" : "Close Dropdown"}
|
42
|
+
</Button>
|
43
|
+
|
44
|
+
<Dropdown
|
45
|
+
isClosed={isDropDownClosed}
|
46
|
+
options={options}
|
47
|
+
{...props}
|
48
|
+
>
|
49
|
+
{options.map((option) => (
|
50
|
+
<Dropdown.Option key={option.id}
|
51
|
+
option={option}
|
52
|
+
/>
|
53
|
+
))}
|
54
|
+
</Dropdown>
|
55
|
+
</div>
|
56
|
+
)
|
57
|
+
}
|
58
|
+
|
59
|
+
export default DropdownWithExternalControl
|
@@ -0,0 +1,72 @@
|
|
1
|
+
import React, { useRef } from 'react'
|
2
|
+
import { Dropdown, useDropdown, CircleIconButton, Icon, Body, FlexItem, Flex } from '../..'
|
3
|
+
|
4
|
+
const DropdownWithHook = (props) => {
|
5
|
+
const [isDropDownClosed, setIsDropdownClosed] = useDropdown(true);
|
6
|
+
const buttonRef = useRef(null);
|
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: "Canada",
|
18
|
+
value: "Canada",
|
19
|
+
areaCode: "+1",
|
20
|
+
icon: "🇨🇦",
|
21
|
+
id: "canada"
|
22
|
+
},
|
23
|
+
{
|
24
|
+
label: "Pakistan",
|
25
|
+
value: "Pakistan",
|
26
|
+
areaCode: "+92",
|
27
|
+
icon: "🇵🇰",
|
28
|
+
id: "pakistan"
|
29
|
+
}
|
30
|
+
];
|
31
|
+
|
32
|
+
return (
|
33
|
+
<div>
|
34
|
+
<CircleIconButton
|
35
|
+
htmlOptions={{ref: buttonRef}}
|
36
|
+
icon={"flag"}
|
37
|
+
onClick={() => setIsDropdownClosed(!isDropDownClosed)}
|
38
|
+
variant="secondary"
|
39
|
+
/>
|
40
|
+
<Dropdown
|
41
|
+
isClosed={isDropDownClosed}
|
42
|
+
options={options}
|
43
|
+
triggerRef={buttonRef}
|
44
|
+
{...props}
|
45
|
+
>
|
46
|
+
{options.map((option) => (
|
47
|
+
<Dropdown.Option key={option.id}
|
48
|
+
option={option}
|
49
|
+
>
|
50
|
+
<>
|
51
|
+
<FlexItem>
|
52
|
+
<Flex paddingRight='md'>
|
53
|
+
<Icon icon={option.icon}
|
54
|
+
paddingRight="xs"
|
55
|
+
/>
|
56
|
+
<Body text={option.label} />
|
57
|
+
</Flex>
|
58
|
+
</FlexItem>
|
59
|
+
<FlexItem>
|
60
|
+
<Body color="light"
|
61
|
+
text={option.areaCode}
|
62
|
+
/>
|
63
|
+
</FlexItem>
|
64
|
+
</>
|
65
|
+
</Dropdown.Option>
|
66
|
+
))}
|
67
|
+
</Dropdown>
|
68
|
+
</div>
|
69
|
+
)
|
70
|
+
}
|
71
|
+
|
72
|
+
export default DropdownWithHook
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
import { Dropdown } from '../..'
|
3
|
+
|
4
|
+
const DropdownDefault = (props) => {
|
5
|
+
|
6
|
+
const options = [
|
7
|
+
{
|
8
|
+
label: "United States",
|
9
|
+
value: "United States",
|
10
|
+
},
|
11
|
+
{
|
12
|
+
label: "Canada",
|
13
|
+
value: "Canada",
|
14
|
+
},
|
15
|
+
{
|
16
|
+
label: "Pakistan",
|
17
|
+
value: "Pakistan",
|
18
|
+
}
|
19
|
+
];
|
20
|
+
|
21
|
+
|
22
|
+
return (
|
23
|
+
<div>
|
24
|
+
<Dropdown
|
25
|
+
label="Select a Country"
|
26
|
+
options={options}
|
27
|
+
{...props}
|
28
|
+
>
|
29
|
+
{options.map((option) => (
|
30
|
+
<Dropdown.Option key={option.id}
|
31
|
+
option={option}
|
32
|
+
/>
|
33
|
+
))}
|
34
|
+
</Dropdown>
|
35
|
+
</div>
|
36
|
+
)
|
37
|
+
}
|
38
|
+
|
39
|
+
export default DropdownDefault
|
@@ -0,0 +1 @@
|
|
1
|
+
The optional `label` prop takes a string value that if present will render that string as the label for the Dropdown.
|
@@ -3,10 +3,14 @@ examples:
|
|
3
3
|
|
4
4
|
react:
|
5
5
|
- dropdown_default: Default
|
6
|
+
- dropdown_subcomponent_structure: Subcomponent Structure
|
7
|
+
- dropdown_with_label: With Label
|
6
8
|
- dropdown_with_custom_options: Custom Options
|
7
9
|
- dropdown_with_custom_display: Custom Display
|
8
10
|
- dropdown_with_custom_trigger: Custom Trigger
|
9
|
-
- dropdown_with_autocomplete: Autocomplete
|
10
|
-
- dropdown_with_autocomplete_and_custom_display: Autocomplete with Custom Display
|
11
11
|
- dropdown_with_custom_padding: Custom Padding for Dropdown Options
|
12
|
+
# - dropdown_with_autocomplete: Autocomplete
|
13
|
+
# - dropdown_with_autocomplete_and_custom_display: Autocomplete with Custom Display
|
14
|
+
# - dropdown_with_external_control: useDropdown Hook
|
15
|
+
# - dropdown_with_hook: useDropdown Hook with Any Trigger
|
12
16
|
|
@@ -4,4 +4,8 @@ export { default as DropdownWithCustomOptions } from './_dropdown_with_custom_op
|
|
4
4
|
export { default as DropdownWithCustomTrigger } from './_dropdown_with_custom_trigger.jsx'
|
5
5
|
export { default as DropdownWithAutocomplete } from './_dropdown_with_autocomplete.jsx'
|
6
6
|
export { default as DropdownWithAutocompleteAndCustomDisplay } from './_dropdown_with_autocomplete_and_custom_display.jsx'
|
7
|
-
export { default as DropdownWithCustomPadding } from './_dropdown_with_custom_padding.jsx'
|
7
|
+
export { default as DropdownWithCustomPadding } from './_dropdown_with_custom_padding.jsx'
|
8
|
+
export { default as DropdownWithLabel } from './_dropdown_with_label.jsx'
|
9
|
+
export { default as DropdownWithExternalControl } from './_dropdown_with_external_control.jsx'
|
10
|
+
export { default as DropdownWithHook } from './_dropdown_with_hook.jsx'
|
11
|
+
export { default as DropdownSubcomponentStructure } from './_dropdown_subcomponent_structure.jsx'
|
@@ -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) => {
|