playbook_ui 13.24.0.pre.alpha.PBNTR261NewKitDropdown2681 → 13.24.0.pre.alpha.PLAY998backgroundkitremoveemptyinlinline2666

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,53 +0,0 @@
1
- import React, { useContext } from "react";
2
- import DropdownContext from "../context";
3
-
4
-
5
- export const useHandleOnKeyDown = () => {
6
-
7
- const {
8
- focusedOptionIndex,
9
- filteredOptions,
10
- setFocusedOptionIndex,
11
- handleOptionClick,
12
- setIsDropDownClosed,
13
- handleBackspace,
14
- selected
15
- }= useContext(DropdownContext)
16
-
17
- return (e: React.KeyboardEvent) => {
18
- switch (e.key) {
19
- case "Backspace":
20
- case "Delete":
21
- handleBackspace();
22
- break;
23
- case "ArrowDown": {
24
- e.preventDefault();
25
- setIsDropDownClosed(false);
26
- const nextIndex = (focusedOptionIndex + 1) % filteredOptions.length;
27
- setFocusedOptionIndex(nextIndex);
28
- break;
29
- }
30
- case "ArrowUp": {
31
- e.preventDefault();
32
- const nextIndexUp =
33
- (focusedOptionIndex - 1 + filteredOptions.length) %
34
- filteredOptions.length;
35
- setFocusedOptionIndex(nextIndexUp);
36
- break;
37
- }
38
- case "Enter":
39
- if (focusedOptionIndex !== -1) {
40
- e.preventDefault();
41
- handleOptionClick(filteredOptions[focusedOptionIndex]);
42
- setFocusedOptionIndex(-1)
43
- }
44
- break;
45
- default:
46
- if (selected && selected.label) {
47
- e.preventDefault();
48
- handleBackspace();
49
- }
50
- break;
51
- }
52
- }
53
- };
@@ -1,95 +0,0 @@
1
- import React, { useContext } from "react";
2
- import classnames from "classnames";
3
- import {
4
- buildAriaProps,
5
- buildCss,
6
- buildDataProps,
7
- } from "../../utilities/props";
8
- import { globalProps } from "../../utilities/globalProps";
9
-
10
- import DropdownContext from "../context";
11
-
12
- import List from "../../pb_list/_list";
13
- import ListItem from "../../pb_list/_list_item";
14
- import TextInput from "../../pb_text_input/_text_input";
15
- import Body from "../../pb_body/_body";
16
-
17
- type DropdownContainerProps = {
18
- aria?: { [key: string]: string };
19
- className?: string;
20
- children?: React.ReactChild[] | React.ReactChild;
21
- data?: { [key: string]: string };
22
- id?: string;
23
- searchbar?: boolean;
24
- };
25
-
26
- const DropdownContainer = (props: DropdownContainerProps) => {
27
- const {
28
- aria = {},
29
- className,
30
- children,
31
- data = {},
32
- id,
33
- searchbar = false,
34
- } = props;
35
-
36
- const {
37
- isDropDownClosed,
38
- handleChange,
39
- filterItem,
40
- filteredOptions,
41
- inputRef,
42
- setFocusedOptionIndex,
43
- } = useContext(DropdownContext);
44
-
45
- const ariaProps = buildAriaProps(aria);
46
- const dataProps = buildDataProps(data);
47
- const classes = classnames(
48
- buildCss("pb_dropdown_container"),
49
- `${isDropDownClosed ? "close" : "open"}`,
50
- globalProps(props),
51
- className
52
- );
53
-
54
- return (
55
- <div {...ariaProps}
56
- {...dataProps}
57
- className={classes}
58
- id={id}
59
- onMouseEnter={() => setFocusedOptionIndex(-1)}
60
- >
61
- {searchbar && (
62
- <TextInput paddingTop="xs"
63
- paddingX="xs"
64
- >
65
- <input
66
- onChange={handleChange}
67
- placeholder="Select..."
68
- ref={inputRef}
69
- value={filterItem}
70
- />
71
- </TextInput>
72
- )}
73
- <List>{
74
- filteredOptions?.length === 0 ? (
75
- <ListItem
76
- display="flex"
77
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
78
- // @ts-ignore
79
- justifyContent="center"
80
- padding="xs"
81
- >
82
- <Body color="light"
83
- text="no option"
84
- />
85
- </ListItem>
86
- ): (
87
- children
88
- )
89
- }
90
- </List>
91
- </div>
92
- );
93
- };
94
-
95
- export default DropdownContainer;
@@ -1,91 +0,0 @@
1
- import React, { useContext } from "react";
2
- import classnames from "classnames";
3
- import {
4
- buildAriaProps,
5
- buildCss,
6
- buildDataProps,
7
- } from "../../utilities/props";
8
- import { globalProps } from "../../utilities/globalProps";
9
-
10
- import DropdownContext from "../context";
11
-
12
- import Flex from "../../pb_flex/_flex";
13
- import Body from "../../pb_body/_body";
14
- import ListItem from "../../pb_list/_list_item";
15
- import { GenericObject } from "../../types";
16
-
17
- type DropdownOptionProps = {
18
- aria?: { [key: string]: string };
19
- className?: string;
20
- children?: React.ReactChild[] | React.ReactChild;
21
- data?: { [key: string]: string };
22
- id?: string;
23
- option?: GenericObject;
24
- key?: string;
25
- };
26
-
27
- const DropdownOption = (props: DropdownOptionProps) => {
28
- const { aria = {}, className, children, data = {}, id, option, key } = props;
29
-
30
- const { handleOptionClick, selected, filterItem, filteredOptions, focusedOptionIndex } =
31
- useContext(DropdownContext);
32
-
33
- const isItemMatchingFilter = (option: GenericObject) =>
34
- option?.label.toLowerCase().includes(filterItem.toLowerCase());
35
-
36
- if (!isItemMatchingFilter(option)) {
37
- return null;
38
- }
39
- const isFocused = focusedOptionIndex >= 0 && filteredOptions[focusedOptionIndex].label === option.label
40
- const focusedClass = isFocused && "dropdown_option_focused"
41
-
42
- const selectedClass = `${
43
- selected.label === option.label
44
- ? "dropdown_option_selected"
45
- : "dropdown_option_list"
46
- }`
47
- const ariaProps = buildAriaProps(aria);
48
- const dataProps = buildDataProps(data);
49
- const classes = classnames(
50
- buildCss("pb_dropdown_option"),
51
- selectedClass,
52
- focusedClass,
53
- globalProps(props),
54
- className
55
- );
56
-
57
- return (
58
- <div {...ariaProps}
59
- {...dataProps}
60
- className={classes}
61
- id={id}
62
- key={key}
63
- >
64
- <ListItem
65
- cursor="pointer"
66
- data-name={option.value}
67
- htmlOptions={{ onClick: () => handleOptionClick(option) }}
68
- key={option.label}
69
- padding="xs"
70
- >
71
- <Flex
72
- align="center"
73
- className="dropdown_option"
74
- justify="between"
75
- paddingX="sm"
76
- paddingY="xxs"
77
- >
78
- {
79
- children ? (
80
- children
81
- ) : (
82
- <Body text={option.label}/>
83
- )
84
- }
85
- </Flex>
86
- </ListItem>
87
- </div>
88
- );
89
- };
90
-
91
- export default DropdownOption;
@@ -1,118 +0,0 @@
1
- import React, { useContext } from "react";
2
- import classnames from "classnames";
3
- import {
4
- buildAriaProps,
5
- buildCss,
6
- buildDataProps,
7
- } from "../../utilities/props";
8
- import { globalProps } from "../../utilities/globalProps";
9
- import { useHandleOnKeyDown } from "../hooks/useHandleOnKeydown";
10
-
11
- import DropdownContext from "../context";
12
-
13
- import Body from "../../pb_body/_body";
14
- import Icon from "../../pb_icon/_icon";
15
- import Flex from "../../pb_flex/_flex";
16
- import FlexItem from "../../pb_flex/_flex_item";
17
-
18
- type DropdownTriggerProps = {
19
- aria?: { [key: string]: string };
20
- children?: React.ReactChild[] | React.ReactChild;
21
- className?: string;
22
- customDisplay?: React.ReactChild[] | React.ReactChild;
23
- data?: { [key: string]: string };
24
- id?: string;
25
- };
26
-
27
- const DropdownTrigger = (props: DropdownTriggerProps) => {
28
- const { aria = {}, className, children, customDisplay, data = {}, id } = props;
29
-
30
- const {
31
- handleWrapperClick,
32
- selected,
33
- filterItem,
34
- handleChange,
35
- toggleDropdown,
36
- isDropDownClosed,
37
- inputRef,
38
- isInputFocused,
39
- setIsInputFocused
40
- } = useContext(DropdownContext);
41
-
42
- const handleKeyDown = useHandleOnKeyDown();
43
-
44
- const ariaProps = buildAriaProps(aria);
45
- const dataProps = buildDataProps(data);
46
- const classes = classnames(
47
- buildCss("pb_dropdown_trigger"),
48
- globalProps(props),
49
- className
50
- );
51
-
52
- return (
53
- <div {...ariaProps}
54
- {...dataProps}
55
- className={classes}
56
- id={id}
57
- >
58
- {children ? (
59
- <div
60
- onClick={() => toggleDropdown()}
61
- style={{ display: "inline-block" }}
62
- >
63
- {children}
64
- </div>
65
- ) : (
66
- <>
67
- <Flex align="center"
68
- borderRadius="lg"
69
- className={`dropdown_trigger_wrapper ${isInputFocused && 'dropdown_trigger_wrapper_focus'}`}
70
- cursor="text"
71
- htmlOptions={{ onClick: () => handleWrapperClick(), tabIndex:"0" }}
72
- justify="between"
73
- paddingX="sm"
74
- paddingY="xs"
75
- >
76
- <FlexItem>
77
- <Flex align="center">
78
- {customDisplay ? (
79
- <Flex align="center">
80
- {customDisplay}
81
- <Body paddingLeft="xs">
82
- <b>{selected.label}</b>
83
- </Body>
84
- </Flex>
85
- ) : (
86
- selected.label && <Body text={selected.label} />
87
- )
88
- }
89
- <input
90
- className="dropdown_input"
91
- onChange={handleChange}
92
- onClick={() => toggleDropdown()}
93
- onFocus={() => setIsInputFocused(true)}
94
- onKeyDown={handleKeyDown}
95
- placeholder={selected.label ? "" : "Select..."}
96
- ref={inputRef}
97
- value={filterItem}
98
- />
99
- </Flex>
100
- </FlexItem>
101
- <FlexItem>
102
- <Body color="light"
103
- key={`${isDropDownClosed ? "chevron-down" : 'chevron-up'}`}
104
- >
105
- <Icon cursor="pointer"
106
- icon={`${isDropDownClosed ? "chevron-down" : 'chevron-up'}`}
107
- size="sm"
108
- />
109
- </Body>
110
- </FlexItem>
111
- </Flex>
112
- </>
113
- )}
114
- </div>
115
- );
116
- };
117
-
118
- export default DropdownTrigger;