@thecb/components 9.3.1-beta.8 → 9.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +114 -143
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.esm.js +114 -144
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/atoms/button-with-action/ButtonWithAction.js +76 -70
- package/src/components/atoms/checkbox/Checkbox.js +2 -1
- package/src/components/atoms/dropdown/Dropdown.js +3 -3
- package/src/components/atoms/icons/KebabMenuIcon.d.ts +1 -0
- package/src/components/atoms/icons/KebabMenuIcon.js +38 -0
- package/src/components/atoms/icons/TrashIcon.js +42 -40
- package/src/components/atoms/icons/icons.stories.js +3 -1
- package/src/components/atoms/icons/index.d.ts +1 -0
- package/src/components/atoms/icons/index.js +3 -1
- package/src/components/atoms/layouts/Motion.js +7 -10
- package/src/components/atoms/toggle-switch/ToggleSwitch.js +2 -1
- package/src/components/molecules/collapsible-section/CollapsibleSection.js +2 -1
- package/src/components/molecules/popover/Popover.js +2 -1
- package/src/components/molecules/popup-menu/PopupMenu.js +152 -0
- package/src/components/molecules/popup-menu/PopupMenu.stories.js +40 -0
- package/src/components/molecules/popup-menu/PopupMenu.styled.js +20 -0
- package/src/components/molecules/popup-menu/PopupMenu.theme.js +11 -0
- package/src/components/molecules/popup-menu/index.d.ts +25 -0
- package/src/components/molecules/popup-menu/index.js +3 -0
- package/src/components/molecules/popup-menu/popup-menu-item/PopupMenuItem.js +79 -0
- package/src/components/molecules/popup-menu/popup-menu-item/PopupMenuItem.styled.js +27 -0
- package/src/components/molecules/popup-menu/popup-menu-item/PopupMenuItem.theme.js +23 -0
- package/src/components/molecules/radio-section/RadioSection.js +177 -284
- package/src/components/molecules/radio-section/RadioSection.stories.js +11 -42
- package/src/components/molecules/radio-section/radio-button/RadioButton.js +1 -1
- package/src/constants/keyboard.js +7 -0
- package/src/util/general.js +10 -0
- package/dist/src/apps/checkout/pages/payment/sub-pages/payment-amount/PaymentAmount_old.js +0 -49322
- package/src/.DS_Store +0 -0
- package/src/components/.DS_Store +0 -0
- package/src/components/atoms/.DS_Store +0 -0
- package/src/components/atoms/icons/.DS_Store +0 -0
- /package/src/components/atoms/icons/{ExternalLinkIcon.js → ExternalLinkicon.js} +0 -0
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useContext } from "react";
|
|
1
|
+
import React, { useContext, forwardRef } from "react";
|
|
2
2
|
import styled, { ThemeContext } from "styled-components";
|
|
3
3
|
import posed from "react-pose";
|
|
4
4
|
import { linear } from "@popmotion/easing";
|
|
@@ -60,32 +60,36 @@ const Spinner = ({ color, isMobile }) => (
|
|
|
60
60
|
|
|
61
61
|
*/
|
|
62
62
|
|
|
63
|
-
const ButtonWithAction = (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
63
|
+
const ButtonWithAction = forwardRef(
|
|
64
|
+
(
|
|
65
|
+
{
|
|
66
|
+
action = noop,
|
|
67
|
+
variant = "primary",
|
|
68
|
+
text,
|
|
69
|
+
textWrap = false,
|
|
70
|
+
isLoading = false,
|
|
71
|
+
loadingColor = "white",
|
|
72
|
+
dataQa = null,
|
|
73
|
+
textExtraStyles,
|
|
74
|
+
contentOverride = false,
|
|
75
|
+
extraStyles = "",
|
|
76
|
+
tabIndex,
|
|
77
|
+
children,
|
|
78
|
+
extraDisabledStyles,
|
|
79
|
+
...rest
|
|
80
|
+
},
|
|
81
|
+
ref
|
|
82
|
+
) => {
|
|
83
|
+
const themeContext = useContext(ThemeContext);
|
|
84
|
+
const themeValues = createThemeValues(
|
|
85
|
+
themeContext,
|
|
86
|
+
fallbackValues,
|
|
87
|
+
"Button",
|
|
88
|
+
variant
|
|
89
|
+
);
|
|
90
|
+
const { isMobile } = themeContext;
|
|
87
91
|
|
|
88
|
-
|
|
92
|
+
const hoverStyles = `
|
|
89
93
|
outline: none;
|
|
90
94
|
background-color: ${themeValues.hoverBackgroundColor};
|
|
91
95
|
border-color: ${themeValues.hoverBorderColor};
|
|
@@ -95,7 +99,7 @@ const ButtonWithAction = ({
|
|
|
95
99
|
};
|
|
96
100
|
cursor: pointer;
|
|
97
101
|
`;
|
|
98
|
-
|
|
102
|
+
const activeStyles = `
|
|
99
103
|
outline: none;
|
|
100
104
|
background-color: ${themeValues.activeBackgroundColor};
|
|
101
105
|
border-color: ${themeValues.activeBorderColor};
|
|
@@ -104,7 +108,7 @@ const ButtonWithAction = ({
|
|
|
104
108
|
variant === "ghost" || variant === "smallGhost" ? "underline" : "none"
|
|
105
109
|
};
|
|
106
110
|
`;
|
|
107
|
-
|
|
111
|
+
const disabledStyles = `
|
|
108
112
|
background-color: #6D717E;
|
|
109
113
|
border-color: #6D717E;
|
|
110
114
|
color: #FFFFFF;
|
|
@@ -116,47 +120,49 @@ const ButtonWithAction = ({
|
|
|
116
120
|
${extraDisabledStyles}
|
|
117
121
|
`;
|
|
118
122
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
123
|
+
return (
|
|
124
|
+
<Box
|
|
125
|
+
ref={ref}
|
|
126
|
+
variant={variant}
|
|
127
|
+
padding={themeValues.padding}
|
|
128
|
+
minHeight={themeValues.height}
|
|
129
|
+
minWidth={themeValues.minWidth}
|
|
130
|
+
background={themeValues.backgroundColor}
|
|
131
|
+
border={themeValues.border}
|
|
132
|
+
hoverStyles={hoverStyles}
|
|
133
|
+
activeStyles={activeStyles}
|
|
134
|
+
disabledStyles={disabledStyles}
|
|
135
|
+
as="button"
|
|
136
|
+
onClick={isLoading ? undefined : action}
|
|
137
|
+
borderRadius="2px"
|
|
138
|
+
theme={themeContext}
|
|
139
|
+
extraStyles={`margin: 0.5rem; ${extraStyles}`}
|
|
140
|
+
dataQa={dataQa}
|
|
141
|
+
tabIndex={tabIndex}
|
|
142
|
+
{...rest}
|
|
143
|
+
>
|
|
144
|
+
{contentOverride ? (
|
|
145
|
+
children
|
|
146
|
+
) : (
|
|
147
|
+
<Center intrinsic>
|
|
148
|
+
{isLoading ? (
|
|
149
|
+
<Spinner color={loadingColor} isMobile={isMobile} />
|
|
150
|
+
) : (
|
|
151
|
+
<Text
|
|
152
|
+
weight={themeValues.fontWeight}
|
|
153
|
+
variant={themeValues.fontSizeVariant}
|
|
154
|
+
color={themeValues.color}
|
|
155
|
+
textWrap={textWrap}
|
|
156
|
+
extraStyles={textExtraStyles}
|
|
157
|
+
>
|
|
158
|
+
{text}
|
|
159
|
+
</Text>
|
|
160
|
+
)}
|
|
161
|
+
</Center>
|
|
162
|
+
)}
|
|
163
|
+
</Box>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
);
|
|
161
167
|
|
|
162
168
|
export default ButtonWithAction;
|
|
@@ -2,6 +2,7 @@ import React, { useState } from "react";
|
|
|
2
2
|
import styled, { css } from "styled-components";
|
|
3
3
|
import { fallbackValues } from "./Checkbox.theme";
|
|
4
4
|
import { noop } from "../../../util/general";
|
|
5
|
+
import { ENTER } from "../../../constants/keyboard";
|
|
5
6
|
import Box from "../layouts/Box";
|
|
6
7
|
import Text from "../text";
|
|
7
8
|
import { themeComponent } from "../../../util/themeUtils";
|
|
@@ -101,7 +102,7 @@ const Checkbox = ({
|
|
|
101
102
|
const [focused, setFocused] = useState(false);
|
|
102
103
|
|
|
103
104
|
const handleClick = (e, func) => {
|
|
104
|
-
if (e
|
|
105
|
+
if (e.keyCode === ENTER) {
|
|
105
106
|
func();
|
|
106
107
|
}
|
|
107
108
|
};
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
STORM_GREY,
|
|
19
19
|
WHITE
|
|
20
20
|
} from "../../../constants/colors";
|
|
21
|
+
import { ENTER } from "../../../constants/keyboard";
|
|
21
22
|
import { fallbackValues } from "./Dropdown.theme";
|
|
22
23
|
import { themeComponent } from "../../../util/themeUtils";
|
|
23
24
|
|
|
@@ -318,10 +319,9 @@ const Dropdown = ({
|
|
|
318
319
|
>
|
|
319
320
|
<Box
|
|
320
321
|
as="input"
|
|
321
|
-
aria-multiline="false"
|
|
322
322
|
autoComplete={autocompleteValue}
|
|
323
323
|
aria-controls={`${ariaLabelledby}_listbox`}
|
|
324
|
-
aria-activedescendant="focused_option"
|
|
324
|
+
aria-activedescendant={isOpen ? "focused_option" : undefined}
|
|
325
325
|
aria-owns={`${ariaLabelledby}_listbox`}
|
|
326
326
|
aria-haspopup="listbox"
|
|
327
327
|
aria-labelledby={ariaLabelledby}
|
|
@@ -402,7 +402,7 @@ const Dropdown = ({
|
|
|
402
402
|
tabIndex={-1}
|
|
403
403
|
onClick={e => handleItemSelection(e, choice, i)}
|
|
404
404
|
onKeyDown={e => {
|
|
405
|
-
if (e.keyCode ===
|
|
405
|
+
if (e.keyCode === ENTER) {
|
|
406
406
|
handleItemSelection(e, choice, i);
|
|
407
407
|
}
|
|
408
408
|
}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const KebabMenuIcon: JSX.Element;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
const KebabMenuIcon = () => {
|
|
4
|
+
return (
|
|
5
|
+
<svg
|
|
6
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
7
|
+
width="21"
|
|
8
|
+
height="32"
|
|
9
|
+
viewBox="0 0 21 32"
|
|
10
|
+
fill="none"
|
|
11
|
+
>
|
|
12
|
+
<path
|
|
13
|
+
d="M0 4C0 1.79086 1.79086 0 4 0L17 0C19.2091 0 21 1.79086 21 4V28C21 30.2091 19.2091 32 17 32H4C1.79086 32 0 30.2091 0 28L0 4Z"
|
|
14
|
+
fill="none"
|
|
15
|
+
/>
|
|
16
|
+
<path
|
|
17
|
+
fillRule="evenodd"
|
|
18
|
+
clipRule="evenodd"
|
|
19
|
+
d="M10.5 6C9.39333 6 8.5 6.89333 8.5 8C8.5 9.10667 9.39333 10 10.5 10C11.6067 10 12.5 9.10667 12.5 8C12.5 6.89333 11.6067 6 10.5 6Z"
|
|
20
|
+
fill="#3B5BDB"
|
|
21
|
+
/>
|
|
22
|
+
<path
|
|
23
|
+
fillRule="evenodd"
|
|
24
|
+
clipRule="evenodd"
|
|
25
|
+
d="M10.5 14C9.39333 14 8.5 14.8933 8.5 16C8.5 17.1067 9.39333 18 10.5 18C11.6067 18 12.5 17.1067 12.5 16C12.5 14.8933 11.6067 14 10.5 14Z"
|
|
26
|
+
fill="#3B5BDB"
|
|
27
|
+
/>
|
|
28
|
+
<path
|
|
29
|
+
fillRule="evenodd"
|
|
30
|
+
clipRule="evenodd"
|
|
31
|
+
d="M10.5 22C9.39333 22 8.5 22.9067 8.5 24C8.5 25.0933 9.40667 26 10.5 26C11.5933 26 12.5 25.0933 12.5 24C12.5 22.9067 11.6067 22 10.5 22Z"
|
|
32
|
+
fill="#3B5BDB"
|
|
33
|
+
/>
|
|
34
|
+
</svg>
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default KebabMenuIcon;
|
|
@@ -2,46 +2,48 @@ import React from "react";
|
|
|
2
2
|
import { fallbackValues } from "./Icons.theme";
|
|
3
3
|
import { themeComponent } from "../../../util/themeUtils";
|
|
4
4
|
|
|
5
|
-
const TrashIcon = ({ themeValues }) =>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
<defs>
|
|
15
|
-
<path
|
|
16
|
-
d="M15,7 L14,15.5714286 C14,16.3571429 13.25,17 12.3333333,17 L12.3333333,17 L7.66666667,17 C6.75,17 6,16.3571429 6,15.5714286 L6,15.5714286 L5,7 L15,7 Z M12.1428571,3 L13,4 L16,4 L16,6 L4,6 L4,4 L7,4 L7.85714286,3 L12.1428571,3 Z"
|
|
17
|
-
id="trash-path-1"
|
|
18
|
-
></path>
|
|
19
|
-
</defs>
|
|
20
|
-
<g
|
|
21
|
-
id="trash-Icons-/-Small-/-20px-S-/-Trash---Mobile---20px"
|
|
22
|
-
stroke="none"
|
|
23
|
-
strokeWidth="1"
|
|
24
|
-
fill="none"
|
|
25
|
-
fillRule="evenodd"
|
|
5
|
+
const TrashIcon = ({ themeValues, iconFill }) => {
|
|
6
|
+
return (
|
|
7
|
+
<svg
|
|
8
|
+
width="20px"
|
|
9
|
+
height="20px"
|
|
10
|
+
viewBox="0 0 20 20"
|
|
11
|
+
version="1.1"
|
|
12
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
13
|
+
xmlnsXlink="http://www.w3.org/1999/xlink"
|
|
26
14
|
>
|
|
27
|
-
<
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
mask="
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
15
|
+
<defs>
|
|
16
|
+
<path
|
|
17
|
+
d="M15,7 L14,15.5714286 C14,16.3571429 13.25,17 12.3333333,17 L12.3333333,17 L7.66666667,17 C6.75,17 6,16.3571429 6,15.5714286 L6,15.5714286 L5,7 L15,7 Z M12.1428571,3 L13,4 L16,4 L16,6 L4,6 L4,4 L7,4 L7.85714286,3 L12.1428571,3 Z"
|
|
18
|
+
id="trash-path-1"
|
|
19
|
+
></path>
|
|
20
|
+
</defs>
|
|
21
|
+
<g
|
|
22
|
+
id="trash-Icons-/-Small-/-20px-S-/-Trash---Mobile---20px"
|
|
23
|
+
stroke="none"
|
|
24
|
+
strokeWidth="1"
|
|
25
|
+
fill="none"
|
|
26
|
+
fillRule="evenodd"
|
|
27
|
+
>
|
|
28
|
+
<mask id="trash-mask-2" fill="white">
|
|
29
|
+
<use xlinkHref="#trash-path-1"></use>
|
|
30
|
+
</mask>
|
|
31
|
+
<use
|
|
32
|
+
id="trash-Mask"
|
|
33
|
+
fill={iconFill ?? themeValues.singleIconColor}
|
|
34
|
+
fillRule="nonzero"
|
|
35
|
+
xlinkHref="#trash-path-1"
|
|
36
|
+
></use>
|
|
37
|
+
<polygon
|
|
38
|
+
id="trash-Path"
|
|
39
|
+
fill={iconFill ?? themeValues.singleIconColor}
|
|
40
|
+
fillRule="nonzero"
|
|
41
|
+
mask="url(#trash-mask-2)"
|
|
42
|
+
points="0 0 20 0 20 20 0 20"
|
|
43
|
+
></polygon>
|
|
44
|
+
</g>
|
|
45
|
+
</svg>
|
|
46
|
+
);
|
|
47
|
+
};
|
|
46
48
|
|
|
47
49
|
export default themeComponent(TrashIcon, "Icons", fallbackValues, "primary");
|
|
@@ -38,7 +38,8 @@ import {
|
|
|
38
38
|
SuccessfulIcon,
|
|
39
39
|
VoidedIcon,
|
|
40
40
|
StatusUnknownIcon,
|
|
41
|
-
AutopayIcon
|
|
41
|
+
AutopayIcon,
|
|
42
|
+
KebabMenuIcon
|
|
42
43
|
} from "./index";
|
|
43
44
|
|
|
44
45
|
const story = page({
|
|
@@ -84,3 +85,4 @@ export const successfulIcon = () => <SuccessfulIcon />;
|
|
|
84
85
|
export const voidedIcon = () => <VoidedIcon />;
|
|
85
86
|
export const statusUnknownIcon = () => <StatusUnknownIcon />;
|
|
86
87
|
export const autopayIcon = () => <AutopayIcon />;
|
|
88
|
+
export const kebabMenuIcon = () => <KebabMenuIcon />;
|
|
@@ -86,6 +86,7 @@ import ArrowLeftCircleIconMedium from "./ArrowLeftCircleIconMedium";
|
|
|
86
86
|
import ChargebackIconMedium from "./ChargebackIconMedium";
|
|
87
87
|
import ChargebackReversalIconMedium from "./ChargebackReversalIconMedium";
|
|
88
88
|
import PlusCircleIcon from "./PlusCircleIcon";
|
|
89
|
+
import KebabMenuIcon from "./KebabMenuIcon";
|
|
89
90
|
|
|
90
91
|
export {
|
|
91
92
|
AccountsIcon,
|
|
@@ -175,5 +176,6 @@ export {
|
|
|
175
176
|
ArrowLeftCircleIconMedium,
|
|
176
177
|
ChargebackIconMedium,
|
|
177
178
|
ChargebackReversalIconMedium,
|
|
178
|
-
PlusCircleIcon
|
|
179
|
+
PlusCircleIcon,
|
|
180
|
+
KebabMenuIcon
|
|
179
181
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { Fragment } from "react";
|
|
1
|
+
import React, { Fragment, forwardRef } from "react";
|
|
2
2
|
import { MotionWrapper } from "./Motion.styled";
|
|
3
3
|
import { safeChildren } from "../../../util/general";
|
|
4
4
|
|
|
@@ -37,15 +37,12 @@ import { safeChildren } from "../../../util/general";
|
|
|
37
37
|
This should be sufficient for most scenarios, but if you need to, you have the ability to make Motion act like all of the other primitives using the props provided.
|
|
38
38
|
*/
|
|
39
39
|
|
|
40
|
-
export const Motion = (
|
|
41
|
-
position = "relative",
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
<MotionWrapper position={position} padding={padding} {...rest}>
|
|
47
|
-
{safeChildren(children, <Fragment />)}
|
|
48
|
-
</MotionWrapper>
|
|
40
|
+
export const Motion = forwardRef(
|
|
41
|
+
({ position = "relative", padding = "0", children, ...rest }, ref) => (
|
|
42
|
+
<MotionWrapper position={position} padding={padding} ref={ref} {...rest}>
|
|
43
|
+
{safeChildren(children, <Fragment />)}
|
|
44
|
+
</MotionWrapper>
|
|
45
|
+
)
|
|
49
46
|
);
|
|
50
47
|
|
|
51
48
|
export default Motion;
|
|
@@ -7,6 +7,7 @@ import Heading from "../heading";
|
|
|
7
7
|
import { Box, Center, Cover, Cluster } from "../layouts";
|
|
8
8
|
import { FONT_WEIGHT_SEMIBOLD } from "../../../constants/style_constants";
|
|
9
9
|
import { CHARADE_GREY } from "../../../constants/colors";
|
|
10
|
+
import { ENTER } from "../../../constants/keyboard";
|
|
10
11
|
import { noop } from "../../../util/general";
|
|
11
12
|
|
|
12
13
|
const HiddenToggleSwitchBox = styled.input`
|
|
@@ -149,7 +150,7 @@ const ToggleSwitch = ({
|
|
|
149
150
|
});
|
|
150
151
|
|
|
151
152
|
const handleKeyDown = e => {
|
|
152
|
-
if (e.keyCode ===
|
|
153
|
+
if (e.keyCode === ENTER) {
|
|
153
154
|
onToggle();
|
|
154
155
|
}
|
|
155
156
|
};
|
|
@@ -4,6 +4,7 @@ import { AnimatePresence } from "framer-motion";
|
|
|
4
4
|
import { themeComponent } from "../../../util/themeUtils";
|
|
5
5
|
import Title from "../../atoms/title";
|
|
6
6
|
import { FONT_WEIGHT_SEMIBOLD } from "../../../constants/style_constants";
|
|
7
|
+
import { ENTER } from "../../../constants/keyboard";
|
|
7
8
|
import { Box, Cluster, Stack, Motion } from "../../atoms/layouts";
|
|
8
9
|
import { ChevronIcon } from "../../atoms/icons";
|
|
9
10
|
import { noop } from "../../../util/general";
|
|
@@ -28,7 +29,7 @@ const CollapsibleSection = ({
|
|
|
28
29
|
extraStyles = ""
|
|
29
30
|
}) => {
|
|
30
31
|
const handleKeyDown = e => {
|
|
31
|
-
if (e.keyCode ===
|
|
32
|
+
if (e.keyCode === ENTER) {
|
|
32
33
|
toggleSection();
|
|
33
34
|
}
|
|
34
35
|
};
|
|
@@ -6,6 +6,7 @@ import { Box } from "../../atoms/layouts";
|
|
|
6
6
|
import ButtonWithAction from "../../atoms/button-with-action";
|
|
7
7
|
import { useOutsideClick } from "../../../hooks";
|
|
8
8
|
import { noop } from "../../../util/general";
|
|
9
|
+
import { ESCAPE } from "../../../constants/keyboard";
|
|
9
10
|
import { fallbackValues } from "./Popover.theme";
|
|
10
11
|
|
|
11
12
|
const arrowBorder = (borderColor, direction, width = "8px") => {
|
|
@@ -76,7 +77,7 @@ const Popover = ({
|
|
|
76
77
|
handleTogglePopover(false);
|
|
77
78
|
}}
|
|
78
79
|
onKeyDown={e => {
|
|
79
|
-
if (e.keyCode ===
|
|
80
|
+
if (e.keyCode === ESCAPE) {
|
|
80
81
|
handleTogglePopover(false);
|
|
81
82
|
}
|
|
82
83
|
}}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import React, { useState, useRef, useEffect } from "react";
|
|
2
|
+
import { themeComponent } from "../../../util/themeUtils";
|
|
3
|
+
import Text from "../../atoms/text";
|
|
4
|
+
import { Box } from "../../atoms/layouts";
|
|
5
|
+
import PopupMenuItem from "./popup-menu-item/PopupMenuItem";
|
|
6
|
+
import { fallbackValues } from "./PopupMenu.theme";
|
|
7
|
+
import { PopupMenuContainer, PopupMenuTriggerButton } from "./PopupMenu.styled";
|
|
8
|
+
|
|
9
|
+
const PopupMenu = ({
|
|
10
|
+
menuId = "popup-menu",
|
|
11
|
+
menuItems = [],
|
|
12
|
+
themeValues,
|
|
13
|
+
triggerText = "trigger text",
|
|
14
|
+
hasIcon = false,
|
|
15
|
+
icon: Icon,
|
|
16
|
+
iconHelpText = "", // for screen-readers, required if using an icon for trigger
|
|
17
|
+
menuFocus,
|
|
18
|
+
containerExtraStyles,
|
|
19
|
+
textExtraStyles,
|
|
20
|
+
minWidth = "250px",
|
|
21
|
+
maxWidth = "300px",
|
|
22
|
+
height = "auto",
|
|
23
|
+
position,
|
|
24
|
+
transform = "none",
|
|
25
|
+
buttonExtraStyles,
|
|
26
|
+
popupExtraStyles
|
|
27
|
+
}) => {
|
|
28
|
+
const {
|
|
29
|
+
hoverColor,
|
|
30
|
+
activeColor,
|
|
31
|
+
menuTriggerColor,
|
|
32
|
+
backgroundColor
|
|
33
|
+
} = themeValues;
|
|
34
|
+
const { top = `${height}px`, right = "auto", bottom = "auto", left = "0" } =
|
|
35
|
+
position ?? {};
|
|
36
|
+
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
|
37
|
+
const menuRef = useRef();
|
|
38
|
+
const triggerRef = useRef();
|
|
39
|
+
const toggleMenu = menuState => setIsMenuOpen(menuState);
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
const checkIfClickedOutside = e => {
|
|
43
|
+
// If the menu is open and the clicked target is not within the menu or the trigger
|
|
44
|
+
if (
|
|
45
|
+
isMenuOpen &&
|
|
46
|
+
menuRef.current &&
|
|
47
|
+
!menuRef.current.contains(e.target) &&
|
|
48
|
+
triggerRef.current &&
|
|
49
|
+
!triggerRef.current.contains(e.target)
|
|
50
|
+
) {
|
|
51
|
+
toggleMenu(false);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
document.addEventListener("click", checkIfClickedOutside);
|
|
56
|
+
|
|
57
|
+
return () => {
|
|
58
|
+
document.removeEventListener("click", checkIfClickedOutside);
|
|
59
|
+
};
|
|
60
|
+
}, [isMenuOpen]);
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<PopupMenuContainer extraStyles={containerExtraStyles}>
|
|
64
|
+
<PopupMenuTriggerButton
|
|
65
|
+
ref={triggerRef}
|
|
66
|
+
action={() => {
|
|
67
|
+
toggleMenu(!isMenuOpen);
|
|
68
|
+
}}
|
|
69
|
+
onKeyDown={e => {
|
|
70
|
+
if (e.key === "Escape") {
|
|
71
|
+
toggleMenu(false);
|
|
72
|
+
}
|
|
73
|
+
}}
|
|
74
|
+
contentOverride
|
|
75
|
+
variant="smallGhost"
|
|
76
|
+
tabIndex="0"
|
|
77
|
+
id={menuId}
|
|
78
|
+
borderRadius="8px"
|
|
79
|
+
aria-haspopup="true"
|
|
80
|
+
aria-expanded={isMenuOpen}
|
|
81
|
+
aria-controls={`${menuId}-container`}
|
|
82
|
+
extraStyles={buttonExtraStyles}
|
|
83
|
+
>
|
|
84
|
+
{hasIcon && (
|
|
85
|
+
<>
|
|
86
|
+
<Icon />
|
|
87
|
+
<Box padding="0" srOnly>
|
|
88
|
+
<Text id={`btn${menuId}_info`}>{iconHelpText}</Text>
|
|
89
|
+
</Box>
|
|
90
|
+
</>
|
|
91
|
+
)}
|
|
92
|
+
{!hasIcon && (
|
|
93
|
+
<Text
|
|
94
|
+
color={menuTriggerColor}
|
|
95
|
+
extraStyles={`&:active { color: ${activeColor}; } &:hover { color: ${hoverColor} }; ${textExtraStyles}`}
|
|
96
|
+
>
|
|
97
|
+
{triggerText}
|
|
98
|
+
</Text>
|
|
99
|
+
)}
|
|
100
|
+
</PopupMenuTriggerButton>
|
|
101
|
+
<Box
|
|
102
|
+
as="div"
|
|
103
|
+
id={`${menuId}-container`}
|
|
104
|
+
ref={menuRef}
|
|
105
|
+
onKeyDown={e => {
|
|
106
|
+
if (e.key === "Escape") {
|
|
107
|
+
toggleMenu(false);
|
|
108
|
+
}
|
|
109
|
+
}}
|
|
110
|
+
background={backgroundColor}
|
|
111
|
+
borderRadius="8px"
|
|
112
|
+
boxShadow={`
|
|
113
|
+
0px 7px 32px 0px rgba(41, 42, 51, 0.2),
|
|
114
|
+
0px 1px 4px 0px rgba(41, 42, 51, 0.2),
|
|
115
|
+
0px 1px 8px -1px rgba(41, 42, 51, 0.3);
|
|
116
|
+
`}
|
|
117
|
+
role="menu"
|
|
118
|
+
aria-labelledby={menuId}
|
|
119
|
+
tabIndex={menuFocus && isMenuOpen ? "0" : "-1"}
|
|
120
|
+
minWidth={minWidth}
|
|
121
|
+
maxWidth={maxWidth}
|
|
122
|
+
extraStyles={`
|
|
123
|
+
display: ${isMenuOpen ? "block" : "none"};
|
|
124
|
+
position: absolute;
|
|
125
|
+
padding: 8px 8px 3px 8px;
|
|
126
|
+
top: ${top};
|
|
127
|
+
left: ${left};
|
|
128
|
+
right: ${right};
|
|
129
|
+
bottom: ${bottom};
|
|
130
|
+
height: ${height};
|
|
131
|
+
transform: ${transform};
|
|
132
|
+
${popupExtraStyles};
|
|
133
|
+
`}
|
|
134
|
+
>
|
|
135
|
+
{menuItems.map((item, index) => (
|
|
136
|
+
<PopupMenuItem
|
|
137
|
+
key={index}
|
|
138
|
+
id={`${menuId}-item-${index}`}
|
|
139
|
+
closeMenuCallback={() => {
|
|
140
|
+
toggleMenu(false);
|
|
141
|
+
// focus back to trigger button when menu closes
|
|
142
|
+
triggerRef.current.focus();
|
|
143
|
+
}}
|
|
144
|
+
{...item}
|
|
145
|
+
/>
|
|
146
|
+
))}
|
|
147
|
+
</Box>
|
|
148
|
+
</PopupMenuContainer>
|
|
149
|
+
);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export default themeComponent(PopupMenu, "PopupMenu", fallbackValues);
|