@trackunit/react-drawer 1.0.15 → 1.0.17

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.
Files changed (3) hide show
  1. package/index.cjs.js +13 -16
  2. package/index.esm.js +13 -16
  3. package/package.json +3 -3
package/index.cjs.js CHANGED
@@ -416,37 +416,36 @@ const SNAP_POINT_TRANSITION = "transform 500ms cubic-bezier(0.32,0.72,0,1)";
416
416
  */
417
417
  const SwipeableDrawer = react.forwardRef(({ open, onClose, onOpenGesture, onSnapPointChange, children, keepMountedWhenClosed, className, position = "bottom", snapPoints, activeSnapPoint: activeSnapPointProp = null, container, ...others }, ref) => {
418
418
  const drawerRef = react.useRef(null);
419
- const containerRef = react.useRef(container !== null && container !== void 0 ? container : null);
419
+ const containerRef = react.useRef(container ?? null);
420
420
  const containerGeometry = reactComponents.useGeometry(containerRef);
421
421
  react.useImperativeHandle(ref, () => drawerRef.current);
422
422
  const [activeSnapPoint, setActiveSnapPoint] = react.useState(activeSnapPointProp);
423
423
  const [snapPointOffsets, setSnapPointOffsets] = react.useState([]);
424
424
  const isLastSnapPoint = react.useMemo(() => {
425
- return activeSnapPoint === (snapPoints === null || snapPoints === void 0 ? void 0 : snapPoints[snapPoints.length - 1]);
425
+ return activeSnapPoint === snapPoints?.[snapPoints.length - 1];
426
426
  }, [activeSnapPoint, snapPoints]);
427
427
  const isFirstSnapPoint = react.useMemo(() => {
428
- return activeSnapPoint === (snapPoints === null || snapPoints === void 0 ? void 0 : snapPoints[0]);
428
+ return activeSnapPoint === snapPoints?.[0];
429
429
  }, [activeSnapPoint, snapPoints]);
430
- const activeSnapPointIndex = react.useMemo(() => { var _a; return (_a = snapPoints === null || snapPoints === void 0 ? void 0 : snapPoints.findIndex(snapPoint => snapPoint === activeSnapPoint)) !== null && _a !== void 0 ? _a : -1; }, [snapPoints, activeSnapPoint]);
430
+ const activeSnapPointIndex = react.useMemo(() => snapPoints?.findIndex(snapPoint => snapPoint === activeSnapPoint) ?? -1, [snapPoints, activeSnapPoint]);
431
431
  const onHandleDragEnd = react.useCallback((draggedBy, velocity) => {
432
- var _a, _b, _c;
433
432
  if (!snapPoints || !snapPoints.length) {
434
433
  return;
435
434
  }
436
435
  const direction = draggedBy > 0 ? -1 : 1;
437
436
  // If the velocity is greater than the threshold and the dragged distance is less than 40% of the container height, snap to the next snap point
438
437
  if (velocity > VELOCITY_THRESHOLD && Math.abs(draggedBy) < containerGeometry.height * 0.4) {
439
- const newSnapPoint = (_a = snapPoints[activeSnapPointIndex + direction]) !== null && _a !== void 0 ? _a : null;
438
+ const newSnapPoint = snapPoints[activeSnapPointIndex + direction] ?? null;
440
439
  if (newSnapPoint) {
441
440
  setActiveSnapPoint(newSnapPoint);
442
- onSnapPointChange === null || onSnapPointChange === void 0 ? void 0 : onSnapPointChange(newSnapPoint);
441
+ onSnapPointChange?.(newSnapPoint);
443
442
  }
444
443
  return;
445
444
  }
446
445
  // Otherwise, find the closest snap point
447
446
  // This is when the user is dragging but not swiping.
448
447
  // For example, when the user is dragging the drawer to the bottom but not fast enough to trigger a swipe.
449
- const currentPosition = ((_b = snapPointOffsets[activeSnapPointIndex]) !== null && _b !== void 0 ? _b : 0) + draggedBy;
448
+ const currentPosition = (snapPointOffsets[activeSnapPointIndex] ?? 0) + draggedBy;
450
449
  const closestSnapPoint = snapPointOffsets.reduce((prev, curr) => {
451
450
  if (typeof prev !== "number" || typeof curr !== "number") {
452
451
  return prev;
@@ -454,12 +453,12 @@ const SwipeableDrawer = react.forwardRef(({ open, onClose, onOpenGesture, onSnap
454
453
  return Math.abs(curr - currentPosition) < Math.abs(prev - currentPosition) ? curr : prev;
455
454
  });
456
455
  const snapPointIndex = snapPointOffsets.findIndex(offset => offset === closestSnapPoint);
457
- const nextSnapPoint = (_c = snapPoints[snapPointIndex]) !== null && _c !== void 0 ? _c : null;
456
+ const nextSnapPoint = snapPoints[snapPointIndex] ?? null;
458
457
  if (!nextSnapPoint) {
459
458
  return;
460
459
  }
461
460
  setActiveSnapPoint(nextSnapPoint);
462
- onSnapPointChange === null || onSnapPointChange === void 0 ? void 0 : onSnapPointChange(nextSnapPoint);
461
+ onSnapPointChange?.(nextSnapPoint);
463
462
  }, [snapPoints, snapPointOffsets, activeSnapPointIndex, containerGeometry, onSnapPointChange]);
464
463
  const { handlers, isDragging, dragDistance } = useSwipeHandlers({
465
464
  ref: drawerRef,
@@ -511,17 +510,16 @@ const SwipeableDrawer = react.forwardRef(({ open, onClose, onOpenGesture, onSnap
511
510
  }
512
511
  }, [container]);
513
512
  react.useEffect(() => {
514
- var _a;
515
513
  if (!snapPoints || snapPoints.length === 0) {
516
514
  return;
517
515
  }
518
516
  const snapPointIndex = snapPoints.findIndex(offset => offset === activeSnapPointProp);
519
- const nextSnapPoint = (_a = snapPoints[snapPointIndex > -1 ? snapPointIndex : 0]) !== null && _a !== void 0 ? _a : null;
517
+ const nextSnapPoint = snapPoints[snapPointIndex > -1 ? snapPointIndex : 0] ?? null;
520
518
  if (!nextSnapPoint) {
521
519
  return;
522
520
  }
523
521
  setActiveSnapPoint(nextSnapPoint);
524
- onSnapPointChange === null || onSnapPointChange === void 0 ? void 0 : onSnapPointChange(nextSnapPoint);
522
+ onSnapPointChange?.(nextSnapPoint);
525
523
  }, [snapPoints, activeSnapPointProp, onSnapPointChange]);
526
524
  const drawerStyle = react.useMemo(() => {
527
525
  if (isDragging) {
@@ -539,13 +537,12 @@ const SwipeableDrawer = react.forwardRef(({ open, onClose, onOpenGesture, onSnap
539
537
  return {};
540
538
  }, [isDragging, dragDistance, snapPointOffsets, activeSnapPointIndex, snapPoints]);
541
539
  react.useEffect(() => {
542
- var _a, _b;
543
540
  if (!drawerRef.current) {
544
541
  return;
545
542
  }
546
543
  if (open) {
547
- drawerRef.current.style.transform = (_a = drawerStyle.transform) !== null && _a !== void 0 ? _a : "";
548
- drawerRef.current.style.transition = (_b = drawerStyle.transition) !== null && _b !== void 0 ? _b : "";
544
+ drawerRef.current.style.transform = drawerStyle.transform ?? "";
545
+ drawerRef.current.style.transition = drawerStyle.transition ?? "";
549
546
  }
550
547
  else {
551
548
  drawerRef.current.style.transform = "";
package/index.esm.js CHANGED
@@ -414,37 +414,36 @@ const SNAP_POINT_TRANSITION = "transform 500ms cubic-bezier(0.32,0.72,0,1)";
414
414
  */
415
415
  const SwipeableDrawer = forwardRef(({ open, onClose, onOpenGesture, onSnapPointChange, children, keepMountedWhenClosed, className, position = "bottom", snapPoints, activeSnapPoint: activeSnapPointProp = null, container, ...others }, ref) => {
416
416
  const drawerRef = useRef(null);
417
- const containerRef = useRef(container !== null && container !== void 0 ? container : null);
417
+ const containerRef = useRef(container ?? null);
418
418
  const containerGeometry = useGeometry(containerRef);
419
419
  useImperativeHandle(ref, () => drawerRef.current);
420
420
  const [activeSnapPoint, setActiveSnapPoint] = useState(activeSnapPointProp);
421
421
  const [snapPointOffsets, setSnapPointOffsets] = useState([]);
422
422
  const isLastSnapPoint = useMemo(() => {
423
- return activeSnapPoint === (snapPoints === null || snapPoints === void 0 ? void 0 : snapPoints[snapPoints.length - 1]);
423
+ return activeSnapPoint === snapPoints?.[snapPoints.length - 1];
424
424
  }, [activeSnapPoint, snapPoints]);
425
425
  const isFirstSnapPoint = useMemo(() => {
426
- return activeSnapPoint === (snapPoints === null || snapPoints === void 0 ? void 0 : snapPoints[0]);
426
+ return activeSnapPoint === snapPoints?.[0];
427
427
  }, [activeSnapPoint, snapPoints]);
428
- const activeSnapPointIndex = useMemo(() => { var _a; return (_a = snapPoints === null || snapPoints === void 0 ? void 0 : snapPoints.findIndex(snapPoint => snapPoint === activeSnapPoint)) !== null && _a !== void 0 ? _a : -1; }, [snapPoints, activeSnapPoint]);
428
+ const activeSnapPointIndex = useMemo(() => snapPoints?.findIndex(snapPoint => snapPoint === activeSnapPoint) ?? -1, [snapPoints, activeSnapPoint]);
429
429
  const onHandleDragEnd = useCallback((draggedBy, velocity) => {
430
- var _a, _b, _c;
431
430
  if (!snapPoints || !snapPoints.length) {
432
431
  return;
433
432
  }
434
433
  const direction = draggedBy > 0 ? -1 : 1;
435
434
  // If the velocity is greater than the threshold and the dragged distance is less than 40% of the container height, snap to the next snap point
436
435
  if (velocity > VELOCITY_THRESHOLD && Math.abs(draggedBy) < containerGeometry.height * 0.4) {
437
- const newSnapPoint = (_a = snapPoints[activeSnapPointIndex + direction]) !== null && _a !== void 0 ? _a : null;
436
+ const newSnapPoint = snapPoints[activeSnapPointIndex + direction] ?? null;
438
437
  if (newSnapPoint) {
439
438
  setActiveSnapPoint(newSnapPoint);
440
- onSnapPointChange === null || onSnapPointChange === void 0 ? void 0 : onSnapPointChange(newSnapPoint);
439
+ onSnapPointChange?.(newSnapPoint);
441
440
  }
442
441
  return;
443
442
  }
444
443
  // Otherwise, find the closest snap point
445
444
  // This is when the user is dragging but not swiping.
446
445
  // For example, when the user is dragging the drawer to the bottom but not fast enough to trigger a swipe.
447
- const currentPosition = ((_b = snapPointOffsets[activeSnapPointIndex]) !== null && _b !== void 0 ? _b : 0) + draggedBy;
446
+ const currentPosition = (snapPointOffsets[activeSnapPointIndex] ?? 0) + draggedBy;
448
447
  const closestSnapPoint = snapPointOffsets.reduce((prev, curr) => {
449
448
  if (typeof prev !== "number" || typeof curr !== "number") {
450
449
  return prev;
@@ -452,12 +451,12 @@ const SwipeableDrawer = forwardRef(({ open, onClose, onOpenGesture, onSnapPointC
452
451
  return Math.abs(curr - currentPosition) < Math.abs(prev - currentPosition) ? curr : prev;
453
452
  });
454
453
  const snapPointIndex = snapPointOffsets.findIndex(offset => offset === closestSnapPoint);
455
- const nextSnapPoint = (_c = snapPoints[snapPointIndex]) !== null && _c !== void 0 ? _c : null;
454
+ const nextSnapPoint = snapPoints[snapPointIndex] ?? null;
456
455
  if (!nextSnapPoint) {
457
456
  return;
458
457
  }
459
458
  setActiveSnapPoint(nextSnapPoint);
460
- onSnapPointChange === null || onSnapPointChange === void 0 ? void 0 : onSnapPointChange(nextSnapPoint);
459
+ onSnapPointChange?.(nextSnapPoint);
461
460
  }, [snapPoints, snapPointOffsets, activeSnapPointIndex, containerGeometry, onSnapPointChange]);
462
461
  const { handlers, isDragging, dragDistance } = useSwipeHandlers({
463
462
  ref: drawerRef,
@@ -509,17 +508,16 @@ const SwipeableDrawer = forwardRef(({ open, onClose, onOpenGesture, onSnapPointC
509
508
  }
510
509
  }, [container]);
511
510
  useEffect(() => {
512
- var _a;
513
511
  if (!snapPoints || snapPoints.length === 0) {
514
512
  return;
515
513
  }
516
514
  const snapPointIndex = snapPoints.findIndex(offset => offset === activeSnapPointProp);
517
- const nextSnapPoint = (_a = snapPoints[snapPointIndex > -1 ? snapPointIndex : 0]) !== null && _a !== void 0 ? _a : null;
515
+ const nextSnapPoint = snapPoints[snapPointIndex > -1 ? snapPointIndex : 0] ?? null;
518
516
  if (!nextSnapPoint) {
519
517
  return;
520
518
  }
521
519
  setActiveSnapPoint(nextSnapPoint);
522
- onSnapPointChange === null || onSnapPointChange === void 0 ? void 0 : onSnapPointChange(nextSnapPoint);
520
+ onSnapPointChange?.(nextSnapPoint);
523
521
  }, [snapPoints, activeSnapPointProp, onSnapPointChange]);
524
522
  const drawerStyle = useMemo(() => {
525
523
  if (isDragging) {
@@ -537,13 +535,12 @@ const SwipeableDrawer = forwardRef(({ open, onClose, onOpenGesture, onSnapPointC
537
535
  return {};
538
536
  }, [isDragging, dragDistance, snapPointOffsets, activeSnapPointIndex, snapPoints]);
539
537
  useEffect(() => {
540
- var _a, _b;
541
538
  if (!drawerRef.current) {
542
539
  return;
543
540
  }
544
541
  if (open) {
545
- drawerRef.current.style.transform = (_a = drawerStyle.transform) !== null && _a !== void 0 ? _a : "";
546
- drawerRef.current.style.transition = (_b = drawerStyle.transition) !== null && _b !== void 0 ? _b : "";
542
+ drawerRef.current.style.transform = drawerStyle.transform ?? "";
543
+ drawerRef.current.style.transition = drawerStyle.transition ?? "";
547
544
  }
548
545
  else {
549
546
  drawerRef.current.style.transform = "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-drawer",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
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": "18.3.1",
11
11
  "react-swipeable": "^7.0.1",
12
- "@trackunit/react-components": "^1.0.13",
12
+ "@trackunit/react-components": "^1.1.0",
13
13
  "@trackunit/css-class-variance-utilities": "^1.0.1",
14
14
  "@trackunit/ui-icons": "^1.0.3",
15
- "@trackunit/i18n-library-translation": "^1.0.7"
15
+ "@trackunit/i18n-library-translation": "^1.0.8"
16
16
  },
17
17
  "module": "./index.esm.js",
18
18
  "main": "./index.cjs.js",