@trackunit/react-drawer 1.15.11 → 1.15.15
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 +24 -11
- package/index.esm.js +25 -12
- package/package.json +5 -5
package/index.cjs.js
CHANGED
|
@@ -185,6 +185,18 @@ const cvaDrawerContent = cssClassVarianceUtilities.cvaMerge(["flex", "flex-col",
|
|
|
185
185
|
const TRANSITION_DURATION = 100;
|
|
186
186
|
const DEFAULT_POSITION = "left";
|
|
187
187
|
const NOOP$1 = () => void 0;
|
|
188
|
+
const drawerReducer = (state, action) => {
|
|
189
|
+
switch (action.type) {
|
|
190
|
+
case "open":
|
|
191
|
+
return { shouldRender: true, mode: "open" };
|
|
192
|
+
case "close":
|
|
193
|
+
return { ...state, mode: "closed" };
|
|
194
|
+
case "transitionEnd":
|
|
195
|
+
return state.mode === "closed" ? { ...state, shouldRender: false } : state;
|
|
196
|
+
default:
|
|
197
|
+
return state;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
188
200
|
/**
|
|
189
201
|
* Drawers components can be switched between open and closed states.
|
|
190
202
|
* They start closed but can be temporarily opened, appearing on top of other content until the user chooses a section.
|
|
@@ -246,34 +258,35 @@ const Drawer = ({ open = false, // Default to closed
|
|
|
246
258
|
onClose = NOOP$1, onOpen = NOOP$1, hasOverlay = true, position = DEFAULT_POSITION, children, "data-testid": dataTestId, className, renderInPortal = false, keepMountedWhenClosed = false, containerClassName, ref, ...others }) => {
|
|
247
259
|
const { isSm } = reactComponents.useViewportBreakpoints();
|
|
248
260
|
const shouldUsePortal = !isSm || renderInPortal;
|
|
249
|
-
const [
|
|
250
|
-
|
|
261
|
+
const [drawerState, dispatch] = react.useReducer(drawerReducer, {
|
|
262
|
+
shouldRender: open,
|
|
263
|
+
mode: open ? "open" : "closed",
|
|
264
|
+
});
|
|
251
265
|
const onOpenRef = react.useRef(onOpen);
|
|
252
266
|
react.useEffect(() => {
|
|
253
267
|
onOpenRef.current = onOpen;
|
|
254
268
|
}, [onOpen]);
|
|
255
269
|
react.useEffect(() => {
|
|
256
270
|
if (open) {
|
|
257
|
-
|
|
271
|
+
dispatch({ type: "open" });
|
|
258
272
|
setTimeout(() => {
|
|
259
|
-
setMode("open");
|
|
260
273
|
onOpenRef.current();
|
|
261
274
|
}, TRANSITION_DURATION);
|
|
262
275
|
}
|
|
263
276
|
else {
|
|
264
|
-
|
|
277
|
+
dispatch({ type: "close" });
|
|
265
278
|
}
|
|
266
279
|
}, [open]);
|
|
267
280
|
const handleAnimationEnd = react.useCallback((transitionEvent) => {
|
|
268
|
-
if (
|
|
269
|
-
|
|
281
|
+
if (transitionEvent.propertyName === "transform") {
|
|
282
|
+
dispatch({ type: "transitionEnd" });
|
|
270
283
|
}
|
|
271
|
-
}, [
|
|
272
|
-
if (!shouldRender && !keepMountedWhenClosed) {
|
|
284
|
+
}, []);
|
|
285
|
+
if (!drawerState.shouldRender && !keepMountedWhenClosed) {
|
|
273
286
|
return null;
|
|
274
287
|
}
|
|
275
|
-
const content = (jsxRuntime.jsxs("div", { className: containerClassName, children: [hasOverlay ? jsxRuntime.jsx(Overlay, { onClose: onClose, open: mode === "open" }) : null, jsxRuntime.jsx("div", { className: cvaDrawer({
|
|
276
|
-
mode,
|
|
288
|
+
const content = (jsxRuntime.jsxs("div", { className: containerClassName, children: [hasOverlay ? jsxRuntime.jsx(Overlay, { onClose: onClose, open: drawerState.mode === "open" }) : null, jsxRuntime.jsx("div", { className: cvaDrawer({
|
|
289
|
+
mode: drawerState.mode,
|
|
277
290
|
position: position,
|
|
278
291
|
className,
|
|
279
292
|
}), "data-testid": dataTestId, onTransitionEnd: handleAnimationEnd, ref: ref, ...others, children: jsxRuntime.jsx("div", { className: cvaDrawerContent({ position }), children: children }) })] }));
|
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, useMeasure, useMergeRefs, useScrollBlock } from '@trackunit/react-components';
|
|
4
|
-
import { useEffect,
|
|
4
|
+
import { useEffect, useReducer, useRef, useCallback, useState, useMemo, useImperativeHandle } from 'react';
|
|
5
5
|
import { cvaMerge } from '@trackunit/css-class-variance-utilities';
|
|
6
6
|
import { useSwipeable } from 'react-swipeable';
|
|
7
7
|
|
|
@@ -183,6 +183,18 @@ const cvaDrawerContent = cvaMerge(["flex", "flex-col", "h-full", "shadow-lg"], {
|
|
|
183
183
|
const TRANSITION_DURATION = 100;
|
|
184
184
|
const DEFAULT_POSITION = "left";
|
|
185
185
|
const NOOP$1 = () => void 0;
|
|
186
|
+
const drawerReducer = (state, action) => {
|
|
187
|
+
switch (action.type) {
|
|
188
|
+
case "open":
|
|
189
|
+
return { shouldRender: true, mode: "open" };
|
|
190
|
+
case "close":
|
|
191
|
+
return { ...state, mode: "closed" };
|
|
192
|
+
case "transitionEnd":
|
|
193
|
+
return state.mode === "closed" ? { ...state, shouldRender: false } : state;
|
|
194
|
+
default:
|
|
195
|
+
return state;
|
|
196
|
+
}
|
|
197
|
+
};
|
|
186
198
|
/**
|
|
187
199
|
* Drawers components can be switched between open and closed states.
|
|
188
200
|
* They start closed but can be temporarily opened, appearing on top of other content until the user chooses a section.
|
|
@@ -244,34 +256,35 @@ const Drawer = ({ open = false, // Default to closed
|
|
|
244
256
|
onClose = NOOP$1, onOpen = NOOP$1, hasOverlay = true, position = DEFAULT_POSITION, children, "data-testid": dataTestId, className, renderInPortal = false, keepMountedWhenClosed = false, containerClassName, ref, ...others }) => {
|
|
245
257
|
const { isSm } = useViewportBreakpoints();
|
|
246
258
|
const shouldUsePortal = !isSm || renderInPortal;
|
|
247
|
-
const [
|
|
248
|
-
|
|
259
|
+
const [drawerState, dispatch] = useReducer(drawerReducer, {
|
|
260
|
+
shouldRender: open,
|
|
261
|
+
mode: open ? "open" : "closed",
|
|
262
|
+
});
|
|
249
263
|
const onOpenRef = useRef(onOpen);
|
|
250
264
|
useEffect(() => {
|
|
251
265
|
onOpenRef.current = onOpen;
|
|
252
266
|
}, [onOpen]);
|
|
253
267
|
useEffect(() => {
|
|
254
268
|
if (open) {
|
|
255
|
-
|
|
269
|
+
dispatch({ type: "open" });
|
|
256
270
|
setTimeout(() => {
|
|
257
|
-
setMode("open");
|
|
258
271
|
onOpenRef.current();
|
|
259
272
|
}, TRANSITION_DURATION);
|
|
260
273
|
}
|
|
261
274
|
else {
|
|
262
|
-
|
|
275
|
+
dispatch({ type: "close" });
|
|
263
276
|
}
|
|
264
277
|
}, [open]);
|
|
265
278
|
const handleAnimationEnd = useCallback((transitionEvent) => {
|
|
266
|
-
if (
|
|
267
|
-
|
|
279
|
+
if (transitionEvent.propertyName === "transform") {
|
|
280
|
+
dispatch({ type: "transitionEnd" });
|
|
268
281
|
}
|
|
269
|
-
}, [
|
|
270
|
-
if (!shouldRender && !keepMountedWhenClosed) {
|
|
282
|
+
}, []);
|
|
283
|
+
if (!drawerState.shouldRender && !keepMountedWhenClosed) {
|
|
271
284
|
return null;
|
|
272
285
|
}
|
|
273
|
-
const content = (jsxs("div", { className: containerClassName, children: [hasOverlay ? jsx(Overlay, { onClose: onClose, open: mode === "open" }) : null, jsx("div", { className: cvaDrawer({
|
|
274
|
-
mode,
|
|
286
|
+
const content = (jsxs("div", { className: containerClassName, children: [hasOverlay ? jsx(Overlay, { onClose: onClose, open: drawerState.mode === "open" }) : null, jsx("div", { className: cvaDrawer({
|
|
287
|
+
mode: drawerState.mode,
|
|
275
288
|
position: position,
|
|
276
289
|
className,
|
|
277
290
|
}), "data-testid": dataTestId, onTransitionEnd: handleAnimationEnd, ref: ref, ...others, children: jsx("div", { className: cvaDrawerContent({ position }), children: children }) })] }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-drawer",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.15",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"react": "19.0.0",
|
|
11
11
|
"react-swipeable": "^7.0.1",
|
|
12
|
-
"@trackunit/react-components": "1.18.
|
|
13
|
-
"@trackunit/css-class-variance-utilities": "1.11.
|
|
14
|
-
"@trackunit/ui-icons": "1.11.
|
|
15
|
-
"@trackunit/i18n-library-translation": "1.13.
|
|
12
|
+
"@trackunit/react-components": "1.18.22",
|
|
13
|
+
"@trackunit/css-class-variance-utilities": "1.11.75",
|
|
14
|
+
"@trackunit/ui-icons": "1.11.72",
|
|
15
|
+
"@trackunit/i18n-library-translation": "1.13.13"
|
|
16
16
|
},
|
|
17
17
|
"module": "./index.esm.js",
|
|
18
18
|
"main": "./index.cjs.js",
|