Skip to content

Commit c165de0

Browse files
committed
bit more
1 parent e67d68c commit c165de0

23 files changed

+120
-869
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<script lang="ts">
2+
import { box, mergeProps } from "svelte-toolbelt";
3+
import { useId } from "bits-ui";
4+
import type { DrawerHandleProps } from "./types.js";
5+
import { useDrawerHandle } from "$lib/vaul.svelte.js";
6+
7+
let {
8+
id = useId(),
9+
ref = $bindable(null),
10+
preventCycle = false,
11+
children,
12+
...restProps
13+
}: DrawerHandleProps = $props();
14+
15+
const handleState = useDrawerHandle({
16+
id: box.with(() => id),
17+
ref: box.with(
18+
() => ref,
19+
(v) => (ref = v)
20+
),
21+
preventCycle: box.with(() => preventCycle),
22+
});
23+
24+
const mergedProps = $derived(mergeProps(restProps, handleState.props));
25+
</script>
26+
27+
<div {...mergedProps}>
28+
<span {...handleState.hitAreaProps}>
29+
{@render children?.()}
30+
</span>
31+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<script lang="ts">
2+
import DrawerRoot from "./drawer.svelte";
3+
import type { DrawerRootProps } from "./types.js";
4+
import { noop } from "$lib/internal/helpers/noop.js";
5+
import { getDrawerRootContext } from "$lib/vaul.svelte.js";
6+
7+
let {
8+
onOpenChange = noop,
9+
onDrag = noop,
10+
...restProps
11+
}: Omit<DrawerRootProps, "nested" | "onRelease" | "onClose"> = $props();
12+
13+
const rootState = getDrawerRootContext();
14+
</script>
15+
16+
<DrawerRoot
17+
nested
18+
onClose={() => rootState.onNestedOpenChange(false)}
19+
onDrag={(e, p) => {
20+
rootState.onNestedDrag(e, p);
21+
onDrag(e, p);
22+
}}
23+
onOpenChange={(o) => {
24+
if (o) {
25+
rootState.onNestedOpenChange(o);
26+
}
27+
onOpenChange(o);
28+
}}
29+
onRelease={(e, o) => rootState.onNestedRelease(e, o)}
30+
{...restProps}
31+
/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Dialog as DrawerPrimitive } from "bits-ui";
2+
3+
export { default as Root } from "./drawer.svelte";
4+
export { default as Content } from "./drawer-content.svelte";
5+
export { default as Overlay } from "./drawer-overlay.svelte";
6+
export { default as NestedRoot } from "./drawer-nested.svelte";
7+
export { default as Handle } from "./drawer-handle.svelte";
8+
9+
export const Portal = DrawerPrimitive.Portal;
10+
export const Trigger = DrawerPrimitive.Trigger;
11+
export const Title = DrawerPrimitive.Title;
12+
export const Description = DrawerPrimitive.Description;
13+
export const Close = DrawerPrimitive.Close;
14+
15+
export type PortalProps = DrawerPrimitive.PortalProps;
16+
export type TriggerProps = DrawerPrimitive.TriggerProps;
17+
export type TitleProps = DrawerPrimitive.TitleProps;
18+
export type DescriptionProps = DrawerPrimitive.DescriptionProps;
19+
export type CloseProps = DrawerPrimitive.CloseProps;
20+
21+
export type {
22+
DrawerRootProps as RootProps,
23+
DrawerContentProps as ContentProps,
24+
DrawerOverlayProps as OverlayProps,
25+
DrawerRootProps as NestedRootProps,
26+
DrawerHandleProps as HandleProps,
27+
} from "./types.js";

packages/vaul-svelte/src/lib/components/types.ts packages/vaul-svelte/src/lib/components/drawer/types.ts

+17
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import type {
55
DialogOverlayPropsWithoutHTML,
66
Dialog as DialogPrimitive,
77
DialogTitlePropsWithoutHTML,
8+
PrimitiveDivAttributes,
9+
WithChild,
810
} from "bits-ui";
911
import type { WithChildren, Without } from "svelte-toolbelt";
1012
import type { DrawerDirection, OnChangeFn } from "$lib/types.js";
@@ -176,3 +178,18 @@ export type DrawerCloseProps = DialogPrimitive.CloseProps;
176178
export type DrawerContentPropsWithoutHTML = DialogContentPropsWithoutHTML;
177179

178180
export type DrawerContentProps = DialogPrimitive.ContentProps;
181+
182+
export type DrawerHandlePropsWithoutHTML = Omit<
183+
WithChild<{
184+
/**
185+
* Whether to prevent cycling the snap points when the handle is pressed.
186+
*
187+
* @default false
188+
*/
189+
preventCycle?: boolean;
190+
}>,
191+
"child"
192+
>;
193+
194+
export type DrawerHandleProps = DrawerHandlePropsWithoutHTML &
195+
Without<PrimitiveDivAttributes, DrawerHandlePropsWithoutHTML>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * as Drawer from "./drawer/index.js";

packages/vaul-svelte/src/lib/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "./vaul/index.js";
1+
export * from "./components/index.js";

packages/vaul-svelte/src/lib/vaul.svelte.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { onMount, tick, untrack } from "svelte";
1+
import { tick, untrack } from "svelte";
22
import {
33
type ReadableBoxedValues,
44
type WithRefProps,
@@ -8,7 +8,7 @@ import {
88
useRefById,
99
} from "svelte-toolbelt";
1010
import { isBottomOrRight, isInput, isVertical } from "./internal/helpers/is.js";
11-
import { getTranslate, resetStyles, setStyles, styleToString } from "./internal/helpers/style.js";
11+
import { getTranslate, resetStyles, setStyles } from "./internal/helpers/style.js";
1212
import { TRANSITIONS, VELOCITY_THRESHOLD } from "./internal/constants.js";
1313
import { isIOS, preventScroll } from "./internal/prevent-scroll.js";
1414
import { PositionFixed } from "./position-fixed.svelte.js";
@@ -1133,6 +1133,10 @@ class DrawerRootState {
11331133
createOverlayState = (props: DrawerOverlayStateProps) => {
11341134
return new DrawerOverlayState(props, this);
11351135
};
1136+
1137+
createHandleState = (props: DrawerHandleStateProps) => {
1138+
return new DrawerHandleState(props, this);
1139+
};
11361140
}
11371141

11381142
type DrawerContentStateProps = WithRefProps;
@@ -1452,7 +1456,8 @@ class DrawerHandleState {
14521456
// CONTEXT
14531457
////////////////////////////////////
14541458

1455-
const [setDrawerRootContext, getDrawerRootContext] = createContext<DrawerRootState>("Drawer.Root");
1459+
export const [setDrawerRootContext, getDrawerRootContext] =
1460+
createContext<DrawerRootState>("Drawer.Root");
14561461

14571462
export function useDrawerRoot(props: DrawerRootStateProps) {
14581463
return setDrawerRootContext(new DrawerRootState(props));
@@ -1466,6 +1471,10 @@ export function useDrawerOverlay(props: DrawerOverlayStateProps) {
14661471
return getDrawerRootContext().createOverlayState(props);
14671472
}
14681473

1474+
export function useDrawerHandle(props: DrawerHandleStateProps) {
1475+
return getDrawerRootContext().createHandleState(props);
1476+
}
1477+
14691478
////////////////////////////////////
14701479
// HELPERS
14711480
////////////////////////////////////

packages/vaul-svelte/src/lib/vaul/components/close-wrapper.svelte

-45
This file was deleted.

packages/vaul-svelte/src/lib/vaul/components/close.svelte

-57
This file was deleted.

packages/vaul-svelte/src/lib/vaul/components/content.svelte

-46
This file was deleted.

packages/vaul-svelte/src/lib/vaul/components/index.ts

-15
This file was deleted.

0 commit comments

Comments
 (0)