feat(drawer): add shadcn drawer
This commit is contained in:
7
src/shared/shadcn/ui/drawer/drawer-close.svelte
Normal file
7
src/shared/shadcn/ui/drawer/drawer-close.svelte
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Drawer as DrawerPrimitive } from 'vaul-svelte';
|
||||||
|
|
||||||
|
let { ref = $bindable(null), ...restProps }: DrawerPrimitive.CloseProps = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<DrawerPrimitive.Close bind:ref data-slot="drawer-close" {...restProps} />
|
||||||
39
src/shared/shadcn/ui/drawer/drawer-content.svelte
Normal file
39
src/shared/shadcn/ui/drawer/drawer-content.svelte
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { cn } from '$shared/shadcn/utils/shadcn-utils.js';
|
||||||
|
import type { WithoutChildrenOrChild } from '$shared/shadcn/utils/shadcn-utils.js';
|
||||||
|
import type { ComponentProps } from 'svelte';
|
||||||
|
import { Drawer as DrawerPrimitive } from 'vaul-svelte';
|
||||||
|
import DrawerOverlay from './drawer-overlay.svelte';
|
||||||
|
import DrawerPortal from './drawer-portal.svelte';
|
||||||
|
|
||||||
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
|
class: className,
|
||||||
|
portalProps,
|
||||||
|
children,
|
||||||
|
...restProps
|
||||||
|
}: DrawerPrimitive.ContentProps & {
|
||||||
|
portalProps?: WithoutChildrenOrChild<ComponentProps<typeof DrawerPortal>>;
|
||||||
|
} = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<DrawerPortal {...portalProps}>
|
||||||
|
<DrawerOverlay />
|
||||||
|
<DrawerPrimitive.Content
|
||||||
|
bind:ref
|
||||||
|
data-slot="drawer-content"
|
||||||
|
class={cn(
|
||||||
|
'group/drawer-content bg-background fixed z-50 flex h-auto flex-col',
|
||||||
|
'data-[vaul-drawer-direction=top]:inset-x-0 data-[vaul-drawer-direction=top]:top-0 data-[vaul-drawer-direction=top]:mb-24 data-[vaul-drawer-direction=top]:max-h-[80vh] data-[vaul-drawer-direction=top]:rounded-b-lg data-[vaul-drawer-direction=top]:border-b',
|
||||||
|
'data-[vaul-drawer-direction=bottom]:inset-x-0 data-[vaul-drawer-direction=bottom]:bottom-0 data-[vaul-drawer-direction=bottom]:mt-24 data-[vaul-drawer-direction=bottom]:max-h-[80vh] data-[vaul-drawer-direction=bottom]:rounded-t-lg data-[vaul-drawer-direction=bottom]:border-t',
|
||||||
|
'data-[vaul-drawer-direction=right]:inset-y-0 data-[vaul-drawer-direction=right]:end-0 data-[vaul-drawer-direction=right]:w-3/4 data-[vaul-drawer-direction=right]:border-s data-[vaul-drawer-direction=right]:sm:max-w-sm',
|
||||||
|
'data-[vaul-drawer-direction=left]:inset-y-0 data-[vaul-drawer-direction=left]:start-0 data-[vaul-drawer-direction=left]:w-3/4 data-[vaul-drawer-direction=left]:border-e data-[vaul-drawer-direction=left]:sm:max-w-sm',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...restProps}
|
||||||
|
>
|
||||||
|
<div class="bg-muted mx-auto mt-4 hidden h-2 w-[100px] shrink-0 rounded-full group-data-[vaul-drawer-direction=bottom]/drawer-content:block">
|
||||||
|
</div>
|
||||||
|
{@render children?.()}
|
||||||
|
</DrawerPrimitive.Content>
|
||||||
|
</DrawerPortal>
|
||||||
17
src/shared/shadcn/ui/drawer/drawer-description.svelte
Normal file
17
src/shared/shadcn/ui/drawer/drawer-description.svelte
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { cn } from '$shared/shadcn/utils/shadcn-utils.js';
|
||||||
|
import { Drawer as DrawerPrimitive } from 'vaul-svelte';
|
||||||
|
|
||||||
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
|
class: className,
|
||||||
|
...restProps
|
||||||
|
}: DrawerPrimitive.DescriptionProps = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<DrawerPrimitive.Description
|
||||||
|
bind:ref
|
||||||
|
data-slot="drawer-description"
|
||||||
|
class={cn('text-muted-foreground text-sm', className)}
|
||||||
|
{...restProps}
|
||||||
|
/>
|
||||||
23
src/shared/shadcn/ui/drawer/drawer-footer.svelte
Normal file
23
src/shared/shadcn/ui/drawer/drawer-footer.svelte
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import {
|
||||||
|
type WithElementRef,
|
||||||
|
cn,
|
||||||
|
} from '$shared/shadcn/utils/shadcn-utils.js';
|
||||||
|
import type { HTMLAttributes } from 'svelte/elements';
|
||||||
|
|
||||||
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
|
class: className,
|
||||||
|
children,
|
||||||
|
...restProps
|
||||||
|
}: WithElementRef<HTMLAttributes<HTMLDivElement>> = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div
|
||||||
|
bind:this={ref}
|
||||||
|
data-slot="drawer-footer"
|
||||||
|
class={cn('mt-auto flex flex-col gap-2 p-4', className)}
|
||||||
|
{...restProps}
|
||||||
|
>
|
||||||
|
{@render children?.()}
|
||||||
|
</div>
|
||||||
23
src/shared/shadcn/ui/drawer/drawer-header.svelte
Normal file
23
src/shared/shadcn/ui/drawer/drawer-header.svelte
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import {
|
||||||
|
type WithElementRef,
|
||||||
|
cn,
|
||||||
|
} from '$shared/shadcn/utils/shadcn-utils.js';
|
||||||
|
import type { HTMLAttributes } from 'svelte/elements';
|
||||||
|
|
||||||
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
|
class: className,
|
||||||
|
children,
|
||||||
|
...restProps
|
||||||
|
}: WithElementRef<HTMLAttributes<HTMLDivElement>> = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div
|
||||||
|
bind:this={ref}
|
||||||
|
data-slot="drawer-header"
|
||||||
|
class={cn('flex flex-col gap-1.5 p-4', className)}
|
||||||
|
{...restProps}
|
||||||
|
>
|
||||||
|
{@render children?.()}
|
||||||
|
</div>
|
||||||
12
src/shared/shadcn/ui/drawer/drawer-nested.svelte
Normal file
12
src/shared/shadcn/ui/drawer/drawer-nested.svelte
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Drawer as DrawerPrimitive } from 'vaul-svelte';
|
||||||
|
|
||||||
|
let {
|
||||||
|
shouldScaleBackground = true,
|
||||||
|
open = $bindable(false),
|
||||||
|
activeSnapPoint = $bindable(null),
|
||||||
|
...restProps
|
||||||
|
}: DrawerPrimitive.RootProps = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<DrawerPrimitive.NestedRoot {shouldScaleBackground} bind:open bind:activeSnapPoint {...restProps} />
|
||||||
20
src/shared/shadcn/ui/drawer/drawer-overlay.svelte
Normal file
20
src/shared/shadcn/ui/drawer/drawer-overlay.svelte
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { cn } from '$shared/shadcn/utils/shadcn-utils.js';
|
||||||
|
import { Drawer as DrawerPrimitive } from 'vaul-svelte';
|
||||||
|
|
||||||
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
|
class: className,
|
||||||
|
...restProps
|
||||||
|
}: DrawerPrimitive.OverlayProps = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<DrawerPrimitive.Overlay
|
||||||
|
bind:ref
|
||||||
|
data-slot="drawer-overlay"
|
||||||
|
class={cn(
|
||||||
|
'data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...restProps}
|
||||||
|
/>
|
||||||
7
src/shared/shadcn/ui/drawer/drawer-portal.svelte
Normal file
7
src/shared/shadcn/ui/drawer/drawer-portal.svelte
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Drawer as DrawerPrimitive } from 'vaul-svelte';
|
||||||
|
|
||||||
|
let { ...restProps }: DrawerPrimitive.PortalProps = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<DrawerPrimitive.Portal {...restProps} />
|
||||||
17
src/shared/shadcn/ui/drawer/drawer-title.svelte
Normal file
17
src/shared/shadcn/ui/drawer/drawer-title.svelte
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { cn } from '$shared/shadcn/utils/shadcn-utils.js';
|
||||||
|
import { Drawer as DrawerPrimitive } from 'vaul-svelte';
|
||||||
|
|
||||||
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
|
class: className,
|
||||||
|
...restProps
|
||||||
|
}: DrawerPrimitive.TitleProps = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<DrawerPrimitive.Title
|
||||||
|
bind:ref
|
||||||
|
data-slot="drawer-title"
|
||||||
|
class={cn('text-foreground font-semibold', className)}
|
||||||
|
{...restProps}
|
||||||
|
/>
|
||||||
7
src/shared/shadcn/ui/drawer/drawer-trigger.svelte
Normal file
7
src/shared/shadcn/ui/drawer/drawer-trigger.svelte
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Drawer as DrawerPrimitive } from 'vaul-svelte';
|
||||||
|
|
||||||
|
let { ref = $bindable(null), ...restProps }: DrawerPrimitive.TriggerProps = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<DrawerPrimitive.Trigger bind:ref data-slot="drawer-trigger" {...restProps} />
|
||||||
12
src/shared/shadcn/ui/drawer/drawer.svelte
Normal file
12
src/shared/shadcn/ui/drawer/drawer.svelte
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Drawer as DrawerPrimitive } from 'vaul-svelte';
|
||||||
|
|
||||||
|
let {
|
||||||
|
shouldScaleBackground = true,
|
||||||
|
open = $bindable(false),
|
||||||
|
activeSnapPoint = $bindable(null),
|
||||||
|
...restProps
|
||||||
|
}: DrawerPrimitive.RootProps = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<DrawerPrimitive.Root {shouldScaleBackground} bind:open bind:activeSnapPoint {...restProps} />
|
||||||
37
src/shared/shadcn/ui/drawer/index.ts
Normal file
37
src/shared/shadcn/ui/drawer/index.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import Close from './drawer-close.svelte';
|
||||||
|
import Content from './drawer-content.svelte';
|
||||||
|
import Description from './drawer-description.svelte';
|
||||||
|
import Footer from './drawer-footer.svelte';
|
||||||
|
import Header from './drawer-header.svelte';
|
||||||
|
import NestedRoot from './drawer-nested.svelte';
|
||||||
|
import Overlay from './drawer-overlay.svelte';
|
||||||
|
import Portal from './drawer-portal.svelte';
|
||||||
|
import Title from './drawer-title.svelte';
|
||||||
|
import Trigger from './drawer-trigger.svelte';
|
||||||
|
import Root from './drawer.svelte';
|
||||||
|
|
||||||
|
export {
|
||||||
|
Close,
|
||||||
|
Close as DrawerClose,
|
||||||
|
Content,
|
||||||
|
Content as DrawerContent,
|
||||||
|
Description,
|
||||||
|
Description as DrawerDescription,
|
||||||
|
Footer,
|
||||||
|
Footer as DrawerFooter,
|
||||||
|
Header,
|
||||||
|
Header as DrawerHeader,
|
||||||
|
NestedRoot,
|
||||||
|
NestedRoot as DrawerNestedRoot,
|
||||||
|
Overlay,
|
||||||
|
Overlay as DrawerOverlay,
|
||||||
|
Portal,
|
||||||
|
Portal as DrawerPortal,
|
||||||
|
Root,
|
||||||
|
//
|
||||||
|
Root as Drawer,
|
||||||
|
Title,
|
||||||
|
Title as DrawerTitle,
|
||||||
|
Trigger,
|
||||||
|
Trigger as DrawerTrigger,
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user