@seed-design/react-drawer 1.0.6 → 1.0.7
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/lib/{Drawer-12s-BdeYHia6.js → Drawer-12s-1gup1cyj.js} +10 -51
- package/lib/{Drawer-12s-DriAYAR2.cjs → Drawer-12s-L4KZ1h_g.cjs} +8 -50
- package/lib/index.cjs +1 -3
- package/lib/index.d.ts +30 -39
- package/lib/index.js +3 -4
- package/package.json +1 -1
- package/src/Drawer.namespace.ts +0 -2
- package/src/Drawer.tsx +6 -27
- package/src/index.ts +0 -2
- package/src/useDrawer.ts +0 -32
|
@@ -5,7 +5,7 @@ import * as DialogPrimitive from '@radix-ui/react-dialog';
|
|
|
5
5
|
import { useCallbackRef } from '@radix-ui/react-use-callback-ref';
|
|
6
6
|
import { dataAttr } from '@seed-design/dom-utils';
|
|
7
7
|
import { Primitive } from '@seed-design/react-primitive';
|
|
8
|
-
import React, { useState,
|
|
8
|
+
import React, { useState, useRef, useCallback, useEffect, useMemo, createContext, useContext, forwardRef } from 'react';
|
|
9
9
|
import { useControllableState } from '@radix-ui/react-use-controllable-state';
|
|
10
10
|
|
|
11
11
|
function isMobileFirefox() {
|
|
@@ -482,13 +482,8 @@ function useDrawer(props) {
|
|
|
482
482
|
}
|
|
483
483
|
});
|
|
484
484
|
const [hasBeenOpened, setHasBeenOpened] = useState(false);
|
|
485
|
-
const [hasAnimationDone, setHasAnimationDone] = useState(false);
|
|
486
485
|
const [isDragging, setIsDragging] = useState(false);
|
|
487
486
|
const [shouldOverlayAnimate, setShouldOverlayAnimate] = useState(false);
|
|
488
|
-
const [isCloseButtonRendered, setIsCloseButtonRendered] = useState(false);
|
|
489
|
-
const closeButtonRef = useCallback((node)=>{
|
|
490
|
-
setIsCloseButtonRendered(!!node);
|
|
491
|
-
}, []);
|
|
492
487
|
const overlayRef = useRef(null);
|
|
493
488
|
const openTime = useRef(null);
|
|
494
489
|
const dragStartTime = useRef(null);
|
|
@@ -811,7 +806,6 @@ function useDrawer(props) {
|
|
|
811
806
|
}, [
|
|
812
807
|
modal
|
|
813
808
|
]);
|
|
814
|
-
// Effect 1: Track drawer open state
|
|
815
809
|
useEffect(()=>{
|
|
816
810
|
if (isOpen) {
|
|
817
811
|
setHasBeenOpened(true);
|
|
@@ -819,24 +813,6 @@ function useDrawer(props) {
|
|
|
819
813
|
}, [
|
|
820
814
|
isOpen
|
|
821
815
|
]);
|
|
822
|
-
// Effect 2: Handle animation state and timer
|
|
823
|
-
useEffect(()=>{
|
|
824
|
-
if (isOpen) {
|
|
825
|
-
// Only reset animation state if this is the first open
|
|
826
|
-
if (!hasBeenOpened) {
|
|
827
|
-
setHasAnimationDone(false);
|
|
828
|
-
}
|
|
829
|
-
const timeoutId = setTimeout(()=>{
|
|
830
|
-
setHasAnimationDone(true);
|
|
831
|
-
}, TRANSITIONS.ENTER_DURATION * 1000);
|
|
832
|
-
return ()=>clearTimeout(timeoutId);
|
|
833
|
-
}
|
|
834
|
-
// Reset animation state when drawer closes
|
|
835
|
-
setHasAnimationDone(false);
|
|
836
|
-
}, [
|
|
837
|
-
isOpen,
|
|
838
|
-
hasBeenOpened
|
|
839
|
-
]);
|
|
840
816
|
useEffect(()=>{
|
|
841
817
|
if (isOpen && snapPoints && fadeFromIndex === 0) {
|
|
842
818
|
setShouldOverlayAnimate(true);
|
|
@@ -879,10 +855,7 @@ function useDrawer(props) {
|
|
|
879
855
|
setHasBeenOpened,
|
|
880
856
|
setIsOpen,
|
|
881
857
|
closeOnInteractOutside,
|
|
882
|
-
closeOnEscape
|
|
883
|
-
hasAnimationDone,
|
|
884
|
-
closeButtonRef,
|
|
885
|
-
isCloseButtonRendered
|
|
858
|
+
closeOnEscape
|
|
886
859
|
}), [
|
|
887
860
|
activeSnapPoint,
|
|
888
861
|
snapPoints,
|
|
@@ -907,10 +880,7 @@ function useDrawer(props) {
|
|
|
907
880
|
closeOnEscape,
|
|
908
881
|
onRelease,
|
|
909
882
|
onDrag,
|
|
910
|
-
onPress
|
|
911
|
-
hasAnimationDone,
|
|
912
|
-
closeButtonRef,
|
|
913
|
-
isCloseButtonRendered
|
|
883
|
+
onPress
|
|
914
884
|
]);
|
|
915
885
|
}
|
|
916
886
|
|
|
@@ -960,10 +930,11 @@ const DrawerPositioner = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
960
930
|
});
|
|
961
931
|
DrawerPositioner.displayName = "DrawerPositioner";
|
|
962
932
|
const DrawerBackdrop = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
963
|
-
const { overlayRef, onRelease, modal, snapPoints, isOpen, shouldFade, shouldOverlayAnimate
|
|
933
|
+
const { overlayRef, onRelease, modal, snapPoints, isOpen, shouldFade, shouldOverlayAnimate } = useDrawerContext();
|
|
964
934
|
const composedRef = useComposedRefs(ref, overlayRef);
|
|
965
935
|
const hasSnapPoints = snapPoints && snapPoints.length > 0;
|
|
966
936
|
const onMouseUp = useCallbackRef((event)=>onRelease(event));
|
|
937
|
+
// Overlay is the component that is locking scroll, removing it will unlock the scroll without having to dig into Radix's Dialog library
|
|
967
938
|
if (!modal) {
|
|
968
939
|
return null;
|
|
969
940
|
}
|
|
@@ -974,14 +945,13 @@ const DrawerBackdrop = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
974
945
|
"data-snap-points-overlay": isOpen && shouldFade ? "true" : "false",
|
|
975
946
|
"data-should-overlay-animate": shouldOverlayAnimate ? "true" : "false",
|
|
976
947
|
"data-open": dataAttr(isOpen),
|
|
977
|
-
"data-animation-done": hasAnimationDone ? "true" : "false",
|
|
978
948
|
...props
|
|
979
949
|
});
|
|
980
950
|
});
|
|
981
951
|
DrawerBackdrop.displayName = "DrawerBackdrop";
|
|
982
952
|
const DrawerContent = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
983
953
|
const { onPointerDownOutside, style, onOpenAutoFocus, ...restProps } = props;
|
|
984
|
-
const { drawerRef, onPress, onRelease, onDrag, keyboardIsOpen, snapPointsOffset, activeSnapPointIndex, modal, isOpen, direction, snapPoints, container, handleOnly, autoFocus, closeDrawer, closeOnInteractOutside, closeOnEscape, dismissible
|
|
954
|
+
const { drawerRef, onPress, onRelease, onDrag, keyboardIsOpen, snapPointsOffset, activeSnapPointIndex, modal, isOpen, direction, snapPoints, container, handleOnly, autoFocus, closeDrawer, closeOnInteractOutside, closeOnEscape, dismissible } = useDrawerContext();
|
|
985
955
|
// Needed to use transition instead of animations
|
|
986
956
|
const [delayedSnapPoints, setDelayedSnapPoints] = useState(false);
|
|
987
957
|
const composedRef = useComposedRefs(ref, drawerRef);
|
|
@@ -1028,7 +998,6 @@ const DrawerContent = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
1028
998
|
"data-delayed-snap-points": delayedSnapPoints ? "true" : "false",
|
|
1029
999
|
"data-drawer-direction": direction,
|
|
1030
1000
|
"data-open": dataAttr(isOpen),
|
|
1031
|
-
"data-animation-done": hasAnimationDone ? "true" : "false",
|
|
1032
1001
|
"data-drawer": "",
|
|
1033
1002
|
"data-snap-points": isOpen && hasSnapPoints ? "true" : "false",
|
|
1034
1003
|
"data-custom-container": container ? "true" : "false",
|
|
@@ -1121,25 +1090,15 @@ const DrawerContent = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
1121
1090
|
DrawerContent.displayName = "DrawerContent";
|
|
1122
1091
|
const DrawerTitle = DialogPrimitive.Title;
|
|
1123
1092
|
const DrawerDescription = DialogPrimitive.Description;
|
|
1124
|
-
const DrawerHeader = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
1125
|
-
const { isCloseButtonRendered } = useDrawerContext();
|
|
1126
|
-
return /*#__PURE__*/ jsx(Primitive.div, {
|
|
1127
|
-
ref: ref,
|
|
1128
|
-
"data-show-close-button": dataAttr(isCloseButtonRendered),
|
|
1129
|
-
...props
|
|
1130
|
-
});
|
|
1131
|
-
});
|
|
1132
|
-
DrawerHeader.displayName = "DrawerHeader";
|
|
1133
1093
|
const DrawerCloseButton = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
1134
|
-
const
|
|
1135
|
-
const composedRef = useComposedRefs(ref, closeButtonRef);
|
|
1094
|
+
const api = useDrawerContext();
|
|
1136
1095
|
return /*#__PURE__*/ jsx(Primitive.button, {
|
|
1137
|
-
ref:
|
|
1096
|
+
ref: ref,
|
|
1138
1097
|
...props,
|
|
1139
1098
|
onClick: (e)=>{
|
|
1140
1099
|
props.onClick?.(e);
|
|
1141
1100
|
if (e.defaultPrevented) return;
|
|
1142
|
-
setIsOpen(false);
|
|
1101
|
+
api.setIsOpen(false);
|
|
1143
1102
|
}
|
|
1144
1103
|
});
|
|
1145
1104
|
});
|
|
@@ -1220,4 +1179,4 @@ const DrawerHandle = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
1220
1179
|
});
|
|
1221
1180
|
DrawerHandle.displayName = "DrawerHandle";
|
|
1222
1181
|
|
|
1223
|
-
export { DrawerBackdrop as D, DrawerCloseButton as a, DrawerContent as b, DrawerDescription as c, DrawerHandle as d,
|
|
1182
|
+
export { DrawerBackdrop as D, DrawerCloseButton as a, DrawerContent as b, DrawerDescription as c, DrawerHandle as d, DrawerPositioner as e, DrawerRoot as f, DrawerTitle as g, DrawerTrigger as h, useDrawerContext as i, useDrawer as u };
|
|
@@ -505,13 +505,8 @@ function useDrawer(props) {
|
|
|
505
505
|
}
|
|
506
506
|
});
|
|
507
507
|
const [hasBeenOpened, setHasBeenOpened] = React.useState(false);
|
|
508
|
-
const [hasAnimationDone, setHasAnimationDone] = React.useState(false);
|
|
509
508
|
const [isDragging, setIsDragging] = React.useState(false);
|
|
510
509
|
const [shouldOverlayAnimate, setShouldOverlayAnimate] = React.useState(false);
|
|
511
|
-
const [isCloseButtonRendered, setIsCloseButtonRendered] = React.useState(false);
|
|
512
|
-
const closeButtonRef = React.useCallback((node)=>{
|
|
513
|
-
setIsCloseButtonRendered(!!node);
|
|
514
|
-
}, []);
|
|
515
510
|
const overlayRef = React.useRef(null);
|
|
516
511
|
const openTime = React.useRef(null);
|
|
517
512
|
const dragStartTime = React.useRef(null);
|
|
@@ -834,7 +829,6 @@ function useDrawer(props) {
|
|
|
834
829
|
}, [
|
|
835
830
|
modal
|
|
836
831
|
]);
|
|
837
|
-
// Effect 1: Track drawer open state
|
|
838
832
|
React.useEffect(()=>{
|
|
839
833
|
if (isOpen) {
|
|
840
834
|
setHasBeenOpened(true);
|
|
@@ -842,24 +836,6 @@ function useDrawer(props) {
|
|
|
842
836
|
}, [
|
|
843
837
|
isOpen
|
|
844
838
|
]);
|
|
845
|
-
// Effect 2: Handle animation state and timer
|
|
846
|
-
React.useEffect(()=>{
|
|
847
|
-
if (isOpen) {
|
|
848
|
-
// Only reset animation state if this is the first open
|
|
849
|
-
if (!hasBeenOpened) {
|
|
850
|
-
setHasAnimationDone(false);
|
|
851
|
-
}
|
|
852
|
-
const timeoutId = setTimeout(()=>{
|
|
853
|
-
setHasAnimationDone(true);
|
|
854
|
-
}, TRANSITIONS.ENTER_DURATION * 1000);
|
|
855
|
-
return ()=>clearTimeout(timeoutId);
|
|
856
|
-
}
|
|
857
|
-
// Reset animation state when drawer closes
|
|
858
|
-
setHasAnimationDone(false);
|
|
859
|
-
}, [
|
|
860
|
-
isOpen,
|
|
861
|
-
hasBeenOpened
|
|
862
|
-
]);
|
|
863
839
|
React.useEffect(()=>{
|
|
864
840
|
if (isOpen && snapPoints && fadeFromIndex === 0) {
|
|
865
841
|
setShouldOverlayAnimate(true);
|
|
@@ -902,10 +878,7 @@ function useDrawer(props) {
|
|
|
902
878
|
setHasBeenOpened,
|
|
903
879
|
setIsOpen,
|
|
904
880
|
closeOnInteractOutside,
|
|
905
|
-
closeOnEscape
|
|
906
|
-
hasAnimationDone,
|
|
907
|
-
closeButtonRef,
|
|
908
|
-
isCloseButtonRendered
|
|
881
|
+
closeOnEscape
|
|
909
882
|
}), [
|
|
910
883
|
activeSnapPoint,
|
|
911
884
|
snapPoints,
|
|
@@ -930,10 +903,7 @@ function useDrawer(props) {
|
|
|
930
903
|
closeOnEscape,
|
|
931
904
|
onRelease,
|
|
932
905
|
onDrag,
|
|
933
|
-
onPress
|
|
934
|
-
hasAnimationDone,
|
|
935
|
-
closeButtonRef,
|
|
936
|
-
isCloseButtonRendered
|
|
906
|
+
onPress
|
|
937
907
|
]);
|
|
938
908
|
}
|
|
939
909
|
|
|
@@ -983,10 +953,11 @@ const DrawerPositioner = /*#__PURE__*/ React.forwardRef((props, ref)=>{
|
|
|
983
953
|
});
|
|
984
954
|
DrawerPositioner.displayName = "DrawerPositioner";
|
|
985
955
|
const DrawerBackdrop = /*#__PURE__*/ React.forwardRef((props, ref)=>{
|
|
986
|
-
const { overlayRef, onRelease, modal, snapPoints, isOpen, shouldFade, shouldOverlayAnimate
|
|
956
|
+
const { overlayRef, onRelease, modal, snapPoints, isOpen, shouldFade, shouldOverlayAnimate } = useDrawerContext();
|
|
987
957
|
const composedRef = reactComposeRefs.useComposedRefs(ref, overlayRef);
|
|
988
958
|
const hasSnapPoints = snapPoints && snapPoints.length > 0;
|
|
989
959
|
const onMouseUp = reactUseCallbackRef.useCallbackRef((event)=>onRelease(event));
|
|
960
|
+
// Overlay is the component that is locking scroll, removing it will unlock the scroll without having to dig into Radix's Dialog library
|
|
990
961
|
if (!modal) {
|
|
991
962
|
return null;
|
|
992
963
|
}
|
|
@@ -997,14 +968,13 @@ const DrawerBackdrop = /*#__PURE__*/ React.forwardRef((props, ref)=>{
|
|
|
997
968
|
"data-snap-points-overlay": isOpen && shouldFade ? "true" : "false",
|
|
998
969
|
"data-should-overlay-animate": shouldOverlayAnimate ? "true" : "false",
|
|
999
970
|
"data-open": domUtils.dataAttr(isOpen),
|
|
1000
|
-
"data-animation-done": hasAnimationDone ? "true" : "false",
|
|
1001
971
|
...props
|
|
1002
972
|
});
|
|
1003
973
|
});
|
|
1004
974
|
DrawerBackdrop.displayName = "DrawerBackdrop";
|
|
1005
975
|
const DrawerContent = /*#__PURE__*/ React.forwardRef((props, ref)=>{
|
|
1006
976
|
const { onPointerDownOutside, style, onOpenAutoFocus, ...restProps } = props;
|
|
1007
|
-
const { drawerRef, onPress, onRelease, onDrag, keyboardIsOpen, snapPointsOffset, activeSnapPointIndex, modal, isOpen, direction, snapPoints, container, handleOnly, autoFocus, closeDrawer, closeOnInteractOutside, closeOnEscape, dismissible
|
|
977
|
+
const { drawerRef, onPress, onRelease, onDrag, keyboardIsOpen, snapPointsOffset, activeSnapPointIndex, modal, isOpen, direction, snapPoints, container, handleOnly, autoFocus, closeDrawer, closeOnInteractOutside, closeOnEscape, dismissible } = useDrawerContext();
|
|
1008
978
|
// Needed to use transition instead of animations
|
|
1009
979
|
const [delayedSnapPoints, setDelayedSnapPoints] = React.useState(false);
|
|
1010
980
|
const composedRef = reactComposeRefs.useComposedRefs(ref, drawerRef);
|
|
@@ -1051,7 +1021,6 @@ const DrawerContent = /*#__PURE__*/ React.forwardRef((props, ref)=>{
|
|
|
1051
1021
|
"data-delayed-snap-points": delayedSnapPoints ? "true" : "false",
|
|
1052
1022
|
"data-drawer-direction": direction,
|
|
1053
1023
|
"data-open": domUtils.dataAttr(isOpen),
|
|
1054
|
-
"data-animation-done": hasAnimationDone ? "true" : "false",
|
|
1055
1024
|
"data-drawer": "",
|
|
1056
1025
|
"data-snap-points": isOpen && hasSnapPoints ? "true" : "false",
|
|
1057
1026
|
"data-custom-container": container ? "true" : "false",
|
|
@@ -1144,25 +1113,15 @@ const DrawerContent = /*#__PURE__*/ React.forwardRef((props, ref)=>{
|
|
|
1144
1113
|
DrawerContent.displayName = "DrawerContent";
|
|
1145
1114
|
const DrawerTitle = DialogPrimitive__namespace.Title;
|
|
1146
1115
|
const DrawerDescription = DialogPrimitive__namespace.Description;
|
|
1147
|
-
const DrawerHeader = /*#__PURE__*/ React.forwardRef((props, ref)=>{
|
|
1148
|
-
const { isCloseButtonRendered } = useDrawerContext();
|
|
1149
|
-
return /*#__PURE__*/ jsxRuntime.jsx(reactPrimitive.Primitive.div, {
|
|
1150
|
-
ref: ref,
|
|
1151
|
-
"data-show-close-button": domUtils.dataAttr(isCloseButtonRendered),
|
|
1152
|
-
...props
|
|
1153
|
-
});
|
|
1154
|
-
});
|
|
1155
|
-
DrawerHeader.displayName = "DrawerHeader";
|
|
1156
1116
|
const DrawerCloseButton = /*#__PURE__*/ React.forwardRef((props, ref)=>{
|
|
1157
|
-
const
|
|
1158
|
-
const composedRef = reactComposeRefs.useComposedRefs(ref, closeButtonRef);
|
|
1117
|
+
const api = useDrawerContext();
|
|
1159
1118
|
return /*#__PURE__*/ jsxRuntime.jsx(reactPrimitive.Primitive.button, {
|
|
1160
|
-
ref:
|
|
1119
|
+
ref: ref,
|
|
1161
1120
|
...props,
|
|
1162
1121
|
onClick: (e)=>{
|
|
1163
1122
|
props.onClick?.(e);
|
|
1164
1123
|
if (e.defaultPrevented) return;
|
|
1165
|
-
setIsOpen(false);
|
|
1124
|
+
api.setIsOpen(false);
|
|
1166
1125
|
}
|
|
1167
1126
|
});
|
|
1168
1127
|
});
|
|
@@ -1248,7 +1207,6 @@ exports.DrawerCloseButton = DrawerCloseButton;
|
|
|
1248
1207
|
exports.DrawerContent = DrawerContent;
|
|
1249
1208
|
exports.DrawerDescription = DrawerDescription;
|
|
1250
1209
|
exports.DrawerHandle = DrawerHandle;
|
|
1251
|
-
exports.DrawerHeader = DrawerHeader;
|
|
1252
1210
|
exports.DrawerPositioner = DrawerPositioner;
|
|
1253
1211
|
exports.DrawerRoot = DrawerRoot;
|
|
1254
1212
|
exports.DrawerTitle = DrawerTitle;
|
package/lib/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var Drawer12s = require('./Drawer-12s-
|
|
1
|
+
var Drawer12s = require('./Drawer-12s-L4KZ1h_g.cjs');
|
|
2
2
|
|
|
3
3
|
var Drawer_namespace = {
|
|
4
4
|
__proto__: null,
|
|
@@ -7,7 +7,6 @@ var Drawer_namespace = {
|
|
|
7
7
|
Content: Drawer12s.DrawerContent,
|
|
8
8
|
Description: Drawer12s.DrawerDescription,
|
|
9
9
|
Handle: Drawer12s.DrawerHandle,
|
|
10
|
-
Header: Drawer12s.DrawerHeader,
|
|
11
10
|
Positioner: Drawer12s.DrawerPositioner,
|
|
12
11
|
Root: Drawer12s.DrawerRoot,
|
|
13
12
|
Title: Drawer12s.DrawerTitle,
|
|
@@ -19,7 +18,6 @@ exports.DrawerCloseButton = Drawer12s.DrawerCloseButton;
|
|
|
19
18
|
exports.DrawerContent = Drawer12s.DrawerContent;
|
|
20
19
|
exports.DrawerDescription = Drawer12s.DrawerDescription;
|
|
21
20
|
exports.DrawerHandle = Drawer12s.DrawerHandle;
|
|
22
|
-
exports.DrawerHeader = Drawer12s.DrawerHeader;
|
|
23
21
|
exports.DrawerPositioner = Drawer12s.DrawerPositioner;
|
|
24
22
|
exports.DrawerRoot = Drawer12s.DrawerRoot;
|
|
25
23
|
exports.DrawerTitle = Drawer12s.DrawerTitle;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
|
3
3
|
import { PrimitiveProps } from '@seed-design/react-primitive';
|
|
4
|
-
import * as
|
|
4
|
+
import * as react from 'react';
|
|
5
5
|
|
|
6
6
|
interface UseDrawerProps {
|
|
7
7
|
activeSnapPoint?: number | string | null;
|
|
@@ -106,9 +106,9 @@ interface UseDrawerProps {
|
|
|
106
106
|
declare function useDrawer(props: UseDrawerProps): {
|
|
107
107
|
activeSnapPoint: string | number | null;
|
|
108
108
|
snapPoints: (string | number)[] | undefined;
|
|
109
|
-
setActiveSnapPoint: (value:
|
|
110
|
-
drawerRef:
|
|
111
|
-
overlayRef:
|
|
109
|
+
setActiveSnapPoint: (value: react.SetStateAction<string | number | null>) => void;
|
|
110
|
+
drawerRef: react.RefObject<HTMLDivElement | null>;
|
|
111
|
+
overlayRef: react.RefObject<HTMLDivElement | null>;
|
|
112
112
|
shouldOverlayAnimate: boolean;
|
|
113
113
|
onOpenChange: ((open: boolean) => void) | undefined;
|
|
114
114
|
onPress: (event: React.PointerEvent<HTMLDivElement>) => void;
|
|
@@ -120,7 +120,7 @@ declare function useDrawer(props: UseDrawerProps): {
|
|
|
120
120
|
isDragging: boolean;
|
|
121
121
|
shouldFade: boolean;
|
|
122
122
|
closeDrawer: (fromWithin?: boolean) => void;
|
|
123
|
-
keyboardIsOpen:
|
|
123
|
+
keyboardIsOpen: react.RefObject<boolean>;
|
|
124
124
|
modal: boolean;
|
|
125
125
|
snapPointsOffset: number[];
|
|
126
126
|
activeSnapPointIndex: number | null;
|
|
@@ -128,55 +128,49 @@ declare function useDrawer(props: UseDrawerProps): {
|
|
|
128
128
|
noBodyStyles: boolean;
|
|
129
129
|
container: HTMLElement | null | undefined;
|
|
130
130
|
autoFocus: boolean;
|
|
131
|
-
setHasBeenOpened:
|
|
132
|
-
setIsOpen: (value:
|
|
131
|
+
setHasBeenOpened: react.Dispatch<react.SetStateAction<boolean>>;
|
|
132
|
+
setIsOpen: (value: react.SetStateAction<boolean>) => void;
|
|
133
133
|
closeOnInteractOutside: boolean;
|
|
134
134
|
closeOnEscape: boolean;
|
|
135
|
-
hasAnimationDone: boolean;
|
|
136
|
-
closeButtonRef: (node: HTMLButtonElement | null) => void;
|
|
137
|
-
isCloseButtonRendered: boolean;
|
|
138
135
|
};
|
|
139
136
|
|
|
140
137
|
interface DrawerRootProps extends UseDrawerProps {
|
|
141
|
-
children?:
|
|
138
|
+
children?: react.ReactNode;
|
|
142
139
|
}
|
|
143
140
|
declare const DrawerRoot: (props: DrawerRootProps) => react_jsx_runtime.JSX.Element;
|
|
144
141
|
interface DrawerTriggerProps extends DialogPrimitive.DialogTriggerProps {
|
|
145
142
|
}
|
|
146
|
-
declare const DrawerTrigger:
|
|
147
|
-
interface DrawerPositionerProps extends PrimitiveProps,
|
|
143
|
+
declare const DrawerTrigger: react.ForwardRefExoticComponent<DialogPrimitive.DialogTriggerProps & react.RefAttributes<HTMLButtonElement>>;
|
|
144
|
+
interface DrawerPositionerProps extends PrimitiveProps, react.HTMLAttributes<HTMLDivElement> {
|
|
148
145
|
}
|
|
149
|
-
declare const DrawerPositioner:
|
|
150
|
-
interface DrawerBackdropProps extends DialogPrimitive.DialogOverlayProps,
|
|
146
|
+
declare const DrawerPositioner: react.ForwardRefExoticComponent<DrawerPositionerProps & react.RefAttributes<HTMLDivElement>>;
|
|
147
|
+
interface DrawerBackdropProps extends DialogPrimitive.DialogOverlayProps, react.HTMLAttributes<HTMLDivElement> {
|
|
151
148
|
}
|
|
152
|
-
declare const DrawerBackdrop:
|
|
153
|
-
interface DrawerContentProps extends DialogPrimitive.DialogContentProps,
|
|
149
|
+
declare const DrawerBackdrop: react.ForwardRefExoticComponent<DrawerBackdropProps & react.RefAttributes<HTMLDivElement>>;
|
|
150
|
+
interface DrawerContentProps extends DialogPrimitive.DialogContentProps, react.HTMLAttributes<HTMLDivElement> {
|
|
154
151
|
}
|
|
155
|
-
declare const DrawerContent:
|
|
152
|
+
declare const DrawerContent: react.ForwardRefExoticComponent<DrawerContentProps & react.RefAttributes<HTMLDivElement>>;
|
|
156
153
|
interface DrawerTitleProps extends DialogPrimitive.DialogTitleProps {
|
|
157
154
|
}
|
|
158
|
-
declare const DrawerTitle:
|
|
155
|
+
declare const DrawerTitle: react.ForwardRefExoticComponent<DialogPrimitive.DialogTitleProps & react.RefAttributes<HTMLHeadingElement>>;
|
|
159
156
|
interface DrawerDescriptionProps extends DialogPrimitive.DialogDescriptionProps {
|
|
160
157
|
}
|
|
161
|
-
declare const DrawerDescription:
|
|
162
|
-
interface DrawerHeaderProps extends PrimitiveProps, React$1.HTMLAttributes<HTMLDivElement> {
|
|
163
|
-
}
|
|
164
|
-
declare const DrawerHeader: React$1.ForwardRefExoticComponent<DrawerHeaderProps & React$1.RefAttributes<HTMLDivElement>>;
|
|
158
|
+
declare const DrawerDescription: react.ForwardRefExoticComponent<DialogPrimitive.DialogDescriptionProps & react.RefAttributes<HTMLParagraphElement>>;
|
|
165
159
|
interface DrawerCloseButtonProps extends DialogPrimitive.DialogCloseProps {
|
|
166
160
|
}
|
|
167
|
-
declare const DrawerCloseButton:
|
|
168
|
-
interface DrawerHandleProps extends
|
|
161
|
+
declare const DrawerCloseButton: react.ForwardRefExoticComponent<DrawerCloseButtonProps & react.RefAttributes<HTMLButtonElement>>;
|
|
162
|
+
interface DrawerHandleProps extends react.HTMLAttributes<HTMLDivElement> {
|
|
169
163
|
preventCycle?: boolean;
|
|
170
164
|
}
|
|
171
|
-
declare const DrawerHandle:
|
|
165
|
+
declare const DrawerHandle: react.ForwardRefExoticComponent<DrawerHandleProps & react.RefAttributes<HTMLDivElement>>;
|
|
172
166
|
|
|
173
167
|
type DrawerContextValue = ReturnType<typeof useDrawer>;
|
|
174
168
|
declare function useDrawerContext(): {
|
|
175
169
|
activeSnapPoint: string | number | null;
|
|
176
170
|
snapPoints: (string | number)[] | undefined;
|
|
177
|
-
setActiveSnapPoint: (value:
|
|
178
|
-
drawerRef:
|
|
179
|
-
overlayRef:
|
|
171
|
+
setActiveSnapPoint: (value: react.SetStateAction<string | number | null>) => void;
|
|
172
|
+
drawerRef: react.RefObject<HTMLDivElement | null>;
|
|
173
|
+
overlayRef: react.RefObject<HTMLDivElement | null>;
|
|
180
174
|
shouldOverlayAnimate: boolean;
|
|
181
175
|
onOpenChange: ((open: boolean) => void) | undefined;
|
|
182
176
|
onPress: (event: React.PointerEvent<HTMLDivElement>) => void;
|
|
@@ -188,7 +182,7 @@ declare function useDrawerContext(): {
|
|
|
188
182
|
isDragging: boolean;
|
|
189
183
|
shouldFade: boolean;
|
|
190
184
|
closeDrawer: (fromWithin?: boolean) => void;
|
|
191
|
-
keyboardIsOpen:
|
|
185
|
+
keyboardIsOpen: react.RefObject<boolean>;
|
|
192
186
|
modal: boolean;
|
|
193
187
|
snapPointsOffset: number[];
|
|
194
188
|
activeSnapPointIndex: number | null;
|
|
@@ -196,19 +190,16 @@ declare function useDrawerContext(): {
|
|
|
196
190
|
noBodyStyles: boolean;
|
|
197
191
|
container: HTMLElement | null | undefined;
|
|
198
192
|
autoFocus: boolean;
|
|
199
|
-
setHasBeenOpened:
|
|
200
|
-
setIsOpen: (value:
|
|
193
|
+
setHasBeenOpened: react.Dispatch<react.SetStateAction<boolean>>;
|
|
194
|
+
setIsOpen: (value: react.SetStateAction<boolean>) => void;
|
|
201
195
|
closeOnInteractOutside: boolean;
|
|
202
196
|
closeOnEscape: boolean;
|
|
203
|
-
hasAnimationDone: boolean;
|
|
204
|
-
closeButtonRef: (node: HTMLButtonElement | null) => void;
|
|
205
|
-
isCloseButtonRendered: boolean;
|
|
206
197
|
};
|
|
207
198
|
|
|
208
199
|
declare namespace Drawer_namespace {
|
|
209
|
-
export { DrawerBackdrop as Backdrop, DrawerCloseButton as CloseButton, DrawerContent as Content, DrawerDescription as Description, DrawerHandle as Handle,
|
|
210
|
-
export type { DrawerBackdropProps as BackdropProps, DrawerCloseButtonProps as CloseButtonProps, DrawerContentProps as ContentProps, DrawerDescriptionProps as DescriptionProps, DrawerHandleProps as HandleProps,
|
|
200
|
+
export { DrawerBackdrop as Backdrop, DrawerCloseButton as CloseButton, DrawerContent as Content, DrawerDescription as Description, DrawerHandle as Handle, DrawerPositioner as Positioner, DrawerRoot as Root, DrawerTitle as Title, DrawerTrigger as Trigger };
|
|
201
|
+
export type { DrawerBackdropProps as BackdropProps, DrawerCloseButtonProps as CloseButtonProps, DrawerContentProps as ContentProps, DrawerDescriptionProps as DescriptionProps, DrawerHandleProps as HandleProps, DrawerPositionerProps as PositionerProps, DrawerRootProps as RootProps, DrawerTitleProps as TitleProps, DrawerTriggerProps as TriggerProps };
|
|
211
202
|
}
|
|
212
203
|
|
|
213
|
-
export { Drawer_namespace as Drawer, DrawerBackdrop, DrawerCloseButton, DrawerContent, DrawerDescription, DrawerHandle,
|
|
214
|
-
export type { DrawerBackdropProps, DrawerCloseButtonProps, DrawerContentProps, DrawerContextValue, DrawerDescriptionProps, DrawerHandleProps,
|
|
204
|
+
export { Drawer_namespace as Drawer, DrawerBackdrop, DrawerCloseButton, DrawerContent, DrawerDescription, DrawerHandle, DrawerPositioner, DrawerRoot, DrawerTitle, DrawerTrigger, useDrawer, useDrawerContext };
|
|
205
|
+
export type { DrawerBackdropProps, DrawerCloseButtonProps, DrawerContentProps, DrawerContextValue, DrawerDescriptionProps, DrawerHandleProps, DrawerPositionerProps, DrawerRootProps, DrawerTitleProps, DrawerTriggerProps, UseDrawerProps };
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as DrawerBackdrop, a as DrawerCloseButton, b as DrawerContent, c as DrawerDescription, d as DrawerHandle, e as
|
|
2
|
-
export { u as useDrawer,
|
|
1
|
+
import { D as DrawerBackdrop, a as DrawerCloseButton, b as DrawerContent, c as DrawerDescription, d as DrawerHandle, e as DrawerPositioner, f as DrawerRoot, g as DrawerTitle, h as DrawerTrigger } from './Drawer-12s-1gup1cyj.js';
|
|
2
|
+
export { u as useDrawer, i as useDrawerContext } from './Drawer-12s-1gup1cyj.js';
|
|
3
3
|
|
|
4
4
|
var Drawer_namespace = {
|
|
5
5
|
__proto__: null,
|
|
@@ -8,11 +8,10 @@ var Drawer_namespace = {
|
|
|
8
8
|
Content: DrawerContent,
|
|
9
9
|
Description: DrawerDescription,
|
|
10
10
|
Handle: DrawerHandle,
|
|
11
|
-
Header: DrawerHeader,
|
|
12
11
|
Positioner: DrawerPositioner,
|
|
13
12
|
Root: DrawerRoot,
|
|
14
13
|
Title: DrawerTitle,
|
|
15
14
|
Trigger: DrawerTrigger
|
|
16
15
|
};
|
|
17
16
|
|
|
18
|
-
export { Drawer_namespace as Drawer, DrawerBackdrop, DrawerCloseButton, DrawerContent, DrawerDescription, DrawerHandle,
|
|
17
|
+
export { Drawer_namespace as Drawer, DrawerBackdrop, DrawerCloseButton, DrawerContent, DrawerDescription, DrawerHandle, DrawerPositioner, DrawerRoot, DrawerTitle, DrawerTrigger };
|
package/package.json
CHANGED
package/src/Drawer.namespace.ts
CHANGED
|
@@ -4,7 +4,6 @@ export {
|
|
|
4
4
|
DrawerContent as Content,
|
|
5
5
|
DrawerDescription as Description,
|
|
6
6
|
DrawerHandle as Handle,
|
|
7
|
-
DrawerHeader as Header,
|
|
8
7
|
DrawerPositioner as Positioner,
|
|
9
8
|
DrawerRoot as Root,
|
|
10
9
|
DrawerTitle as Title,
|
|
@@ -14,7 +13,6 @@ export {
|
|
|
14
13
|
type DrawerContentProps as ContentProps,
|
|
15
14
|
type DrawerDescriptionProps as DescriptionProps,
|
|
16
15
|
type DrawerHandleProps as HandleProps,
|
|
17
|
-
type DrawerHeaderProps as HeaderProps,
|
|
18
16
|
type DrawerPositionerProps as PositionerProps,
|
|
19
17
|
type DrawerRootProps as RootProps,
|
|
20
18
|
type DrawerTitleProps as TitleProps,
|
package/src/Drawer.tsx
CHANGED
|
@@ -64,20 +64,13 @@ export interface DrawerBackdropProps
|
|
|
64
64
|
React.HTMLAttributes<HTMLDivElement> {}
|
|
65
65
|
|
|
66
66
|
export const DrawerBackdrop = forwardRef<HTMLDivElement, DrawerBackdropProps>((props, ref) => {
|
|
67
|
-
const {
|
|
68
|
-
|
|
69
|
-
onRelease,
|
|
70
|
-
modal,
|
|
71
|
-
snapPoints,
|
|
72
|
-
isOpen,
|
|
73
|
-
shouldFade,
|
|
74
|
-
shouldOverlayAnimate,
|
|
75
|
-
hasAnimationDone,
|
|
76
|
-
} = useDrawerContext();
|
|
67
|
+
const { overlayRef, onRelease, modal, snapPoints, isOpen, shouldFade, shouldOverlayAnimate } =
|
|
68
|
+
useDrawerContext();
|
|
77
69
|
const composedRef = useComposedRefs(ref, overlayRef);
|
|
78
70
|
const hasSnapPoints = snapPoints && snapPoints.length > 0;
|
|
79
71
|
const onMouseUp = useCallbackRef((event: React.PointerEvent<HTMLDivElement>) => onRelease(event));
|
|
80
72
|
|
|
73
|
+
// Overlay is the component that is locking scroll, removing it will unlock the scroll without having to dig into Radix's Dialog library
|
|
81
74
|
if (!modal) {
|
|
82
75
|
return null;
|
|
83
76
|
}
|
|
@@ -90,7 +83,6 @@ export const DrawerBackdrop = forwardRef<HTMLDivElement, DrawerBackdropProps>((p
|
|
|
90
83
|
data-snap-points-overlay={isOpen && shouldFade ? "true" : "false"}
|
|
91
84
|
data-should-overlay-animate={shouldOverlayAnimate ? "true" : "false"}
|
|
92
85
|
data-open={dataAttr(isOpen)}
|
|
93
|
-
data-animation-done={hasAnimationDone ? "true" : "false"}
|
|
94
86
|
{...props}
|
|
95
87
|
/>
|
|
96
88
|
);
|
|
@@ -122,7 +114,6 @@ export const DrawerContent = forwardRef<HTMLDivElement, DrawerContentProps>((pro
|
|
|
122
114
|
closeOnInteractOutside,
|
|
123
115
|
closeOnEscape,
|
|
124
116
|
dismissible,
|
|
125
|
-
hasAnimationDone,
|
|
126
117
|
} = useDrawerContext();
|
|
127
118
|
// Needed to use transition instead of animations
|
|
128
119
|
const [delayedSnapPoints, setDelayedSnapPoints] = useState(false);
|
|
@@ -179,7 +170,6 @@ export const DrawerContent = forwardRef<HTMLDivElement, DrawerContentProps>((pro
|
|
|
179
170
|
data-delayed-snap-points={delayedSnapPoints ? "true" : "false"}
|
|
180
171
|
data-drawer-direction={direction}
|
|
181
172
|
data-open={dataAttr(isOpen)}
|
|
182
|
-
data-animation-done={hasAnimationDone ? "true" : "false"}
|
|
183
173
|
data-drawer=""
|
|
184
174
|
data-snap-points={isOpen && hasSnapPoints ? "true" : "false"}
|
|
185
175
|
data-custom-container={container ? "true" : "false"}
|
|
@@ -286,30 +276,19 @@ export interface DrawerDescriptionProps extends DialogPrimitive.DialogDescriptio
|
|
|
286
276
|
|
|
287
277
|
export const DrawerDescription = DialogPrimitive.Description;
|
|
288
278
|
|
|
289
|
-
export interface DrawerHeaderProps extends PrimitiveProps, React.HTMLAttributes<HTMLDivElement> {}
|
|
290
|
-
|
|
291
|
-
export const DrawerHeader = forwardRef<HTMLDivElement, DrawerHeaderProps>((props, ref) => {
|
|
292
|
-
const { isCloseButtonRendered } = useDrawerContext();
|
|
293
|
-
return (
|
|
294
|
-
<Primitive.div ref={ref} data-show-close-button={dataAttr(isCloseButtonRendered)} {...props} />
|
|
295
|
-
);
|
|
296
|
-
});
|
|
297
|
-
DrawerHeader.displayName = "DrawerHeader";
|
|
298
|
-
|
|
299
279
|
export interface DrawerCloseButtonProps extends DialogPrimitive.DialogCloseProps {}
|
|
300
280
|
|
|
301
281
|
export const DrawerCloseButton = forwardRef<HTMLButtonElement, DrawerCloseButtonProps>(
|
|
302
282
|
(props, ref) => {
|
|
303
|
-
const
|
|
304
|
-
const composedRef = useComposedRefs(ref, closeButtonRef);
|
|
283
|
+
const api = useDrawerContext();
|
|
305
284
|
return (
|
|
306
285
|
<Primitive.button
|
|
307
|
-
ref={
|
|
286
|
+
ref={ref}
|
|
308
287
|
{...props}
|
|
309
288
|
onClick={(e) => {
|
|
310
289
|
props.onClick?.(e);
|
|
311
290
|
if (e.defaultPrevented) return;
|
|
312
|
-
setIsOpen(false);
|
|
291
|
+
api.setIsOpen(false);
|
|
313
292
|
}}
|
|
314
293
|
/>
|
|
315
294
|
);
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,6 @@ export {
|
|
|
4
4
|
DrawerContent,
|
|
5
5
|
DrawerDescription,
|
|
6
6
|
DrawerHandle,
|
|
7
|
-
DrawerHeader,
|
|
8
7
|
DrawerPositioner,
|
|
9
8
|
DrawerRoot,
|
|
10
9
|
DrawerTitle,
|
|
@@ -14,7 +13,6 @@ export {
|
|
|
14
13
|
type DrawerContentProps,
|
|
15
14
|
type DrawerDescriptionProps,
|
|
16
15
|
type DrawerHandleProps,
|
|
17
|
-
type DrawerHeaderProps,
|
|
18
16
|
type DrawerPositionerProps,
|
|
19
17
|
type DrawerRootProps,
|
|
20
18
|
type DrawerTitleProps,
|
package/src/useDrawer.ts
CHANGED
|
@@ -178,15 +178,9 @@ export function useDrawer(props: UseDrawerProps) {
|
|
|
178
178
|
});
|
|
179
179
|
|
|
180
180
|
const [hasBeenOpened, setHasBeenOpened] = useState<boolean>(false);
|
|
181
|
-
const [hasAnimationDone, setHasAnimationDone] = useState<boolean>(false);
|
|
182
181
|
const [isDragging, setIsDragging] = useState<boolean>(false);
|
|
183
182
|
const [shouldOverlayAnimate, setShouldOverlayAnimate] = useState<boolean>(false);
|
|
184
183
|
|
|
185
|
-
const [isCloseButtonRendered, setIsCloseButtonRendered] = useState<boolean>(false);
|
|
186
|
-
const closeButtonRef = useCallback((node: HTMLButtonElement | null) => {
|
|
187
|
-
setIsCloseButtonRendered(!!node);
|
|
188
|
-
}, []);
|
|
189
|
-
|
|
190
184
|
const overlayRef = useRef<HTMLDivElement>(null);
|
|
191
185
|
const openTime = useRef<Date | null>(null);
|
|
192
186
|
const dragStartTime = useRef<Date | null>(null);
|
|
@@ -613,32 +607,12 @@ export function useDrawer(props: UseDrawerProps) {
|
|
|
613
607
|
}
|
|
614
608
|
}, [modal]);
|
|
615
609
|
|
|
616
|
-
// Effect 1: Track drawer open state
|
|
617
610
|
useEffect(() => {
|
|
618
611
|
if (isOpen) {
|
|
619
612
|
setHasBeenOpened(true);
|
|
620
613
|
}
|
|
621
614
|
}, [isOpen]);
|
|
622
615
|
|
|
623
|
-
// Effect 2: Handle animation state and timer
|
|
624
|
-
useEffect(() => {
|
|
625
|
-
if (isOpen) {
|
|
626
|
-
// Only reset animation state if this is the first open
|
|
627
|
-
if (!hasBeenOpened) {
|
|
628
|
-
setHasAnimationDone(false);
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
const timeoutId = setTimeout(() => {
|
|
632
|
-
setHasAnimationDone(true);
|
|
633
|
-
}, TRANSITIONS.ENTER_DURATION * 1000);
|
|
634
|
-
|
|
635
|
-
return () => clearTimeout(timeoutId);
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
// Reset animation state when drawer closes
|
|
639
|
-
setHasAnimationDone(false);
|
|
640
|
-
}, [isOpen, hasBeenOpened]);
|
|
641
|
-
|
|
642
616
|
useEffect(() => {
|
|
643
617
|
if (isOpen && snapPoints && fadeFromIndex === 0) {
|
|
644
618
|
setShouldOverlayAnimate(true);
|
|
@@ -683,9 +657,6 @@ export function useDrawer(props: UseDrawerProps) {
|
|
|
683
657
|
setIsOpen,
|
|
684
658
|
closeOnInteractOutside,
|
|
685
659
|
closeOnEscape,
|
|
686
|
-
hasAnimationDone,
|
|
687
|
-
closeButtonRef,
|
|
688
|
-
isCloseButtonRendered,
|
|
689
660
|
}),
|
|
690
661
|
[
|
|
691
662
|
activeSnapPoint,
|
|
@@ -712,9 +683,6 @@ export function useDrawer(props: UseDrawerProps) {
|
|
|
712
683
|
onRelease,
|
|
713
684
|
onDrag,
|
|
714
685
|
onPress,
|
|
715
|
-
hasAnimationDone,
|
|
716
|
-
closeButtonRef,
|
|
717
|
-
isCloseButtonRendered,
|
|
718
686
|
],
|
|
719
687
|
);
|
|
720
688
|
}
|