@trackunit/react-drawer 1.3.25 → 1.3.29
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/index.cjs.js +8 -10
- package/index.esm.js +9 -11
- package/package.json +6 -6
- package/src/components/Drawer/Drawer.d.ts +9 -2
- package/src/components/Overlay/Overlay.d.ts +3 -2
- package/src/components/SwipeableDrawer/DrawerPuller.d.ts +7 -2
- package/src/components/SwipeableDrawer/SwipeableDrawer.d.ts +9 -1
- package/src/hooks/useSwipeHandlers.d.ts +1 -1
package/index.cjs.js
CHANGED
|
@@ -55,7 +55,7 @@ const setupLibraryTranslations = () => {
|
|
|
55
55
|
* @param {object} props - The Overlay component properties
|
|
56
56
|
* @param {boolean} props.open - Open status of the Overlay
|
|
57
57
|
* @param {Function} props.onClose - Callback function when Overlay is closed
|
|
58
|
-
* @returns {
|
|
58
|
+
* @returns {ReactElement|null} The Overlay component
|
|
59
59
|
*/
|
|
60
60
|
const Overlay = ({ open, onClose }) => {
|
|
61
61
|
react.useEffect(() => {
|
|
@@ -182,10 +182,9 @@ const NOOP$1 = () => void 0;
|
|
|
182
182
|
* To close the drawer, users can either click outside of it or press the Esc key.
|
|
183
183
|
*
|
|
184
184
|
* @param {DrawerProps} props - The props for the Drawer component
|
|
185
|
-
* @returns {JSX.Element | null} Drawer component
|
|
186
185
|
*/
|
|
187
|
-
const Drawer =
|
|
188
|
-
onClose = NOOP$1, hasOverlay = true, position = DEFAULT_POSITION, children, dataTestId, className, renderInPortal = false, keepMountedWhenClosed = false, containerClassName, ...others }
|
|
186
|
+
const Drawer = ({ open = false, // Default to closed
|
|
187
|
+
onClose = NOOP$1, hasOverlay = true, position = DEFAULT_POSITION, children, dataTestId, className, renderInPortal = false, keepMountedWhenClosed = false, containerClassName, ref, ...others }) => {
|
|
189
188
|
const { isSm } = reactComponents.useViewportBreakpoints();
|
|
190
189
|
const shouldUsePortal = !isSm || renderInPortal;
|
|
191
190
|
const [shouldRender, setShouldRender] = react.useState(open);
|
|
@@ -213,7 +212,7 @@ onClose = NOOP$1, hasOverlay = true, position = DEFAULT_POSITION, children, data
|
|
|
213
212
|
className,
|
|
214
213
|
}), "data-testid": dataTestId, onTransitionEnd: handleAnimationEnd, ref: ref, ...others, children: jsxRuntime.jsx("div", { className: cvaDrawerContent({ position }), children: children }) })] }));
|
|
215
214
|
return shouldUsePortal ? jsxRuntime.jsx(reactComponents.Portal, { children: content }) : content;
|
|
216
|
-
}
|
|
215
|
+
};
|
|
217
216
|
Drawer.displayName = "Drawer";
|
|
218
217
|
|
|
219
218
|
const NOOP = () => void 0;
|
|
@@ -406,11 +405,10 @@ const useSwipeHandlers = ({ ref, closingThreshold, onCloseGesture, onOpenGesture
|
|
|
406
405
|
* @param {CommonProps} props - The props for the DrawerPuller component.
|
|
407
406
|
* @param {string} [props.className] - Additional class names to apply to the puller element.
|
|
408
407
|
* @param {Ref<HTMLDivElement>} ref - The ref to be forwarded to the root div element.
|
|
409
|
-
* @returns {JSX.Element} The rendered DrawerPuller component.
|
|
410
408
|
*/
|
|
411
|
-
const DrawerPuller =
|
|
409
|
+
const DrawerPuller = ({ className, ref, ...props }) => {
|
|
412
410
|
return (jsxRuntime.jsx("div", { className: cvaPuller({ className }), "data-testid": "drawer-puller", ...props, ref: ref, children: jsxRuntime.jsx("div", { className: cvaPullerIcon() }) }));
|
|
413
|
-
}
|
|
411
|
+
};
|
|
414
412
|
DrawerPuller.displayName = "DrawerPuller";
|
|
415
413
|
const cvaPuller = cssClassVarianceUtilities.cvaMerge(["pt-1", "pb-4", "flex", "items-center", "justify-center"]);
|
|
416
414
|
const cvaPullerIcon = cssClassVarianceUtilities.cvaMerge(["block", "h-1", "w-8", "rounded-full", "bg-gray-400"]);
|
|
@@ -425,7 +423,7 @@ const SNAP_POINT_TRANSITION = "transform 500ms cubic-bezier(0.32,0.72,0,1)";
|
|
|
425
423
|
* The component manages its docked state based on the open prop and keepMountedWhenClosed prop.
|
|
426
424
|
* It also applies styles dynamically based on whether the drawer is being dragged.
|
|
427
425
|
*/
|
|
428
|
-
const SwipeableDrawer =
|
|
426
|
+
const SwipeableDrawer = ({ open, onClose, onOpenGesture, onSnapPointChange, children, keepMountedWhenClosed, className, position = "bottom", snapPoints, activeSnapPoint: activeSnapPointProp = null, container, ref, ...others }) => {
|
|
429
427
|
const drawerRef = react.useRef(null);
|
|
430
428
|
const containerRef = react.useRef(container ?? null);
|
|
431
429
|
const containerGeometry = reactComponents.useGeometry(containerRef);
|
|
@@ -561,7 +559,7 @@ const SwipeableDrawer = react.forwardRef(({ open, onClose, onOpenGesture, onSnap
|
|
|
561
559
|
}
|
|
562
560
|
}, [drawerStyle, drawerRef, open]);
|
|
563
561
|
return (jsxRuntime.jsxs(Drawer, { className: cvaSwipeableDrawer({ className }), keepMountedWhenClosed: keepMountedWhenClosed, onClose: onClose, open: open, position: position, ref: drawerRef, ...others, children: [jsxRuntime.jsx(DrawerPuller, { ...handlers }), children] }));
|
|
564
|
-
}
|
|
562
|
+
};
|
|
565
563
|
SwipeableDrawer.displayName = "SwipeableDrawer";
|
|
566
564
|
const cvaSwipeableDrawer = cssClassVarianceUtilities.cvaMerge([]);
|
|
567
565
|
|
package/index.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { registerTranslations } from '@trackunit/i18n-library-translation';
|
|
3
3
|
import { useViewportBreakpoints, Portal, Icon, useGeometry } from '@trackunit/react-components';
|
|
4
|
-
import { useEffect,
|
|
4
|
+
import { useEffect, useState, useCallback, useRef, useImperativeHandle, useMemo } from 'react';
|
|
5
5
|
import { cvaMerge } from '@trackunit/css-class-variance-utilities';
|
|
6
6
|
import { useSwipeable } from 'react-swipeable';
|
|
7
7
|
|
|
@@ -53,7 +53,7 @@ const setupLibraryTranslations = () => {
|
|
|
53
53
|
* @param {object} props - The Overlay component properties
|
|
54
54
|
* @param {boolean} props.open - Open status of the Overlay
|
|
55
55
|
* @param {Function} props.onClose - Callback function when Overlay is closed
|
|
56
|
-
* @returns {
|
|
56
|
+
* @returns {ReactElement|null} The Overlay component
|
|
57
57
|
*/
|
|
58
58
|
const Overlay = ({ open, onClose }) => {
|
|
59
59
|
useEffect(() => {
|
|
@@ -180,10 +180,9 @@ const NOOP$1 = () => void 0;
|
|
|
180
180
|
* To close the drawer, users can either click outside of it or press the Esc key.
|
|
181
181
|
*
|
|
182
182
|
* @param {DrawerProps} props - The props for the Drawer component
|
|
183
|
-
* @returns {JSX.Element | null} Drawer component
|
|
184
183
|
*/
|
|
185
|
-
const Drawer =
|
|
186
|
-
onClose = NOOP$1, hasOverlay = true, position = DEFAULT_POSITION, children, dataTestId, className, renderInPortal = false, keepMountedWhenClosed = false, containerClassName, ...others }
|
|
184
|
+
const Drawer = ({ open = false, // Default to closed
|
|
185
|
+
onClose = NOOP$1, hasOverlay = true, position = DEFAULT_POSITION, children, dataTestId, className, renderInPortal = false, keepMountedWhenClosed = false, containerClassName, ref, ...others }) => {
|
|
187
186
|
const { isSm } = useViewportBreakpoints();
|
|
188
187
|
const shouldUsePortal = !isSm || renderInPortal;
|
|
189
188
|
const [shouldRender, setShouldRender] = useState(open);
|
|
@@ -211,7 +210,7 @@ onClose = NOOP$1, hasOverlay = true, position = DEFAULT_POSITION, children, data
|
|
|
211
210
|
className,
|
|
212
211
|
}), "data-testid": dataTestId, onTransitionEnd: handleAnimationEnd, ref: ref, ...others, children: jsx("div", { className: cvaDrawerContent({ position }), children: children }) })] }));
|
|
213
212
|
return shouldUsePortal ? jsx(Portal, { children: content }) : content;
|
|
214
|
-
}
|
|
213
|
+
};
|
|
215
214
|
Drawer.displayName = "Drawer";
|
|
216
215
|
|
|
217
216
|
const NOOP = () => void 0;
|
|
@@ -404,11 +403,10 @@ const useSwipeHandlers = ({ ref, closingThreshold, onCloseGesture, onOpenGesture
|
|
|
404
403
|
* @param {CommonProps} props - The props for the DrawerPuller component.
|
|
405
404
|
* @param {string} [props.className] - Additional class names to apply to the puller element.
|
|
406
405
|
* @param {Ref<HTMLDivElement>} ref - The ref to be forwarded to the root div element.
|
|
407
|
-
* @returns {JSX.Element} The rendered DrawerPuller component.
|
|
408
406
|
*/
|
|
409
|
-
const DrawerPuller =
|
|
407
|
+
const DrawerPuller = ({ className, ref, ...props }) => {
|
|
410
408
|
return (jsx("div", { className: cvaPuller({ className }), "data-testid": "drawer-puller", ...props, ref: ref, children: jsx("div", { className: cvaPullerIcon() }) }));
|
|
411
|
-
}
|
|
409
|
+
};
|
|
412
410
|
DrawerPuller.displayName = "DrawerPuller";
|
|
413
411
|
const cvaPuller = cvaMerge(["pt-1", "pb-4", "flex", "items-center", "justify-center"]);
|
|
414
412
|
const cvaPullerIcon = cvaMerge(["block", "h-1", "w-8", "rounded-full", "bg-gray-400"]);
|
|
@@ -423,7 +421,7 @@ const SNAP_POINT_TRANSITION = "transform 500ms cubic-bezier(0.32,0.72,0,1)";
|
|
|
423
421
|
* The component manages its docked state based on the open prop and keepMountedWhenClosed prop.
|
|
424
422
|
* It also applies styles dynamically based on whether the drawer is being dragged.
|
|
425
423
|
*/
|
|
426
|
-
const SwipeableDrawer =
|
|
424
|
+
const SwipeableDrawer = ({ open, onClose, onOpenGesture, onSnapPointChange, children, keepMountedWhenClosed, className, position = "bottom", snapPoints, activeSnapPoint: activeSnapPointProp = null, container, ref, ...others }) => {
|
|
427
425
|
const drawerRef = useRef(null);
|
|
428
426
|
const containerRef = useRef(container ?? null);
|
|
429
427
|
const containerGeometry = useGeometry(containerRef);
|
|
@@ -559,7 +557,7 @@ const SwipeableDrawer = forwardRef(({ open, onClose, onOpenGesture, onSnapPointC
|
|
|
559
557
|
}
|
|
560
558
|
}, [drawerStyle, drawerRef, open]);
|
|
561
559
|
return (jsxs(Drawer, { className: cvaSwipeableDrawer({ className }), keepMountedWhenClosed: keepMountedWhenClosed, onClose: onClose, open: open, position: position, ref: drawerRef, ...others, children: [jsx(DrawerPuller, { ...handlers }), children] }));
|
|
562
|
-
}
|
|
560
|
+
};
|
|
563
561
|
SwipeableDrawer.displayName = "SwipeableDrawer";
|
|
564
562
|
const cvaSwipeableDrawer = cvaMerge([]);
|
|
565
563
|
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-drawer",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.29",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=20.x"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"react": "
|
|
10
|
+
"react": "19.0.0",
|
|
11
11
|
"react-swipeable": "^7.0.1",
|
|
12
|
-
"@trackunit/react-components": "1.4.
|
|
13
|
-
"@trackunit/css-class-variance-utilities": "1.3.
|
|
14
|
-
"@trackunit/ui-icons": "1.3.
|
|
15
|
-
"@trackunit/i18n-library-translation": "1.3.
|
|
12
|
+
"@trackunit/react-components": "1.4.27",
|
|
13
|
+
"@trackunit/css-class-variance-utilities": "1.3.27",
|
|
14
|
+
"@trackunit/ui-icons": "1.3.27",
|
|
15
|
+
"@trackunit/i18n-library-translation": "1.3.28"
|
|
16
16
|
},
|
|
17
17
|
"module": "./index.esm.js",
|
|
18
18
|
"main": "./index.cjs.js",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CommonProps } from "@trackunit/react-components";
|
|
2
|
+
import { Ref } from "react";
|
|
2
3
|
import type { DrawerPosition } from "../../types";
|
|
3
4
|
export declare const TRANSITION_DURATION = 100;
|
|
4
5
|
export interface DrawerRefsHandle {
|
|
@@ -45,6 +46,10 @@ export interface DrawerProps extends CommonProps {
|
|
|
45
46
|
* The class name for the drawer container.
|
|
46
47
|
*/
|
|
47
48
|
containerClassName?: string;
|
|
49
|
+
/**
|
|
50
|
+
* A ref for the component
|
|
51
|
+
*/
|
|
52
|
+
ref?: Ref<HTMLDivElement>;
|
|
48
53
|
}
|
|
49
54
|
/**
|
|
50
55
|
* Drawers components can be switched between open and closed states.
|
|
@@ -52,6 +57,8 @@ export interface DrawerProps extends CommonProps {
|
|
|
52
57
|
* To close the drawer, users can either click outside of it or press the Esc key.
|
|
53
58
|
*
|
|
54
59
|
* @param {DrawerProps} props - The props for the Drawer component
|
|
55
|
-
* @returns {JSX.Element | null} Drawer component
|
|
56
60
|
*/
|
|
57
|
-
export declare const Drawer:
|
|
61
|
+
export declare const Drawer: {
|
|
62
|
+
({ open, onClose, hasOverlay, position, children, dataTestId, className, renderInPortal, keepMountedWhenClosed, containerClassName, ref, ...others }: DrawerProps): import("react/jsx-runtime").JSX.Element | null;
|
|
63
|
+
displayName: string;
|
|
64
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ReactElement } from "react";
|
|
1
2
|
interface OverlayProps {
|
|
2
3
|
open: boolean;
|
|
3
4
|
onClose?: () => void;
|
|
@@ -8,7 +9,7 @@ interface OverlayProps {
|
|
|
8
9
|
* @param {object} props - The Overlay component properties
|
|
9
10
|
* @param {boolean} props.open - Open status of the Overlay
|
|
10
11
|
* @param {Function} props.onClose - Callback function when Overlay is closed
|
|
11
|
-
* @returns {
|
|
12
|
+
* @returns {ReactElement|null} The Overlay component
|
|
12
13
|
*/
|
|
13
|
-
export declare const Overlay: ({ open, onClose }: OverlayProps) =>
|
|
14
|
+
export declare const Overlay: ({ open, onClose }: OverlayProps) => ReactElement | null;
|
|
14
15
|
export {};
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { CommonProps } from "@trackunit/react-components";
|
|
2
|
+
import { type Ref } from "react";
|
|
2
3
|
/**
|
|
3
4
|
* DrawerPuller is a React component that renders a puller element for a swipeable drawer.
|
|
4
5
|
*
|
|
5
6
|
* @param {CommonProps} props - The props for the DrawerPuller component.
|
|
6
7
|
* @param {string} [props.className] - Additional class names to apply to the puller element.
|
|
7
8
|
* @param {Ref<HTMLDivElement>} ref - The ref to be forwarded to the root div element.
|
|
8
|
-
* @returns {JSX.Element} The rendered DrawerPuller component.
|
|
9
9
|
*/
|
|
10
|
-
export declare const DrawerPuller:
|
|
10
|
+
export declare const DrawerPuller: {
|
|
11
|
+
({ className, ref, ...props }: CommonProps & {
|
|
12
|
+
ref?: Ref<HTMLDivElement>;
|
|
13
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
displayName: string;
|
|
15
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Ref } from "react";
|
|
1
2
|
import { type DrawerProps } from "../Drawer/Drawer";
|
|
2
3
|
export interface SwipeableDrawerProps extends DrawerProps {
|
|
3
4
|
onOpenGesture?: () => void;
|
|
@@ -5,6 +6,10 @@ export interface SwipeableDrawerProps extends DrawerProps {
|
|
|
5
6
|
snapPoints?: (number | string)[];
|
|
6
7
|
activeSnapPoint?: number | string | null;
|
|
7
8
|
container?: HTMLElement | null;
|
|
9
|
+
/**
|
|
10
|
+
* A ref for the component
|
|
11
|
+
*/
|
|
12
|
+
ref?: Ref<HTMLDivElement>;
|
|
8
13
|
}
|
|
9
14
|
/**
|
|
10
15
|
*
|
|
@@ -13,5 +18,8 @@ export interface SwipeableDrawerProps extends DrawerProps {
|
|
|
13
18
|
* The component manages its docked state based on the open prop and keepMountedWhenClosed prop.
|
|
14
19
|
* It also applies styles dynamically based on whether the drawer is being dragged.
|
|
15
20
|
*/
|
|
16
|
-
export declare const SwipeableDrawer:
|
|
21
|
+
export declare const SwipeableDrawer: {
|
|
22
|
+
({ open, onClose, onOpenGesture, onSnapPointChange, children, keepMountedWhenClosed, className, position, snapPoints, activeSnapPoint: activeSnapPointProp, container, ref, ...others }: SwipeableDrawerProps): import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
displayName: string;
|
|
24
|
+
};
|
|
17
25
|
export declare const cvaSwipeableDrawer: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
|