@seed-design/react-drawer 1.0.1 → 1.0.2
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-CAlIg6sU.js → Drawer-12s-COJG4T4l.js} +9 -8
- package/lib/{Drawer-12s-BXSK15mB.cjs → Drawer-12s-a4zbhVrK.cjs} +9 -8
- package/lib/index.cjs +1 -1
- package/lib/index.d.ts +6 -5
- package/lib/index.js +2 -2
- package/package.json +1 -1
- package/src/Drawer.tsx +4 -5
- package/src/index.ts +1 -1
- package/src/useDrawer.ts +15 -8
|
@@ -681,7 +681,7 @@ function useSnapPoints({ activeSnapPointProp, setActiveSnapPointProp, snapPoints
|
|
|
681
681
|
}
|
|
682
682
|
|
|
683
683
|
function useDrawer(props) {
|
|
684
|
-
const { open: openProp, onOpenChange, onDrag: onDragProp, onRelease: onReleaseProp, snapPoints, closeThreshold = CLOSE_THRESHOLD, scrollLockTimeout = SCROLL_LOCK_TIMEOUT, dismissible = true, handleOnly = false, fadeFromIndex = snapPoints && snapPoints.length - 1, activeSnapPoint: activeSnapPointProp, setActiveSnapPoint: setActiveSnapPointProp, fixed, modal = true, onClose, nested, noBodyStyles =
|
|
684
|
+
const { open: openProp, onOpenChange, onDrag: onDragProp, onRelease: onReleaseProp, snapPoints, closeThreshold = CLOSE_THRESHOLD, scrollLockTimeout = SCROLL_LOCK_TIMEOUT, dismissible = true, handleOnly = false, fadeFromIndex = snapPoints && snapPoints.length - 1, activeSnapPoint: activeSnapPointProp, setActiveSnapPoint: setActiveSnapPointProp, fixed, modal = true, onClose, nested, noBodyStyles = true, direction = "bottom", defaultOpen = false, disablePreventScroll = true, snapToSequentialPoint = false, preventScrollRestoration = false, repositionInputs = true, onAnimationEnd, container, autoFocus = false, closeOnInteractOutside = true, closeOnEscape = true } = props;
|
|
685
685
|
const [isOpen = false, setIsOpen] = useControllableState({
|
|
686
686
|
defaultProp: defaultOpen,
|
|
687
687
|
prop: openProp,
|
|
@@ -760,7 +760,9 @@ function useDrawer(props) {
|
|
|
760
760
|
setIsDragging(true);
|
|
761
761
|
dragStartTime.current = new Date();
|
|
762
762
|
if (isIOS()) {
|
|
763
|
-
window.addEventListener("touchend", ()=>
|
|
763
|
+
window.addEventListener("touchend", ()=>{
|
|
764
|
+
isAllowedToDrag.current = false;
|
|
765
|
+
}, {
|
|
764
766
|
once: true
|
|
765
767
|
});
|
|
766
768
|
}
|
|
@@ -1020,7 +1022,7 @@ function useDrawer(props) {
|
|
|
1020
1022
|
drawerRef.current.style.height = `${initialDrawerHeight.current}px`;
|
|
1021
1023
|
}
|
|
1022
1024
|
if (snapPoints && snapPoints.length > 0 && !keyboardIsOpen.current) {
|
|
1023
|
-
drawerRef.current.style.bottom =
|
|
1025
|
+
drawerRef.current.style.bottom = "0px";
|
|
1024
1026
|
} else {
|
|
1025
1027
|
drawerRef.current.style.bottom = `${Math.max(diffFromInitial, 0)}px`;
|
|
1026
1028
|
}
|
|
@@ -1058,9 +1060,8 @@ function useDrawer(props) {
|
|
|
1058
1060
|
setShouldOverlayAnimate(false);
|
|
1059
1061
|
}, TRANSITIONS.ENTER_DURATION * 1000);
|
|
1060
1062
|
return ()=>clearTimeout(timeoutId);
|
|
1061
|
-
} else {
|
|
1062
|
-
setShouldOverlayAnimate(false);
|
|
1063
1063
|
}
|
|
1064
|
+
setShouldOverlayAnimate(false);
|
|
1064
1065
|
}, [
|
|
1065
1066
|
isOpen,
|
|
1066
1067
|
snapPoints,
|
|
@@ -1135,7 +1136,7 @@ function useDrawerContext() {
|
|
|
1135
1136
|
}
|
|
1136
1137
|
|
|
1137
1138
|
const DrawerRoot = (props)=>{
|
|
1138
|
-
const { children, defaultOpen, dismissible,
|
|
1139
|
+
const { children, defaultOpen, dismissible, modal } = props;
|
|
1139
1140
|
const api = useDrawer(props);
|
|
1140
1141
|
return /*#__PURE__*/ jsx(DialogPrimitive.Root, {
|
|
1141
1142
|
defaultOpen: defaultOpen,
|
|
@@ -1148,7 +1149,6 @@ const DrawerRoot = (props)=>{
|
|
|
1148
1149
|
api.closeDrawer(true);
|
|
1149
1150
|
}
|
|
1150
1151
|
api.setIsOpen(open);
|
|
1151
|
-
onOpenChange?.(open);
|
|
1152
1152
|
},
|
|
1153
1153
|
modal: modal,
|
|
1154
1154
|
children: /*#__PURE__*/ jsx(DrawerProvider, {
|
|
@@ -1164,7 +1164,8 @@ const DrawerPositioner = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
1164
1164
|
ref: ref,
|
|
1165
1165
|
...props,
|
|
1166
1166
|
style: {
|
|
1167
|
-
pointerEvents: api.isOpen ? undefined : "none"
|
|
1167
|
+
pointerEvents: api.isOpen ? undefined : "none",
|
|
1168
|
+
...props.style
|
|
1168
1169
|
}
|
|
1169
1170
|
});
|
|
1170
1171
|
});
|
|
@@ -704,7 +704,7 @@ function useSnapPoints({ activeSnapPointProp, setActiveSnapPointProp, snapPoints
|
|
|
704
704
|
}
|
|
705
705
|
|
|
706
706
|
function useDrawer(props) {
|
|
707
|
-
const { open: openProp, onOpenChange, onDrag: onDragProp, onRelease: onReleaseProp, snapPoints, closeThreshold = CLOSE_THRESHOLD, scrollLockTimeout = SCROLL_LOCK_TIMEOUT, dismissible = true, handleOnly = false, fadeFromIndex = snapPoints && snapPoints.length - 1, activeSnapPoint: activeSnapPointProp, setActiveSnapPoint: setActiveSnapPointProp, fixed, modal = true, onClose, nested, noBodyStyles =
|
|
707
|
+
const { open: openProp, onOpenChange, onDrag: onDragProp, onRelease: onReleaseProp, snapPoints, closeThreshold = CLOSE_THRESHOLD, scrollLockTimeout = SCROLL_LOCK_TIMEOUT, dismissible = true, handleOnly = false, fadeFromIndex = snapPoints && snapPoints.length - 1, activeSnapPoint: activeSnapPointProp, setActiveSnapPoint: setActiveSnapPointProp, fixed, modal = true, onClose, nested, noBodyStyles = true, direction = "bottom", defaultOpen = false, disablePreventScroll = true, snapToSequentialPoint = false, preventScrollRestoration = false, repositionInputs = true, onAnimationEnd, container, autoFocus = false, closeOnInteractOutside = true, closeOnEscape = true } = props;
|
|
708
708
|
const [isOpen = false, setIsOpen] = reactUseControllableState.useControllableState({
|
|
709
709
|
defaultProp: defaultOpen,
|
|
710
710
|
prop: openProp,
|
|
@@ -783,7 +783,9 @@ function useDrawer(props) {
|
|
|
783
783
|
setIsDragging(true);
|
|
784
784
|
dragStartTime.current = new Date();
|
|
785
785
|
if (isIOS()) {
|
|
786
|
-
window.addEventListener("touchend", ()=>
|
|
786
|
+
window.addEventListener("touchend", ()=>{
|
|
787
|
+
isAllowedToDrag.current = false;
|
|
788
|
+
}, {
|
|
787
789
|
once: true
|
|
788
790
|
});
|
|
789
791
|
}
|
|
@@ -1043,7 +1045,7 @@ function useDrawer(props) {
|
|
|
1043
1045
|
drawerRef.current.style.height = `${initialDrawerHeight.current}px`;
|
|
1044
1046
|
}
|
|
1045
1047
|
if (snapPoints && snapPoints.length > 0 && !keyboardIsOpen.current) {
|
|
1046
|
-
drawerRef.current.style.bottom =
|
|
1048
|
+
drawerRef.current.style.bottom = "0px";
|
|
1047
1049
|
} else {
|
|
1048
1050
|
drawerRef.current.style.bottom = `${Math.max(diffFromInitial, 0)}px`;
|
|
1049
1051
|
}
|
|
@@ -1081,9 +1083,8 @@ function useDrawer(props) {
|
|
|
1081
1083
|
setShouldOverlayAnimate(false);
|
|
1082
1084
|
}, TRANSITIONS.ENTER_DURATION * 1000);
|
|
1083
1085
|
return ()=>clearTimeout(timeoutId);
|
|
1084
|
-
} else {
|
|
1085
|
-
setShouldOverlayAnimate(false);
|
|
1086
1086
|
}
|
|
1087
|
+
setShouldOverlayAnimate(false);
|
|
1087
1088
|
}, [
|
|
1088
1089
|
isOpen,
|
|
1089
1090
|
snapPoints,
|
|
@@ -1158,7 +1159,7 @@ function useDrawerContext() {
|
|
|
1158
1159
|
}
|
|
1159
1160
|
|
|
1160
1161
|
const DrawerRoot = (props)=>{
|
|
1161
|
-
const { children, defaultOpen, dismissible,
|
|
1162
|
+
const { children, defaultOpen, dismissible, modal } = props;
|
|
1162
1163
|
const api = useDrawer(props);
|
|
1163
1164
|
return /*#__PURE__*/ jsxRuntime.jsx(DialogPrimitive__namespace.Root, {
|
|
1164
1165
|
defaultOpen: defaultOpen,
|
|
@@ -1171,7 +1172,6 @@ const DrawerRoot = (props)=>{
|
|
|
1171
1172
|
api.closeDrawer(true);
|
|
1172
1173
|
}
|
|
1173
1174
|
api.setIsOpen(open);
|
|
1174
|
-
onOpenChange?.(open);
|
|
1175
1175
|
},
|
|
1176
1176
|
modal: modal,
|
|
1177
1177
|
children: /*#__PURE__*/ jsxRuntime.jsx(DrawerProvider, {
|
|
@@ -1187,7 +1187,8 @@ const DrawerPositioner = /*#__PURE__*/ React.forwardRef((props, ref)=>{
|
|
|
1187
1187
|
ref: ref,
|
|
1188
1188
|
...props,
|
|
1189
1189
|
style: {
|
|
1190
|
-
pointerEvents: api.isOpen ? undefined : "none"
|
|
1190
|
+
pointerEvents: api.isOpen ? undefined : "none",
|
|
1191
|
+
...props.style
|
|
1191
1192
|
}
|
|
1192
1193
|
});
|
|
1193
1194
|
});
|
package/lib/index.cjs
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import * as DialogPrimitive from '@radix-ui/react-dialog';
|
|
|
3
3
|
import { PrimitiveProps } from '@seed-design/react-primitive';
|
|
4
4
|
import * as react from 'react';
|
|
5
5
|
|
|
6
|
-
interface
|
|
6
|
+
interface UseDrawerProps {
|
|
7
7
|
activeSnapPoint?: number | string | null;
|
|
8
8
|
setActiveSnapPoint?: (snapPoint: number | string | null) => void;
|
|
9
9
|
children?: React.ReactNode;
|
|
@@ -15,7 +15,8 @@ interface DialogProps {
|
|
|
15
15
|
*/
|
|
16
16
|
closeThreshold?: number;
|
|
17
17
|
/**
|
|
18
|
-
* When `true` the `body` doesn't get any styles assigned from
|
|
18
|
+
* When `true` the `body` doesn't get any styles assigned from Drawer
|
|
19
|
+
* @default true
|
|
19
20
|
*/
|
|
20
21
|
noBodyStyles?: boolean;
|
|
21
22
|
onOpenChange?: (open: boolean) => void;
|
|
@@ -107,7 +108,7 @@ interface DialogProps {
|
|
|
107
108
|
*/
|
|
108
109
|
closeOnEscape?: boolean;
|
|
109
110
|
}
|
|
110
|
-
declare function useDrawer(props:
|
|
111
|
+
declare function useDrawer(props: UseDrawerProps): {
|
|
111
112
|
activeSnapPoint: string | number | null;
|
|
112
113
|
snapPoints: (string | number)[] | undefined;
|
|
113
114
|
setActiveSnapPoint: (value: react.SetStateAction<string | number | null>) => void;
|
|
@@ -139,7 +140,7 @@ declare function useDrawer(props: DialogProps): {
|
|
|
139
140
|
closeOnEscape: boolean;
|
|
140
141
|
};
|
|
141
142
|
|
|
142
|
-
interface DrawerRootProps extends
|
|
143
|
+
interface DrawerRootProps extends UseDrawerProps {
|
|
143
144
|
children?: react.ReactNode;
|
|
144
145
|
}
|
|
145
146
|
declare const DrawerRoot: (props: DrawerRootProps) => react_jsx_runtime.JSX.Element;
|
|
@@ -208,4 +209,4 @@ declare namespace Drawer_namespace {
|
|
|
208
209
|
}
|
|
209
210
|
|
|
210
211
|
export { Drawer_namespace as Drawer, DrawerBackdrop, DrawerCloseButton, DrawerContent, DrawerDescription, DrawerHandle, DrawerPositioner, DrawerRoot, DrawerTitle, DrawerTrigger, useDrawer, useDrawerContext };
|
|
211
|
-
export type {
|
|
212
|
+
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 DrawerPositioner, f as DrawerRoot, g as DrawerTitle, h as DrawerTrigger } from './Drawer-12s-
|
|
2
|
-
export { u as useDrawer, i as useDrawerContext } from './Drawer-12s-
|
|
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-COJG4T4l.js';
|
|
2
|
+
export { u as useDrawer, i as useDrawerContext } from './Drawer-12s-COJG4T4l.js';
|
|
3
3
|
|
|
4
4
|
var Drawer_namespace = {
|
|
5
5
|
__proto__: null,
|
package/package.json
CHANGED
package/src/Drawer.tsx
CHANGED
|
@@ -8,15 +8,15 @@ import { Primitive, type PrimitiveProps } from "@seed-design/react-primitive";
|
|
|
8
8
|
import type * as React from "react";
|
|
9
9
|
import { forwardRef, useEffect, useRef, useState } from "react";
|
|
10
10
|
import type { DrawerDirection } from "./types";
|
|
11
|
-
import { useDrawer, type
|
|
11
|
+
import { useDrawer, type UseDrawerProps } from "./useDrawer";
|
|
12
12
|
import { DrawerProvider, useDrawerContext } from "./useDrawerContext";
|
|
13
13
|
|
|
14
|
-
export interface DrawerRootProps extends
|
|
14
|
+
export interface DrawerRootProps extends UseDrawerProps {
|
|
15
15
|
children?: React.ReactNode;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export const DrawerRoot = (props: DrawerRootProps) => {
|
|
19
|
-
const { children, defaultOpen, dismissible,
|
|
19
|
+
const { children, defaultOpen, dismissible, modal } = props;
|
|
20
20
|
const api = useDrawer(props);
|
|
21
21
|
return (
|
|
22
22
|
<DialogPrimitive.Root
|
|
@@ -31,7 +31,6 @@ export const DrawerRoot = (props: DrawerRootProps) => {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
api.setIsOpen(open);
|
|
34
|
-
onOpenChange?.(open);
|
|
35
34
|
}}
|
|
36
35
|
modal={modal}
|
|
37
36
|
>
|
|
@@ -54,7 +53,7 @@ export const DrawerPositioner = forwardRef<HTMLDivElement, DrawerPositionerProps
|
|
|
54
53
|
<Primitive.div
|
|
55
54
|
ref={ref}
|
|
56
55
|
{...props}
|
|
57
|
-
style={{ pointerEvents: api.isOpen ? undefined : "none" }}
|
|
56
|
+
style={{ pointerEvents: api.isOpen ? undefined : "none", ...props.style }}
|
|
58
57
|
/>
|
|
59
58
|
);
|
|
60
59
|
});
|
package/src/index.ts
CHANGED
|
@@ -19,7 +19,7 @@ export {
|
|
|
19
19
|
type DrawerTriggerProps,
|
|
20
20
|
} from "./Drawer";
|
|
21
21
|
|
|
22
|
-
export { useDrawer, type
|
|
22
|
+
export { useDrawer, type UseDrawerProps } from "./useDrawer";
|
|
23
23
|
export { useDrawerContext, type DrawerContextValue } from "./useDrawerContext";
|
|
24
24
|
|
|
25
25
|
export * as Drawer from "./Drawer.namespace";
|
package/src/useDrawer.ts
CHANGED
|
@@ -14,7 +14,7 @@ import { usePositionFixed } from "./use-position-fixed";
|
|
|
14
14
|
import { isInput, usePreventScroll } from "./use-prevent-scroll";
|
|
15
15
|
import { useSnapPoints } from "./use-snap-points";
|
|
16
16
|
|
|
17
|
-
export interface
|
|
17
|
+
export interface UseDrawerProps {
|
|
18
18
|
activeSnapPoint?: number | string | null;
|
|
19
19
|
setActiveSnapPoint?: (snapPoint: number | string | null) => void;
|
|
20
20
|
children?: React.ReactNode;
|
|
@@ -26,7 +26,8 @@ export interface DialogProps {
|
|
|
26
26
|
*/
|
|
27
27
|
closeThreshold?: number;
|
|
28
28
|
/**
|
|
29
|
-
* When `true` the `body` doesn't get any styles assigned from
|
|
29
|
+
* When `true` the `body` doesn't get any styles assigned from Drawer
|
|
30
|
+
* @default true
|
|
30
31
|
*/
|
|
31
32
|
noBodyStyles?: boolean;
|
|
32
33
|
onOpenChange?: (open: boolean) => void;
|
|
@@ -123,7 +124,7 @@ export interface DialogProps {
|
|
|
123
124
|
closeOnEscape?: boolean;
|
|
124
125
|
}
|
|
125
126
|
|
|
126
|
-
export function useDrawer(props:
|
|
127
|
+
export function useDrawer(props: UseDrawerProps) {
|
|
127
128
|
const {
|
|
128
129
|
open: openProp,
|
|
129
130
|
onOpenChange,
|
|
@@ -141,7 +142,7 @@ export function useDrawer(props: DialogProps) {
|
|
|
141
142
|
modal = true,
|
|
142
143
|
onClose,
|
|
143
144
|
nested,
|
|
144
|
-
noBodyStyles =
|
|
145
|
+
noBodyStyles = true,
|
|
145
146
|
direction = "bottom",
|
|
146
147
|
defaultOpen = false,
|
|
147
148
|
disablePreventScroll = true,
|
|
@@ -263,7 +264,13 @@ export function useDrawer(props: DialogProps) {
|
|
|
263
264
|
dragStartTime.current = new Date();
|
|
264
265
|
|
|
265
266
|
if (isIOS()) {
|
|
266
|
-
window.addEventListener(
|
|
267
|
+
window.addEventListener(
|
|
268
|
+
"touchend",
|
|
269
|
+
() => {
|
|
270
|
+
isAllowedToDrag.current = false;
|
|
271
|
+
},
|
|
272
|
+
{ once: true },
|
|
273
|
+
);
|
|
267
274
|
}
|
|
268
275
|
(event.target as HTMLElement).setPointerCapture(event.pointerId);
|
|
269
276
|
|
|
@@ -614,7 +621,7 @@ export function useDrawer(props: DialogProps) {
|
|
|
614
621
|
}
|
|
615
622
|
|
|
616
623
|
if (snapPoints && snapPoints.length > 0 && !keyboardIsOpen.current) {
|
|
617
|
-
drawerRef.current.style.bottom =
|
|
624
|
+
drawerRef.current.style.bottom = "0px";
|
|
618
625
|
} else {
|
|
619
626
|
drawerRef.current.style.bottom = `${Math.max(diffFromInitial, 0)}px`;
|
|
620
627
|
}
|
|
@@ -648,9 +655,9 @@ export function useDrawer(props: DialogProps) {
|
|
|
648
655
|
}, TRANSITIONS.ENTER_DURATION * 1000);
|
|
649
656
|
|
|
650
657
|
return () => clearTimeout(timeoutId);
|
|
651
|
-
} else {
|
|
652
|
-
setShouldOverlayAnimate(false);
|
|
653
658
|
}
|
|
659
|
+
|
|
660
|
+
setShouldOverlayAnimate(false);
|
|
654
661
|
}, [isOpen, snapPoints, fadeFromIndex]);
|
|
655
662
|
|
|
656
663
|
return useMemo(
|