@seed-design/react-drawer 1.0.0 → 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/index.cjs ADDED
@@ -0,0 +1,27 @@
1
+ var Drawer12s = require('./Drawer-12s-a4zbhVrK.cjs');
2
+
3
+ var Drawer_namespace = {
4
+ __proto__: null,
5
+ Backdrop: Drawer12s.DrawerBackdrop,
6
+ CloseButton: Drawer12s.DrawerCloseButton,
7
+ Content: Drawer12s.DrawerContent,
8
+ Description: Drawer12s.DrawerDescription,
9
+ Handle: Drawer12s.DrawerHandle,
10
+ Positioner: Drawer12s.DrawerPositioner,
11
+ Root: Drawer12s.DrawerRoot,
12
+ Title: Drawer12s.DrawerTitle,
13
+ Trigger: Drawer12s.DrawerTrigger
14
+ };
15
+
16
+ exports.DrawerBackdrop = Drawer12s.DrawerBackdrop;
17
+ exports.DrawerCloseButton = Drawer12s.DrawerCloseButton;
18
+ exports.DrawerContent = Drawer12s.DrawerContent;
19
+ exports.DrawerDescription = Drawer12s.DrawerDescription;
20
+ exports.DrawerHandle = Drawer12s.DrawerHandle;
21
+ exports.DrawerPositioner = Drawer12s.DrawerPositioner;
22
+ exports.DrawerRoot = Drawer12s.DrawerRoot;
23
+ exports.DrawerTitle = Drawer12s.DrawerTitle;
24
+ exports.DrawerTrigger = Drawer12s.DrawerTrigger;
25
+ exports.useDrawer = Drawer12s.useDrawer;
26
+ exports.useDrawerContext = Drawer12s.useDrawerContext;
27
+ exports.Drawer = Drawer_namespace;
package/lib/index.d.ts ADDED
@@ -0,0 +1,212 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as DialogPrimitive from '@radix-ui/react-dialog';
3
+ import { PrimitiveProps } from '@seed-design/react-primitive';
4
+ import * as react from 'react';
5
+
6
+ interface UseDrawerProps {
7
+ activeSnapPoint?: number | string | null;
8
+ setActiveSnapPoint?: (snapPoint: number | string | null) => void;
9
+ children?: React.ReactNode;
10
+ open?: boolean;
11
+ /**
12
+ * Number between 0 and 1 that determines when the drawer should be closed.
13
+ * Example: threshold of 0.5 would close the drawer if the user swiped for 50% of the height of the drawer or more.
14
+ * @default 0.25
15
+ */
16
+ closeThreshold?: number;
17
+ /**
18
+ * When `true` the `body` doesn't get any styles assigned from Drawer
19
+ * @default true
20
+ */
21
+ noBodyStyles?: boolean;
22
+ onOpenChange?: (open: boolean) => void;
23
+ /**
24
+ * Duration for which the drawer is not draggable after scrolling content inside of the drawer.
25
+ * @default 500ms
26
+ */
27
+ scrollLockTimeout?: number;
28
+ /**
29
+ * When `true`, don't move the drawer upwards if there's space, but rather only change it's height so it's fully scrollable when the keyboard is open
30
+ */
31
+ fixed?: boolean;
32
+ /**
33
+ * When `true` only allows the drawer to be dragged by the `<Drawer.Handle />` component.
34
+ * @default false
35
+ */
36
+ handleOnly?: boolean;
37
+ /**
38
+ * When `false` dragging, clicking outside, pressing esc, etc. will not close the drawer.
39
+ * Use this in comination with the `open` prop, otherwise you won't be able to open/close the drawer.
40
+ * @default true
41
+ */
42
+ dismissible?: boolean;
43
+ onDrag?: (event: React.PointerEvent<HTMLDivElement>, percentageDragged: number) => void;
44
+ onRelease?: (event: React.PointerEvent<HTMLDivElement>, open: boolean) => void;
45
+ /**
46
+ * When `false` it allows to interact with elements outside of the drawer without closing it.
47
+ * @default true
48
+ */
49
+ modal?: boolean;
50
+ nested?: boolean;
51
+ onClose?: () => void;
52
+ /**
53
+ * Direction of the drawer. Can be `top` or `bottom`, `left`, `right`.
54
+ * @default 'bottom'
55
+ */
56
+ direction?: "top" | "bottom" | "left" | "right";
57
+ /**
58
+ * Opened by default, skips initial enter animation. Still reacts to `open` state changes
59
+ * @default false
60
+ */
61
+ defaultOpen?: boolean;
62
+ /**
63
+ * When set to `true` prevents scrolling on the document body on mount, and restores it on unmount.
64
+ * @default false
65
+ */
66
+ disablePreventScroll?: boolean;
67
+ /**
68
+ * When `true` Vaul will reposition inputs rather than scroll then into view if the keyboard is in the way.
69
+ * Setting it to `false` will fall back to the default browser behavior.
70
+ * @default true when {@link snapPoints} is defined
71
+ */
72
+ repositionInputs?: boolean;
73
+ /**
74
+ * Disabled velocity based swiping for snap points.
75
+ * This means that a snap point won't be skipped even if the velocity is high enough.
76
+ * Useful if each snap point in a drawer is equally important.
77
+ * @default false
78
+ */
79
+ snapToSequentialPoint?: boolean;
80
+ container?: HTMLElement | null;
81
+ /**
82
+ * Gets triggered after the open or close animation ends, it receives an `open` argument with the `open` state of the drawer by the time the function was triggered.
83
+ * Useful to revert any state changes for example.
84
+ */
85
+ onAnimationEnd?: (open: boolean) => void;
86
+ preventScrollRestoration?: boolean;
87
+ autoFocus?: boolean;
88
+ /**
89
+ * Array of snap points to use.
90
+ * Example: snapPoints={[0, 100, 200]} will use the first snap point at 0px, the second at 100px, and the third at 200px.
91
+ * @default undefined
92
+ */
93
+ snapPoints?: (number | string)[];
94
+ /**
95
+ * Index of the snap point to start fading from.
96
+ * Example: fadeFromIndex={0} will start fading from the first snap point.
97
+ * @default snapPoints.length - 1
98
+ */
99
+ fadeFromIndex?: number;
100
+ /**
101
+ * Whether to close the drawer when interacting outside of the drawer.
102
+ * @default true
103
+ */
104
+ closeOnInteractOutside?: boolean;
105
+ /**
106
+ * Whether to close the drawer when pressing the escape key.
107
+ * @default true
108
+ */
109
+ closeOnEscape?: boolean;
110
+ }
111
+ declare function useDrawer(props: UseDrawerProps): {
112
+ activeSnapPoint: string | number | null;
113
+ snapPoints: (string | number)[] | undefined;
114
+ setActiveSnapPoint: (value: react.SetStateAction<string | number | null>) => void;
115
+ drawerRef: react.RefObject<HTMLDivElement | null>;
116
+ overlayRef: react.RefObject<HTMLDivElement | null>;
117
+ shouldOverlayAnimate: boolean;
118
+ onOpenChange: ((open: boolean) => void) | undefined;
119
+ onPress: (event: React.PointerEvent<HTMLDivElement>) => void;
120
+ onRelease: (event: React.PointerEvent<HTMLDivElement> | null) => void;
121
+ onDrag: (event: React.PointerEvent<HTMLDivElement>) => void;
122
+ dismissible: boolean;
123
+ shouldAnimate: react.RefObject<boolean>;
124
+ handleOnly: boolean;
125
+ isOpen: boolean;
126
+ isDragging: boolean;
127
+ shouldFade: boolean;
128
+ closeDrawer: (fromWithin?: boolean) => void;
129
+ keyboardIsOpen: react.RefObject<boolean>;
130
+ modal: boolean;
131
+ snapPointsOffset: number[];
132
+ activeSnapPointIndex: number | null;
133
+ direction: "top" | "bottom" | "left" | "right";
134
+ noBodyStyles: boolean;
135
+ container: HTMLElement | null | undefined;
136
+ autoFocus: boolean;
137
+ setHasBeenOpened: react.Dispatch<react.SetStateAction<boolean>>;
138
+ setIsOpen: (value: react.SetStateAction<boolean>) => void;
139
+ closeOnInteractOutside: boolean;
140
+ closeOnEscape: boolean;
141
+ };
142
+
143
+ interface DrawerRootProps extends UseDrawerProps {
144
+ children?: react.ReactNode;
145
+ }
146
+ declare const DrawerRoot: (props: DrawerRootProps) => react_jsx_runtime.JSX.Element;
147
+ interface DrawerTriggerProps extends DialogPrimitive.DialogTriggerProps {
148
+ }
149
+ declare const DrawerTrigger: react.ForwardRefExoticComponent<DialogPrimitive.DialogTriggerProps & react.RefAttributes<HTMLButtonElement>>;
150
+ interface DrawerPositionerProps extends PrimitiveProps, react.HTMLAttributes<HTMLDivElement> {
151
+ }
152
+ declare const DrawerPositioner: react.ForwardRefExoticComponent<DrawerPositionerProps & react.RefAttributes<HTMLDivElement>>;
153
+ interface DrawerBackdropProps extends DialogPrimitive.DialogOverlayProps, react.HTMLAttributes<HTMLDivElement> {
154
+ }
155
+ declare const DrawerBackdrop: react.ForwardRefExoticComponent<DrawerBackdropProps & react.RefAttributes<HTMLDivElement>>;
156
+ interface DrawerContentProps extends DialogPrimitive.DialogContentProps, react.HTMLAttributes<HTMLDivElement> {
157
+ }
158
+ declare const DrawerContent: react.ForwardRefExoticComponent<DrawerContentProps & react.RefAttributes<HTMLDivElement>>;
159
+ interface DrawerTitleProps extends DialogPrimitive.DialogTitleProps {
160
+ }
161
+ declare const DrawerTitle: react.ForwardRefExoticComponent<DialogPrimitive.DialogTitleProps & react.RefAttributes<HTMLHeadingElement>>;
162
+ interface DrawerDescriptionProps extends DialogPrimitive.DialogDescriptionProps {
163
+ }
164
+ declare const DrawerDescription: react.ForwardRefExoticComponent<DialogPrimitive.DialogDescriptionProps & react.RefAttributes<HTMLParagraphElement>>;
165
+ interface DrawerCloseButtonProps extends DialogPrimitive.DialogCloseProps {
166
+ }
167
+ declare const DrawerCloseButton: react.ForwardRefExoticComponent<DrawerCloseButtonProps & react.RefAttributes<HTMLButtonElement>>;
168
+ interface DrawerHandleProps extends react.HTMLAttributes<HTMLDivElement> {
169
+ preventCycle?: boolean;
170
+ }
171
+ declare const DrawerHandle: react.ForwardRefExoticComponent<DrawerHandleProps & react.RefAttributes<HTMLDivElement>>;
172
+
173
+ type DrawerContextValue = ReturnType<typeof useDrawer>;
174
+ declare function useDrawerContext(): {
175
+ activeSnapPoint: string | number | null;
176
+ snapPoints: (string | number)[] | undefined;
177
+ setActiveSnapPoint: (value: react.SetStateAction<string | number | null>) => void;
178
+ drawerRef: react.RefObject<HTMLDivElement | null>;
179
+ overlayRef: react.RefObject<HTMLDivElement | null>;
180
+ shouldOverlayAnimate: boolean;
181
+ onOpenChange: ((open: boolean) => void) | undefined;
182
+ onPress: (event: React.PointerEvent<HTMLDivElement>) => void;
183
+ onRelease: (event: React.PointerEvent<HTMLDivElement> | null) => void;
184
+ onDrag: (event: React.PointerEvent<HTMLDivElement>) => void;
185
+ dismissible: boolean;
186
+ shouldAnimate: react.RefObject<boolean>;
187
+ handleOnly: boolean;
188
+ isOpen: boolean;
189
+ isDragging: boolean;
190
+ shouldFade: boolean;
191
+ closeDrawer: (fromWithin?: boolean) => void;
192
+ keyboardIsOpen: react.RefObject<boolean>;
193
+ modal: boolean;
194
+ snapPointsOffset: number[];
195
+ activeSnapPointIndex: number | null;
196
+ direction: "top" | "bottom" | "left" | "right";
197
+ noBodyStyles: boolean;
198
+ container: HTMLElement | null | undefined;
199
+ autoFocus: boolean;
200
+ setHasBeenOpened: react.Dispatch<react.SetStateAction<boolean>>;
201
+ setIsOpen: (value: react.SetStateAction<boolean>) => void;
202
+ closeOnInteractOutside: boolean;
203
+ closeOnEscape: boolean;
204
+ };
205
+
206
+ declare namespace Drawer_namespace {
207
+ 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 };
208
+ 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 };
209
+ }
210
+
211
+ export { Drawer_namespace as Drawer, DrawerBackdrop, DrawerCloseButton, DrawerContent, DrawerDescription, DrawerHandle, DrawerPositioner, DrawerRoot, DrawerTitle, DrawerTrigger, useDrawer, useDrawerContext };
212
+ export type { DrawerBackdropProps, DrawerCloseButtonProps, DrawerContentProps, DrawerContextValue, DrawerDescriptionProps, DrawerHandleProps, DrawerPositionerProps, DrawerRootProps, DrawerTitleProps, DrawerTriggerProps, UseDrawerProps };
package/lib/index.js ADDED
@@ -0,0 +1,17 @@
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
+
4
+ var Drawer_namespace = {
5
+ __proto__: null,
6
+ Backdrop: DrawerBackdrop,
7
+ CloseButton: DrawerCloseButton,
8
+ Content: DrawerContent,
9
+ Description: DrawerDescription,
10
+ Handle: DrawerHandle,
11
+ Positioner: DrawerPositioner,
12
+ Root: DrawerRoot,
13
+ Title: DrawerTitle,
14
+ Trigger: DrawerTrigger
15
+ };
16
+
17
+ export { Drawer_namespace as Drawer, DrawerBackdrop, DrawerCloseButton, DrawerContent, DrawerDescription, DrawerHandle, DrawerPositioner, DrawerRoot, DrawerTitle, DrawerTrigger };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seed-design/react-drawer",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/daangn/seed-design.git",
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 DialogProps } from "./useDrawer";
11
+ import { useDrawer, type UseDrawerProps } from "./useDrawer";
12
12
  import { DrawerProvider, useDrawerContext } from "./useDrawerContext";
13
13
 
14
- export interface DrawerRootProps extends DialogProps {
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, onOpenChange, modal } = props;
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 DialogProps } from "./useDrawer";
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 DialogProps {
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 Vaul
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: DialogProps) {
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 = false,
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("touchend", () => (isAllowedToDrag.current = false), { once: true });
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 = `0px`;
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(