@conveyorhq/arrow-ds 1.141.0 → 1.143.0
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/package.json +1 -1
- package/public/components/Drawer/Drawer.d.ts +6 -1
- package/public/components/Drawer/Drawer.js +20 -2
- package/public/components/Menu/MenuItem.js +2 -2
- package/public/components/MenuRenderer/MenuRenderer.d.ts +2 -1
- package/public/components/MenuRenderer/MenuRenderer.js +2 -1
- package/public/components/MenuRenderer/context.d.ts +1 -0
- package/public/components/MenuRenderer/context.js +1 -0
- package/public/contexts/drawer.d.ts +1 -0
- package/public/contexts/drawer.js +1 -0
- package/src/components/Drawer/Drawer.tsx +26 -3
- package/src/components/Menu/MenuItem.tsx +2 -2
- package/src/components/MenuRenderer/MenuRenderer.tsx +6 -0
- package/src/components/MenuRenderer/context.ts +2 -0
- package/src/contexts/drawer.tsx +2 -0
package/package.json
CHANGED
|
@@ -2,13 +2,17 @@ import React from "react";
|
|
|
2
2
|
import { BoxProps } from "../Box";
|
|
3
3
|
import { TopBarProps } from "../TopBar";
|
|
4
4
|
import { CloseButtonProps } from "../CloseButton";
|
|
5
|
+
type ScrollableSlotRenderFunction = (props: {
|
|
6
|
+
isOpen: boolean;
|
|
7
|
+
isAnimationComplete: boolean;
|
|
8
|
+
}) => React.ReactNode;
|
|
5
9
|
export interface WithDrawerProps {
|
|
6
10
|
drawerSlot: React.ReactNode;
|
|
7
11
|
onClose: () => void;
|
|
8
12
|
isOpen?: boolean;
|
|
9
13
|
fixedSlotTop?: React.ReactNode;
|
|
10
14
|
fixedSlotBottom?: React.ReactNode;
|
|
11
|
-
scrollableSlot?: React.ReactNode;
|
|
15
|
+
scrollableSlot?: ScrollableSlotRenderFunction | React.ReactNode;
|
|
12
16
|
drawerSide?: "left" | "right";
|
|
13
17
|
noAnimation?: boolean;
|
|
14
18
|
drawerWidth?: number;
|
|
@@ -32,3 +36,4 @@ export declare const Drawer: {
|
|
|
32
36
|
Body: ({ children, className, ...rest }: BoxProps) => React.JSX.Element;
|
|
33
37
|
Footer: ({ children, className, ...rest }: BoxProps) => React.JSX.Element;
|
|
34
38
|
};
|
|
39
|
+
export {};
|
|
@@ -50,6 +50,7 @@ const calculateTransformValue = (isOpen, drawerOnRight, drawerWidth) => {
|
|
|
50
50
|
const WithDrawer = ({ drawerSlot, onClose, isOpen = false, fixedSlotTop, fixedSlotBottom, scrollableSlot, drawerSide = "left", noAnimation = false, drawerWidth = DEFAULT_DRAWER_WIDTH, }) => {
|
|
51
51
|
const drawerOnRight = drawerSide === "right";
|
|
52
52
|
const [isClosedAtRest, setIsClosedAtRest] = (0, react_1.useState)(false);
|
|
53
|
+
const [isAnimationComplete, setIsAnimationComplete] = (0, react_1.useState)(false);
|
|
53
54
|
const { transform, paddingLeft, paddingRight } = (0, web_1.useSpring)({
|
|
54
55
|
transform: calculateTransformValue(isOpen, drawerOnRight, drawerWidth),
|
|
55
56
|
paddingLeft: isOpen && !drawerOnRight ? drawerWidth : 0,
|
|
@@ -63,6 +64,12 @@ const WithDrawer = ({ drawerSlot, onClose, isOpen = false, fixedSlotTop, fixedSl
|
|
|
63
64
|
setIsClosedAtRest(false);
|
|
64
65
|
}
|
|
65
66
|
},
|
|
67
|
+
onStart: () => {
|
|
68
|
+
setIsAnimationComplete(false);
|
|
69
|
+
},
|
|
70
|
+
onRest: () => {
|
|
71
|
+
setIsAnimationComplete(true);
|
|
72
|
+
},
|
|
66
73
|
config: {
|
|
67
74
|
duration: noAnimation ? 0 : 300,
|
|
68
75
|
easing: d3_ease_1.easeCubicInOut,
|
|
@@ -80,7 +87,13 @@ const WithDrawer = ({ drawerSlot, onClose, isOpen = false, fixedSlotTop, fixedSl
|
|
|
80
87
|
const scrollableSlotPaddingToInterpolate = drawerOnRight
|
|
81
88
|
? paddingRight
|
|
82
89
|
: paddingLeft;
|
|
83
|
-
return (react_1.default.createElement(drawer_1.DrawerContext.Provider, { value: {
|
|
90
|
+
return (react_1.default.createElement(drawer_1.DrawerContext.Provider, { value: {
|
|
91
|
+
isOpen,
|
|
92
|
+
onClose,
|
|
93
|
+
isClosedAtRest,
|
|
94
|
+
drawerSide,
|
|
95
|
+
isAnimationComplete,
|
|
96
|
+
} },
|
|
84
97
|
react_1.default.createElement(Box_1.Box, { className: (0, classnames_1.default)(cn(), {
|
|
85
98
|
[cn({ m: "isOpen" })]: isOpen,
|
|
86
99
|
}) },
|
|
@@ -92,7 +105,12 @@ const WithDrawer = ({ drawerSlot, onClose, isOpen = false, fixedSlotTop, fixedSl
|
|
|
92
105
|
scrollableSlot && (react_1.default.createElement(web_1.animated.div, { style: {
|
|
93
106
|
transform: transformReverse,
|
|
94
107
|
width: scrollableSlotPaddingToInterpolate.interpolate((w) => `calc(100% - ${w}px)`),
|
|
95
|
-
}, className: cn({ e: "scrollableSlot" }) }, scrollableSlot
|
|
108
|
+
}, className: cn({ e: "scrollableSlot" }) }, typeof scrollableSlot === "function"
|
|
109
|
+
? scrollableSlot({
|
|
110
|
+
isOpen,
|
|
111
|
+
isAnimationComplete,
|
|
112
|
+
})
|
|
113
|
+
: scrollableSlot)),
|
|
96
114
|
fixedSlotBottom && (react_1.default.createElement(web_1.animated.div, { style: { paddingLeft, paddingRight }, className: cn({ e: "fixedSlot" }) }, fixedSlotBottom))))));
|
|
97
115
|
};
|
|
98
116
|
exports.WithDrawer = WithDrawer;
|
|
@@ -33,12 +33,12 @@ const bem_1 = require("../../utilities/bem");
|
|
|
33
33
|
const MenuRenderer_1 = require("../MenuRenderer");
|
|
34
34
|
const cn = "Menu";
|
|
35
35
|
exports.MenuItem = (0, react_1.forwardRef)(({ children, className, isSelected = false, isHighlighted = false, disabled = false, as: Component = "button", onClick, ...rest }, ref) => {
|
|
36
|
-
const { onClose, itemProps } = (0, MenuRenderer_1.useMenuContext)();
|
|
36
|
+
const { onClose, itemProps, closeOnSelect } = (0, MenuRenderer_1.useMenuContext)();
|
|
37
37
|
const clickHandler = (event) => {
|
|
38
38
|
if (typeof onClick === "function") {
|
|
39
39
|
onClick(event);
|
|
40
40
|
}
|
|
41
|
-
if (typeof onClose === "function") {
|
|
41
|
+
if (typeof onClose === "function" && closeOnSelect) {
|
|
42
42
|
onClose();
|
|
43
43
|
}
|
|
44
44
|
};
|
|
@@ -31,6 +31,7 @@ export interface MenuProps extends Omit<BoxProps, "children"> {
|
|
|
31
31
|
openMenu?: (open: boolean) => void;
|
|
32
32
|
menuDisplay?: "inline-block" | "block";
|
|
33
33
|
disableFocusLock?: boolean;
|
|
34
|
+
closeOnSelect?: boolean;
|
|
34
35
|
}
|
|
35
|
-
export declare const MenuRenderer: ({ children, className, placement, position, trigger, popperModifiers, autoFocus, hasPortal, isOpen: isOpenInitial, isMenuOpen: isOpenControlled, onClose: onCloseProp, openMenu: setOpenControlled, menuDisplay, disableFocusLock, ...rest }: MenuProps) => React.JSX.Element;
|
|
36
|
+
export declare const MenuRenderer: ({ children, className, placement, position, trigger, popperModifiers, autoFocus, hasPortal, isOpen: isOpenInitial, isMenuOpen: isOpenControlled, onClose: onCloseProp, openMenu: setOpenControlled, menuDisplay, disableFocusLock, closeOnSelect, ...rest }: MenuProps) => React.JSX.Element;
|
|
36
37
|
export {};
|
|
@@ -43,7 +43,7 @@ const TRANSITION_START = {
|
|
|
43
43
|
opacity: 0,
|
|
44
44
|
};
|
|
45
45
|
const TRANSITION_END = { transform: "translateY(0)", opacity: 1 };
|
|
46
|
-
const MenuRenderer = ({ children, className, placement = "bottom-start", position = "absolute", trigger, popperModifiers = [], autoFocus = false, hasPortal = false, isOpen: isOpenInitial = false, isMenuOpen: isOpenControlled, onClose: onCloseProp, openMenu: setOpenControlled, menuDisplay = "inline-block", disableFocusLock = false, ...rest }) => {
|
|
46
|
+
const MenuRenderer = ({ children, className, placement = "bottom-start", position = "absolute", trigger, popperModifiers = [], autoFocus = false, hasPortal = false, isOpen: isOpenInitial = false, isMenuOpen: isOpenControlled, onClose: onCloseProp, openMenu: setOpenControlled, menuDisplay = "inline-block", disableFocusLock = false, closeOnSelect = true, ...rest }) => {
|
|
47
47
|
const [isOpenUncontrolled, setOpenUncontrolled] = (0, react_1.useState)(isOpenInitial);
|
|
48
48
|
const open = isOpenControlled !== null && isOpenControlled !== void 0 ? isOpenControlled : isOpenUncontrolled;
|
|
49
49
|
const setOpen = setOpenControlled !== null && setOpenControlled !== void 0 ? setOpenControlled : setOpenUncontrolled;
|
|
@@ -121,6 +121,7 @@ const MenuRenderer = ({ children, className, placement = "bottom-start", positio
|
|
|
121
121
|
menuId,
|
|
122
122
|
buttonId,
|
|
123
123
|
placement,
|
|
124
|
+
closeOnSelect,
|
|
124
125
|
...renderProps,
|
|
125
126
|
};
|
|
126
127
|
(0, hooks_1.useOutsideClick)([menuElement, menuListElement], () => {
|
|
@@ -20,6 +20,7 @@ export type MenuContextProps = RenderProps & {
|
|
|
20
20
|
onToggle?: (event: Event | React.MouseEvent<HTMLButtonElement>) => void;
|
|
21
21
|
onOpen?: () => void;
|
|
22
22
|
placement?: PopperPlacement;
|
|
23
|
+
closeOnSelect?: boolean;
|
|
23
24
|
};
|
|
24
25
|
export declare const defaultContext: MenuContextProps;
|
|
25
26
|
export declare const MenuContext: Context<typeof defaultContext>;
|
|
@@ -12,6 +12,11 @@ import { Flex } from "../Flex";
|
|
|
12
12
|
|
|
13
13
|
const cn = bemHOF("Drawer");
|
|
14
14
|
|
|
15
|
+
type ScrollableSlotRenderFunction = (props: {
|
|
16
|
+
isOpen: boolean;
|
|
17
|
+
isAnimationComplete: boolean;
|
|
18
|
+
}) => React.ReactNode;
|
|
19
|
+
|
|
15
20
|
export interface WithDrawerProps {
|
|
16
21
|
/**
|
|
17
22
|
* The content of the drawer
|
|
@@ -41,7 +46,7 @@ export interface WithDrawerProps {
|
|
|
41
46
|
/**
|
|
42
47
|
* Scrollable content that will be pushed off screen as the Drawer animates in
|
|
43
48
|
*/
|
|
44
|
-
scrollableSlot?: React.ReactNode;
|
|
49
|
+
scrollableSlot?: ScrollableSlotRenderFunction | React.ReactNode;
|
|
45
50
|
|
|
46
51
|
/**
|
|
47
52
|
* Puts the drawer on the left or right of the content
|
|
@@ -87,6 +92,7 @@ export const WithDrawer = ({
|
|
|
87
92
|
}: WithDrawerProps) => {
|
|
88
93
|
const drawerOnRight = drawerSide === "right";
|
|
89
94
|
const [isClosedAtRest, setIsClosedAtRest] = useState(false);
|
|
95
|
+
const [isAnimationComplete, setIsAnimationComplete] = useState(false);
|
|
90
96
|
const { transform, paddingLeft, paddingRight } = useSpring({
|
|
91
97
|
transform: calculateTransformValue(isOpen, drawerOnRight, drawerWidth),
|
|
92
98
|
paddingLeft: isOpen && !drawerOnRight ? drawerWidth : 0,
|
|
@@ -105,6 +111,12 @@ export const WithDrawer = ({
|
|
|
105
111
|
setIsClosedAtRest(false);
|
|
106
112
|
}
|
|
107
113
|
},
|
|
114
|
+
onStart: () => {
|
|
115
|
+
setIsAnimationComplete(false);
|
|
116
|
+
},
|
|
117
|
+
onRest: () => {
|
|
118
|
+
setIsAnimationComplete(true);
|
|
119
|
+
},
|
|
108
120
|
config: {
|
|
109
121
|
duration: noAnimation ? 0 : 300,
|
|
110
122
|
easing: easeCubicInOut,
|
|
@@ -130,7 +142,13 @@ export const WithDrawer = ({
|
|
|
130
142
|
|
|
131
143
|
return (
|
|
132
144
|
<DrawerContext.Provider
|
|
133
|
-
value={{
|
|
145
|
+
value={{
|
|
146
|
+
isOpen,
|
|
147
|
+
onClose,
|
|
148
|
+
isClosedAtRest,
|
|
149
|
+
drawerSide,
|
|
150
|
+
isAnimationComplete,
|
|
151
|
+
}}
|
|
134
152
|
>
|
|
135
153
|
<Box
|
|
136
154
|
className={classNames(cn(), {
|
|
@@ -166,7 +184,12 @@ export const WithDrawer = ({
|
|
|
166
184
|
}}
|
|
167
185
|
className={cn({ e: "scrollableSlot" })}
|
|
168
186
|
>
|
|
169
|
-
{scrollableSlot
|
|
187
|
+
{typeof scrollableSlot === "function"
|
|
188
|
+
? scrollableSlot({
|
|
189
|
+
isOpen,
|
|
190
|
+
isAnimationComplete,
|
|
191
|
+
})
|
|
192
|
+
: scrollableSlot}
|
|
170
193
|
</animated.div>
|
|
171
194
|
)}
|
|
172
195
|
{fixedSlotBottom && (
|
|
@@ -28,12 +28,12 @@ export const MenuItem = forwardRef<MenuItemProps, any>(
|
|
|
28
28
|
},
|
|
29
29
|
ref,
|
|
30
30
|
) => {
|
|
31
|
-
const { onClose, itemProps } = useMenuContext();
|
|
31
|
+
const { onClose, itemProps, closeOnSelect } = useMenuContext();
|
|
32
32
|
const clickHandler = (event: MouseEvent) => {
|
|
33
33
|
if (typeof onClick === "function") {
|
|
34
34
|
onClick(event);
|
|
35
35
|
}
|
|
36
|
-
if (typeof onClose === "function") {
|
|
36
|
+
if (typeof onClose === "function" && closeOnSelect) {
|
|
37
37
|
onClose();
|
|
38
38
|
}
|
|
39
39
|
};
|
|
@@ -90,6 +90,10 @@ export interface MenuProps extends Omit<BoxProps, "children"> {
|
|
|
90
90
|
* Should focus lock be disabled
|
|
91
91
|
*/
|
|
92
92
|
disableFocusLock?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* If true, the menu will close when a menu item is clicked.
|
|
95
|
+
*/
|
|
96
|
+
closeOnSelect?: boolean;
|
|
93
97
|
}
|
|
94
98
|
|
|
95
99
|
const MENU_OFFSET = 8;
|
|
@@ -114,6 +118,7 @@ export const MenuRenderer = ({
|
|
|
114
118
|
openMenu: setOpenControlled,
|
|
115
119
|
menuDisplay = "inline-block",
|
|
116
120
|
disableFocusLock = false,
|
|
121
|
+
closeOnSelect = true,
|
|
117
122
|
...rest
|
|
118
123
|
}: MenuProps) => {
|
|
119
124
|
const [isOpenUncontrolled, setOpenUncontrolled] = useState(isOpenInitial);
|
|
@@ -207,6 +212,7 @@ export const MenuRenderer = ({
|
|
|
207
212
|
menuId,
|
|
208
213
|
buttonId,
|
|
209
214
|
placement,
|
|
215
|
+
closeOnSelect,
|
|
210
216
|
...renderProps,
|
|
211
217
|
};
|
|
212
218
|
|
|
@@ -22,6 +22,7 @@ export type MenuContextProps = RenderProps & {
|
|
|
22
22
|
onToggle?: (event: Event | React.MouseEvent<HTMLButtonElement>) => void;
|
|
23
23
|
onOpen?: () => void;
|
|
24
24
|
placement?: PopperPlacement;
|
|
25
|
+
closeOnSelect?: boolean;
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
export const defaultContext: MenuContextProps = {
|
|
@@ -42,6 +43,7 @@ export const defaultContext: MenuContextProps = {
|
|
|
42
43
|
buttonId: "",
|
|
43
44
|
menuId: "",
|
|
44
45
|
placement: "bottom-start",
|
|
46
|
+
closeOnSelect: true,
|
|
45
47
|
};
|
|
46
48
|
|
|
47
49
|
export const MenuContext: Context<typeof defaultContext> = createContext<
|
package/src/contexts/drawer.tsx
CHANGED
|
@@ -5,6 +5,7 @@ interface DrawerContextType {
|
|
|
5
5
|
onClose: () => void;
|
|
6
6
|
isClosedAtRest: boolean;
|
|
7
7
|
drawerSide: "left" | "right";
|
|
8
|
+
isAnimationComplete: boolean;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
const defaultContext: DrawerContextType = {
|
|
@@ -12,6 +13,7 @@ const defaultContext: DrawerContextType = {
|
|
|
12
13
|
onClose: () => {},
|
|
13
14
|
isClosedAtRest: false,
|
|
14
15
|
drawerSide: "left",
|
|
16
|
+
isAnimationComplete: false,
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
export const DrawerContext: Context<DrawerContextType> = createContext<DrawerContextType>(
|