base-vaul 1.0.0 → 1.2.0
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/dist/index.d.mts +11 -28
- package/dist/index.mjs +15 -10
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -31,11 +31,9 @@ interface WithoutFadeFromProps {
|
|
|
31
31
|
snapPoints?: (number | string)[];
|
|
32
32
|
fadeFromIndex?: never;
|
|
33
33
|
}
|
|
34
|
-
type DialogProps = {
|
|
34
|
+
type DialogProps = Dialog.Root.Props & {
|
|
35
35
|
activeSnapPoint?: number | string | null;
|
|
36
36
|
setActiveSnapPoint?: (snapPoint: number | string | null) => void;
|
|
37
|
-
children?: React.ReactNode;
|
|
38
|
-
open?: boolean;
|
|
39
37
|
/**
|
|
40
38
|
* Number between 0 and 1 that determines when the drawer should be closed.
|
|
41
39
|
* Example: threshold of 0.5 would close the drawer if the user swiped for 50% of the height of the drawer or more.
|
|
@@ -75,23 +73,13 @@ type DialogProps = {
|
|
|
75
73
|
dismissible?: boolean;
|
|
76
74
|
onDrag?: (event: BaseUIMouseEvent, percentageDragged: number) => void;
|
|
77
75
|
onRelease?: (event: BaseUIMouseEvent, open: boolean) => void;
|
|
78
|
-
/**
|
|
79
|
-
* When `false` it allows to interact with elements outside of the drawer without closing it.
|
|
80
|
-
* @default true
|
|
81
|
-
*/
|
|
82
|
-
modal?: boolean;
|
|
83
76
|
nested?: boolean;
|
|
84
77
|
onClose?: () => void;
|
|
85
78
|
/**
|
|
86
79
|
* Direction of the drawer. Can be `top` or `bottom`, `left`, `right`.
|
|
87
80
|
* @default 'bottom'
|
|
88
81
|
*/
|
|
89
|
-
direction?:
|
|
90
|
-
/**
|
|
91
|
-
* Opened by default, skips initial enter animation. Still reacts to `open` state changes
|
|
92
|
-
* @default false
|
|
93
|
-
*/
|
|
94
|
-
defaultOpen?: boolean;
|
|
82
|
+
direction?: 'top' | 'bottom' | 'left' | 'right';
|
|
95
83
|
/**
|
|
96
84
|
* When set to `true` prevents scrolling on the document body on mount, and restores it on unmount.
|
|
97
85
|
* @default false
|
|
@@ -111,17 +99,13 @@ type DialogProps = {
|
|
|
111
99
|
*/
|
|
112
100
|
snapToSequentialPoint?: boolean;
|
|
113
101
|
container?: HTMLElement | null;
|
|
114
|
-
/**
|
|
115
|
-
* 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.
|
|
116
|
-
* Useful to revert any state changes for example.
|
|
117
|
-
*/
|
|
118
|
-
onAnimationEnd?: (open: boolean) => void;
|
|
119
102
|
preventScrollRestoration?: boolean;
|
|
120
103
|
autoFocus?: boolean;
|
|
121
104
|
} & (WithFadeFromProps | WithoutFadeFromProps);
|
|
122
105
|
declare function Root({
|
|
123
106
|
open: openProp,
|
|
124
107
|
onOpenChange,
|
|
108
|
+
onOpenChangeComplete,
|
|
125
109
|
children,
|
|
126
110
|
onDrag: onDragProp,
|
|
127
111
|
onRelease: onReleaseProp,
|
|
@@ -146,14 +130,13 @@ declare function Root({
|
|
|
146
130
|
snapToSequentialPoint,
|
|
147
131
|
preventScrollRestoration,
|
|
148
132
|
repositionInputs,
|
|
149
|
-
onAnimationEnd,
|
|
150
133
|
container,
|
|
151
134
|
autoFocus
|
|
152
135
|
}: DialogProps): react_jsx_runtime0.JSX.Element;
|
|
153
|
-
declare const Overlay: React.ForwardRefExoticComponent<Omit<_base_ui_react0.DialogBackdropProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
136
|
+
declare const Overlay: React.ForwardRefExoticComponent<Omit<Omit<_base_ui_react0.DialogBackdropProps, "ref"> & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
154
137
|
type ContentProps = React.ComponentPropsWithoutRef<typeof Dialog.Popup>;
|
|
155
|
-
declare const Content: React.ForwardRefExoticComponent<Omit<_base_ui_react0.DialogPopupProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
156
|
-
type HandleProps = React.ComponentPropsWithoutRef<
|
|
138
|
+
declare const Content: React.ForwardRefExoticComponent<Omit<Omit<_base_ui_react0.DialogPopupProps, "ref"> & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
139
|
+
type HandleProps = React.ComponentPropsWithoutRef<'div'> & {
|
|
157
140
|
preventCycle?: boolean;
|
|
158
141
|
};
|
|
159
142
|
declare const Handle: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
@@ -170,16 +153,16 @@ declare function Portal(props: PortalProps): react_jsx_runtime0.JSX.Element;
|
|
|
170
153
|
declare const Drawer: {
|
|
171
154
|
Root: typeof Root;
|
|
172
155
|
NestedRoot: typeof NestedRoot;
|
|
173
|
-
Content: React.ForwardRefExoticComponent<Omit<_base_ui_react0.DialogPopupProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
174
|
-
Overlay: React.ForwardRefExoticComponent<Omit<_base_ui_react0.DialogBackdropProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
156
|
+
Content: React.ForwardRefExoticComponent<Omit<Omit<_base_ui_react0.DialogPopupProps, "ref"> & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
157
|
+
Overlay: React.ForwardRefExoticComponent<Omit<Omit<_base_ui_react0.DialogBackdropProps, "ref"> & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
175
158
|
Trigger: Dialog.Trigger;
|
|
176
159
|
Portal: typeof Portal;
|
|
177
160
|
Handle: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
178
161
|
preventCycle?: boolean;
|
|
179
162
|
} & React.RefAttributes<HTMLDivElement>>;
|
|
180
|
-
Close: React.ForwardRefExoticComponent<_base_ui_react0.DialogCloseProps & React.RefAttributes<HTMLButtonElement>>;
|
|
181
|
-
Title: React.ForwardRefExoticComponent<_base_ui_react0.DialogTitleProps & React.RefAttributes<
|
|
182
|
-
Description: React.ForwardRefExoticComponent<_base_ui_react0.DialogDescriptionProps & React.RefAttributes<HTMLParagraphElement>>;
|
|
163
|
+
Close: React.ForwardRefExoticComponent<Omit<_base_ui_react0.DialogCloseProps, "ref"> & React.RefAttributes<HTMLButtonElement>>;
|
|
164
|
+
Title: React.ForwardRefExoticComponent<Omit<_base_ui_react0.DialogTitleProps, "ref"> & React.RefAttributes<HTMLHeadingElement>>;
|
|
165
|
+
Description: React.ForwardRefExoticComponent<Omit<_base_ui_react0.DialogDescriptionProps, "ref"> & React.RefAttributes<HTMLParagraphElement>>;
|
|
183
166
|
};
|
|
184
167
|
//#endregion
|
|
185
168
|
export { Content, ContentProps, DialogProps, Drawer, Handle, HandleProps, NestedRoot, Overlay, Portal, Root, WithFadeFromProps, WithoutFadeFromProps };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
2
|
|
|
3
3
|
import { Dialog } from "@base-ui/react";
|
|
4
4
|
import * as React$1 from "react";
|
|
@@ -663,17 +663,21 @@ function usePositionFixed({ isOpen, modal, nested, hasBeenOpened, preventScrollR
|
|
|
663
663
|
|
|
664
664
|
//#endregion
|
|
665
665
|
//#region src/index.tsx
|
|
666
|
-
function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRelease: onReleaseProp, snapPoints, shouldScaleBackground = false, setBackgroundColorOnScale = true, 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 = false, direction = "bottom", defaultOpen = false, disablePreventScroll = true, snapToSequentialPoint = false, preventScrollRestoration = false, repositionInputs = true,
|
|
666
|
+
function Root({ open: openProp, onOpenChange, onOpenChangeComplete, children, onDrag: onDragProp, onRelease: onReleaseProp, snapPoints, shouldScaleBackground = false, setBackgroundColorOnScale = true, 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 = false, direction = "bottom", defaultOpen = false, disablePreventScroll = true, snapToSequentialPoint = false, preventScrollRestoration = false, repositionInputs = true, container, autoFocus = false }) {
|
|
667
|
+
const isModal = modal === true || modal === "trap-focus";
|
|
667
668
|
const [isOpen = false, setIsOpen] = useControllableState({
|
|
668
669
|
defaultProp: defaultOpen,
|
|
669
670
|
prop: openProp,
|
|
670
671
|
onChange: (o) => {
|
|
671
|
-
onOpenChange?.(o
|
|
672
|
+
onOpenChange?.(o, {
|
|
673
|
+
reason: "none",
|
|
674
|
+
preventUnmountOnClose: () => {}
|
|
675
|
+
});
|
|
672
676
|
if (!o && !nested) restorePositionSetting();
|
|
673
677
|
setTimeout(() => {
|
|
674
|
-
|
|
678
|
+
onOpenChangeComplete?.(o);
|
|
675
679
|
}, TRANSITIONS.DURATION * 1e3);
|
|
676
|
-
if (o && !
|
|
680
|
+
if (o && !isModal) {
|
|
677
681
|
if (typeof window !== "undefined") window.requestAnimationFrame(() => {
|
|
678
682
|
document.body.style.pointerEvents = "auto";
|
|
679
683
|
});
|
|
@@ -713,10 +717,10 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
|
|
|
713
717
|
container,
|
|
714
718
|
snapToSequentialPoint
|
|
715
719
|
});
|
|
716
|
-
usePreventScroll({ isDisabled: !isOpen || isDragging || !
|
|
720
|
+
usePreventScroll({ isDisabled: !isOpen || isDragging || !isModal || justReleased || !hasBeenOpened || !repositionInputs || !disablePreventScroll });
|
|
717
721
|
const { restorePositionSetting } = usePositionFixed({
|
|
718
722
|
isOpen,
|
|
719
|
-
modal,
|
|
723
|
+
modal: isModal,
|
|
720
724
|
nested: nested ?? false,
|
|
721
725
|
hasBeenOpened,
|
|
722
726
|
preventScrollRestoration,
|
|
@@ -996,10 +1000,10 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
|
|
|
996
1000
|
});
|
|
997
1001
|
}
|
|
998
1002
|
React.useEffect(() => {
|
|
999
|
-
if (!
|
|
1003
|
+
if (!isModal) window.requestAnimationFrame(() => {
|
|
1000
1004
|
document.body.style.pointerEvents = "auto";
|
|
1001
1005
|
});
|
|
1002
|
-
}, [
|
|
1006
|
+
}, [isModal]);
|
|
1003
1007
|
return /* @__PURE__ */ jsx(Dialog.Root, {
|
|
1004
1008
|
defaultOpen,
|
|
1005
1009
|
onOpenChange: (open) => {
|
|
@@ -1010,6 +1014,7 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
|
|
|
1010
1014
|
},
|
|
1011
1015
|
open: isOpen,
|
|
1012
1016
|
modal,
|
|
1017
|
+
onOpenChangeComplete,
|
|
1013
1018
|
children: /* @__PURE__ */ jsx(DrawerContext.Provider, {
|
|
1014
1019
|
value: {
|
|
1015
1020
|
activeSnapPoint,
|
|
@@ -1032,7 +1037,7 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
|
|
|
1032
1037
|
onNestedOpenChange,
|
|
1033
1038
|
onNestedRelease,
|
|
1034
1039
|
keyboardIsOpen,
|
|
1035
|
-
modal,
|
|
1040
|
+
modal: isModal,
|
|
1036
1041
|
snapPointsOffset,
|
|
1037
1042
|
activeSnapPointIndex,
|
|
1038
1043
|
direction,
|