@conveyorhq/arrow-ds 1.141.0 → 1.142.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 CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@conveyorhq/arrow-ds",
3
3
  "author": "Conveyor",
4
4
  "license": "MIT",
5
- "version": "1.141.0",
5
+ "version": "1.142.0",
6
6
  "description": "Arrow Design System",
7
7
  "repository": "https://github.com/conveyor/arrow-ds",
8
8
  "publishConfig": {
@@ -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: { isOpen, onClose, isClosedAtRest, drawerSide } },
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;
@@ -4,6 +4,7 @@ interface DrawerContextType {
4
4
  onClose: () => void;
5
5
  isClosedAtRest: boolean;
6
6
  drawerSide: "left" | "right";
7
+ isAnimationComplete: boolean;
7
8
  }
8
9
  export declare const DrawerContext: Context<DrawerContextType>;
9
10
  export {};
@@ -7,5 +7,6 @@ const defaultContext = {
7
7
  onClose: () => { },
8
8
  isClosedAtRest: false,
9
9
  drawerSide: "left",
10
+ isAnimationComplete: false,
10
11
  };
11
12
  exports.DrawerContext = (0, react_1.createContext)(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={{ isOpen, onClose, isClosedAtRest, drawerSide }}
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 && (
@@ -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>(