base-vaul 0.0.1

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/README.md ADDED
@@ -0,0 +1,77 @@
1
+ > **Note**
2
+ > This repository is a port of the original **[Vaul](https://github.com/emilkowalski/vaul)** library by [Emil Kowalski](https://emilkowal.ski), migrated from `radix-ui` to `base-ui`.
3
+
4
+ ## Purpose
5
+
6
+ The primary goal of this repository is to provide a `base-ui` equivalent of Vaul while preserving the original API and behavior as closely as possible.
7
+
8
+ This port intentionally minimizes changes in order to:
9
+
10
+ - Reduce migration friction for existing Vaul users
11
+ - Keep parity with the upstream project
12
+ - Establish a stable baseline before introducing enhancements or divergence
13
+
14
+ ## Quick start
15
+
16
+ ### Installation
17
+
18
+ ```bash
19
+ npm install base-vaul
20
+ # or
21
+ pnpm add base-vaul
22
+ # or
23
+ yarn add base-vaul
24
+ ```
25
+
26
+ ### Basic usage
27
+
28
+ ```tsx
29
+ import { Drawer } from 'base-vaul';
30
+
31
+ export function Example() {
32
+ return (
33
+ <Drawer.Root>
34
+ <Drawer.Trigger>Open drawer</Drawer.Trigger>
35
+
36
+ <Drawer.Portal>
37
+ <Drawer.Overlay />
38
+ <Drawer.Content>
39
+ <Drawer.Title>Drawer title</Drawer.Title>
40
+ <Drawer.Description>Drawer description</Drawer.Description>
41
+ </Drawer.Content>
42
+ </Drawer.Portal>
43
+ </Drawer.Root>
44
+ );
45
+ }
46
+ ```
47
+
48
+ The API mirrors the original Vaul implementation as closely as possible, with the main differences coming from the underlying `base-ui` primitives.
49
+
50
+ ## Differences from the original Vaul
51
+
52
+ ### `render` instead of `asChild`
53
+
54
+ Since `base-ui` does not support `asChild`, components that relied on this pattern in `radix-ui` now expose a `render` prop instead.
55
+
56
+ **Original (Radix / Vaul):**
57
+
58
+ ```tsx
59
+ <Drawer.Trigger asChild>
60
+ <button>Open drawer</button>
61
+ </Drawer.Trigger>
62
+ ```
63
+
64
+ **This port (Base UI):**
65
+
66
+ ```tsx
67
+ <Drawer.Trigger render={<button {...props}>Open drawer</button>} />
68
+ ```
69
+
70
+ ## Roadmap
71
+
72
+ Planned next steps include:
73
+
74
+ - Writing proper documentation (usage, API, and migration notes)
75
+ - Solidifying the project structure with a well-defined monorepo setup
76
+ - Upgrading development dependencies and expanding test coverage
77
+ - Ongoing maintenance, bug fixes, and alignment with upstream changes where relevant
@@ -0,0 +1,147 @@
1
+ import * as _base_ui_react from '@base-ui/react';
2
+ import { Dialog } from '@base-ui/react';
3
+ import React from 'react';
4
+
5
+ type BaseUIMouseEvent = React.MouseEvent<HTMLDivElement> & {
6
+ preventBaseUIHandler: () => void;
7
+ readonly baseUIHandlerPrevented?: boolean | undefined;
8
+ };
9
+
10
+ interface WithFadeFromProps {
11
+ /**
12
+ * Array of numbers from 0 to 100 that corresponds to % of the screen a given snap point should take up.
13
+ * Should go from least visible. Example `[0.2, 0.5, 0.8]`.
14
+ * You can also use px values, which doesn't take screen height into account.
15
+ */
16
+ snapPoints: (number | string)[];
17
+ /**
18
+ * Index of a `snapPoint` from which the overlay fade should be applied. Defaults to the last snap point.
19
+ */
20
+ fadeFromIndex: number;
21
+ }
22
+ interface WithoutFadeFromProps {
23
+ /**
24
+ * Array of numbers from 0 to 100 that corresponds to % of the screen a given snap point should take up.
25
+ * Should go from least visible. Example `[0.2, 0.5, 0.8]`.
26
+ * You can also use px values, which doesn't take screen height into account.
27
+ */
28
+ snapPoints?: (number | string)[];
29
+ fadeFromIndex?: never;
30
+ }
31
+ type DialogProps = {
32
+ activeSnapPoint?: number | string | null;
33
+ setActiveSnapPoint?: (snapPoint: number | string | null) => void;
34
+ children?: React.ReactNode;
35
+ open?: boolean;
36
+ /**
37
+ * Number between 0 and 1 that determines when the drawer should be closed.
38
+ * Example: threshold of 0.5 would close the drawer if the user swiped for 50% of the height of the drawer or more.
39
+ * @default 0.25
40
+ */
41
+ closeThreshold?: number;
42
+ /**
43
+ * When `true` the `body` doesn't get any styles assigned from Vaul
44
+ */
45
+ noBodyStyles?: boolean;
46
+ onOpenChange?: (open: boolean) => void;
47
+ shouldScaleBackground?: boolean;
48
+ /**
49
+ * When `false` we don't change body's background color when the drawer is open.
50
+ * @default true
51
+ */
52
+ setBackgroundColorOnScale?: boolean;
53
+ /**
54
+ * Duration for which the drawer is not draggable after scrolling content inside of the drawer.
55
+ * @default 500ms
56
+ */
57
+ scrollLockTimeout?: number;
58
+ /**
59
+ * 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
60
+ */
61
+ fixed?: boolean;
62
+ /**
63
+ * When `true` only allows the drawer to be dragged by the `<Drawer.Handle />` component.
64
+ * @default false
65
+ */
66
+ handleOnly?: boolean;
67
+ /**
68
+ * When `false` dragging, clicking outside, pressing esc, etc. will not close the drawer.
69
+ * Use this in comination with the `open` prop, otherwise you won't be able to open/close the drawer.
70
+ * @default true
71
+ */
72
+ dismissible?: boolean;
73
+ onDrag?: (event: BaseUIMouseEvent, percentageDragged: number) => void;
74
+ onRelease?: (event: BaseUIMouseEvent, open: boolean) => void;
75
+ /**
76
+ * When `false` it allows to interact with elements outside of the drawer without closing it.
77
+ * @default true
78
+ */
79
+ modal?: boolean;
80
+ nested?: boolean;
81
+ onClose?: () => void;
82
+ /**
83
+ * Direction of the drawer. Can be `top` or `bottom`, `left`, `right`.
84
+ * @default 'bottom'
85
+ */
86
+ direction?: 'top' | 'bottom' | 'left' | 'right';
87
+ /**
88
+ * Opened by default, skips initial enter animation. Still reacts to `open` state changes
89
+ * @default false
90
+ */
91
+ defaultOpen?: boolean;
92
+ /**
93
+ * When set to `true` prevents scrolling on the document body on mount, and restores it on unmount.
94
+ * @default false
95
+ */
96
+ disablePreventScroll?: boolean;
97
+ /**
98
+ * When `true` Vaul will reposition inputs rather than scroll then into view if the keyboard is in the way.
99
+ * Setting it to `false` will fall back to the default browser behavior.
100
+ * @default true when {@link snapPoints} is defined
101
+ */
102
+ repositionInputs?: boolean;
103
+ /**
104
+ * Disabled velocity based swiping for snap points.
105
+ * This means that a snap point won't be skipped even if the velocity is high enough.
106
+ * Useful if each snap point in a drawer is equally important.
107
+ * @default false
108
+ */
109
+ snapToSequentialPoint?: boolean;
110
+ container?: HTMLElement | null;
111
+ /**
112
+ * 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.
113
+ * Useful to revert any state changes for example.
114
+ */
115
+ onAnimationEnd?: (open: boolean) => void;
116
+ preventScrollRestoration?: boolean;
117
+ autoFocus?: boolean;
118
+ } & (WithFadeFromProps | WithoutFadeFromProps);
119
+ declare function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRelease: onReleaseProp, snapPoints, shouldScaleBackground, setBackgroundColorOnScale, closeThreshold, scrollLockTimeout, dismissible, handleOnly, fadeFromIndex, activeSnapPoint: activeSnapPointProp, setActiveSnapPoint: setActiveSnapPointProp, fixed, modal, onClose, nested, noBodyStyles, direction, defaultOpen, disablePreventScroll, snapToSequentialPoint, preventScrollRestoration, repositionInputs, onAnimationEnd, container, autoFocus, }: DialogProps): React.JSX.Element;
120
+ declare const Overlay: React.ForwardRefExoticComponent<Omit<_base_ui_react.DialogBackdropProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
121
+ type ContentProps = React.ComponentPropsWithoutRef<typeof Dialog.Popup>;
122
+ declare const Content: React.ForwardRefExoticComponent<Omit<_base_ui_react.DialogPopupProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
123
+ type HandleProps = React.ComponentPropsWithoutRef<'div'> & {
124
+ preventCycle?: boolean;
125
+ };
126
+ declare const Handle: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
127
+ preventCycle?: boolean | undefined;
128
+ } & React.RefAttributes<HTMLDivElement>>;
129
+ declare function NestedRoot({ onDrag, onOpenChange, open: nestedIsOpen, ...rest }: DialogProps): React.JSX.Element;
130
+ type PortalProps = React.ComponentPropsWithoutRef<typeof Dialog.Portal>;
131
+ declare function Portal(props: PortalProps): React.JSX.Element;
132
+ declare const Drawer: {
133
+ Root: typeof Root;
134
+ NestedRoot: typeof NestedRoot;
135
+ Content: React.ForwardRefExoticComponent<Omit<_base_ui_react.DialogPopupProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
136
+ Overlay: React.ForwardRefExoticComponent<Omit<_base_ui_react.DialogBackdropProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
137
+ Trigger: Dialog.Trigger;
138
+ Portal: typeof Portal;
139
+ Handle: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
140
+ preventCycle?: boolean | undefined;
141
+ } & React.RefAttributes<HTMLDivElement>>;
142
+ Close: React.ForwardRefExoticComponent<_base_ui_react.DialogCloseProps & React.RefAttributes<HTMLButtonElement>>;
143
+ Title: React.ForwardRefExoticComponent<_base_ui_react.DialogTitleProps & React.RefAttributes<HTMLParagraphElement>>;
144
+ Description: React.ForwardRefExoticComponent<_base_ui_react.DialogDescriptionProps & React.RefAttributes<HTMLParagraphElement>>;
145
+ };
146
+
147
+ export { Content, type ContentProps, type DialogProps, Drawer, Handle, type HandleProps, NestedRoot, Overlay, Portal, Root, type WithFadeFromProps, type WithoutFadeFromProps };
@@ -0,0 +1,147 @@
1
+ import * as _base_ui_react from '@base-ui/react';
2
+ import { Dialog } from '@base-ui/react';
3
+ import React from 'react';
4
+
5
+ type BaseUIMouseEvent = React.MouseEvent<HTMLDivElement> & {
6
+ preventBaseUIHandler: () => void;
7
+ readonly baseUIHandlerPrevented?: boolean | undefined;
8
+ };
9
+
10
+ interface WithFadeFromProps {
11
+ /**
12
+ * Array of numbers from 0 to 100 that corresponds to % of the screen a given snap point should take up.
13
+ * Should go from least visible. Example `[0.2, 0.5, 0.8]`.
14
+ * You can also use px values, which doesn't take screen height into account.
15
+ */
16
+ snapPoints: (number | string)[];
17
+ /**
18
+ * Index of a `snapPoint` from which the overlay fade should be applied. Defaults to the last snap point.
19
+ */
20
+ fadeFromIndex: number;
21
+ }
22
+ interface WithoutFadeFromProps {
23
+ /**
24
+ * Array of numbers from 0 to 100 that corresponds to % of the screen a given snap point should take up.
25
+ * Should go from least visible. Example `[0.2, 0.5, 0.8]`.
26
+ * You can also use px values, which doesn't take screen height into account.
27
+ */
28
+ snapPoints?: (number | string)[];
29
+ fadeFromIndex?: never;
30
+ }
31
+ type DialogProps = {
32
+ activeSnapPoint?: number | string | null;
33
+ setActiveSnapPoint?: (snapPoint: number | string | null) => void;
34
+ children?: React.ReactNode;
35
+ open?: boolean;
36
+ /**
37
+ * Number between 0 and 1 that determines when the drawer should be closed.
38
+ * Example: threshold of 0.5 would close the drawer if the user swiped for 50% of the height of the drawer or more.
39
+ * @default 0.25
40
+ */
41
+ closeThreshold?: number;
42
+ /**
43
+ * When `true` the `body` doesn't get any styles assigned from Vaul
44
+ */
45
+ noBodyStyles?: boolean;
46
+ onOpenChange?: (open: boolean) => void;
47
+ shouldScaleBackground?: boolean;
48
+ /**
49
+ * When `false` we don't change body's background color when the drawer is open.
50
+ * @default true
51
+ */
52
+ setBackgroundColorOnScale?: boolean;
53
+ /**
54
+ * Duration for which the drawer is not draggable after scrolling content inside of the drawer.
55
+ * @default 500ms
56
+ */
57
+ scrollLockTimeout?: number;
58
+ /**
59
+ * 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
60
+ */
61
+ fixed?: boolean;
62
+ /**
63
+ * When `true` only allows the drawer to be dragged by the `<Drawer.Handle />` component.
64
+ * @default false
65
+ */
66
+ handleOnly?: boolean;
67
+ /**
68
+ * When `false` dragging, clicking outside, pressing esc, etc. will not close the drawer.
69
+ * Use this in comination with the `open` prop, otherwise you won't be able to open/close the drawer.
70
+ * @default true
71
+ */
72
+ dismissible?: boolean;
73
+ onDrag?: (event: BaseUIMouseEvent, percentageDragged: number) => void;
74
+ onRelease?: (event: BaseUIMouseEvent, open: boolean) => void;
75
+ /**
76
+ * When `false` it allows to interact with elements outside of the drawer without closing it.
77
+ * @default true
78
+ */
79
+ modal?: boolean;
80
+ nested?: boolean;
81
+ onClose?: () => void;
82
+ /**
83
+ * Direction of the drawer. Can be `top` or `bottom`, `left`, `right`.
84
+ * @default 'bottom'
85
+ */
86
+ direction?: 'top' | 'bottom' | 'left' | 'right';
87
+ /**
88
+ * Opened by default, skips initial enter animation. Still reacts to `open` state changes
89
+ * @default false
90
+ */
91
+ defaultOpen?: boolean;
92
+ /**
93
+ * When set to `true` prevents scrolling on the document body on mount, and restores it on unmount.
94
+ * @default false
95
+ */
96
+ disablePreventScroll?: boolean;
97
+ /**
98
+ * When `true` Vaul will reposition inputs rather than scroll then into view if the keyboard is in the way.
99
+ * Setting it to `false` will fall back to the default browser behavior.
100
+ * @default true when {@link snapPoints} is defined
101
+ */
102
+ repositionInputs?: boolean;
103
+ /**
104
+ * Disabled velocity based swiping for snap points.
105
+ * This means that a snap point won't be skipped even if the velocity is high enough.
106
+ * Useful if each snap point in a drawer is equally important.
107
+ * @default false
108
+ */
109
+ snapToSequentialPoint?: boolean;
110
+ container?: HTMLElement | null;
111
+ /**
112
+ * 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.
113
+ * Useful to revert any state changes for example.
114
+ */
115
+ onAnimationEnd?: (open: boolean) => void;
116
+ preventScrollRestoration?: boolean;
117
+ autoFocus?: boolean;
118
+ } & (WithFadeFromProps | WithoutFadeFromProps);
119
+ declare function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRelease: onReleaseProp, snapPoints, shouldScaleBackground, setBackgroundColorOnScale, closeThreshold, scrollLockTimeout, dismissible, handleOnly, fadeFromIndex, activeSnapPoint: activeSnapPointProp, setActiveSnapPoint: setActiveSnapPointProp, fixed, modal, onClose, nested, noBodyStyles, direction, defaultOpen, disablePreventScroll, snapToSequentialPoint, preventScrollRestoration, repositionInputs, onAnimationEnd, container, autoFocus, }: DialogProps): React.JSX.Element;
120
+ declare const Overlay: React.ForwardRefExoticComponent<Omit<_base_ui_react.DialogBackdropProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
121
+ type ContentProps = React.ComponentPropsWithoutRef<typeof Dialog.Popup>;
122
+ declare const Content: React.ForwardRefExoticComponent<Omit<_base_ui_react.DialogPopupProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
123
+ type HandleProps = React.ComponentPropsWithoutRef<'div'> & {
124
+ preventCycle?: boolean;
125
+ };
126
+ declare const Handle: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
127
+ preventCycle?: boolean | undefined;
128
+ } & React.RefAttributes<HTMLDivElement>>;
129
+ declare function NestedRoot({ onDrag, onOpenChange, open: nestedIsOpen, ...rest }: DialogProps): React.JSX.Element;
130
+ type PortalProps = React.ComponentPropsWithoutRef<typeof Dialog.Portal>;
131
+ declare function Portal(props: PortalProps): React.JSX.Element;
132
+ declare const Drawer: {
133
+ Root: typeof Root;
134
+ NestedRoot: typeof NestedRoot;
135
+ Content: React.ForwardRefExoticComponent<Omit<_base_ui_react.DialogPopupProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
136
+ Overlay: React.ForwardRefExoticComponent<Omit<_base_ui_react.DialogBackdropProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
137
+ Trigger: Dialog.Trigger;
138
+ Portal: typeof Portal;
139
+ Handle: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
140
+ preventCycle?: boolean | undefined;
141
+ } & React.RefAttributes<HTMLDivElement>>;
142
+ Close: React.ForwardRefExoticComponent<_base_ui_react.DialogCloseProps & React.RefAttributes<HTMLButtonElement>>;
143
+ Title: React.ForwardRefExoticComponent<_base_ui_react.DialogTitleProps & React.RefAttributes<HTMLParagraphElement>>;
144
+ Description: React.ForwardRefExoticComponent<_base_ui_react.DialogDescriptionProps & React.RefAttributes<HTMLParagraphElement>>;
145
+ };
146
+
147
+ export { Content, type ContentProps, type DialogProps, Drawer, Handle, type HandleProps, NestedRoot, Overlay, Portal, Root, type WithFadeFromProps, type WithoutFadeFromProps };