TypeScript
feat: add drawer and sheet primitives and bottom-sheet dialogs on phones
Vipul Kumarbef08d9f949a
diff --git a/package-lock.json b/package-lock.jsonindex e0b4d49..d255eff 100644--- a/package-lock.json+++ b/package-lock.json@@ -20,6 +20,7 @@"shadcn": "^4.22.1","sonner": "^2.0.8","tw-animate-css": "^1.4.0",+ "vaul": "^1.1.2","zustand": "^5.0.16"},"devDependencies": {@@ -11829,6 +11830,19 @@"node": ">= 0.8"}},+ "node_modules/vaul": {+ "version": "1.1.2",+ "resolved": "https://registry.npmjs.org/vaul/-/vaul-1.1.2.tgz",+ "integrity": "sha512-ZFkClGpWyI2WUQjdLJ/BaGuV6AVQiJ3uELGk3OYtP+B6yCO7Cmn9vPFXVJkRaGkOJu3m8bQMgtyzNHixULceQA==",+ "license": "MIT",+ "dependencies": {+ "@radix-ui/react-dialog": "^1.1.1"+ },+ "peerDependencies": {+ "react": "^16.8 || ^17.0 || ^18.0 || ^19.0.0 || ^19.0.0-rc",+ "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0.0 || ^19.0.0-rc"+ }+ },"node_modules/vite": {"version": "8.3.5","resolved": "https://registry.npmjs.org/vite/-/vite-8.3.5.tgz",diff --git a/package.json b/package.jsonindex 7cf7798..feda44c 100644--- a/package.json+++ b/package.json@@ -23,6 +23,7 @@"shadcn": "^4.22.1","sonner": "^2.0.8","tw-animate-css": "^1.4.0",+ "vaul": "^1.1.2","zustand": "^5.0.16"},"devDependencies": {diff --git a/src/components/ui/alert-dialog.tsx b/src/components/ui/alert-dialog.tsxindex 0435272..82f2729 100644--- a/src/components/ui/alert-dialog.tsx+++ b/src/components/ui/alert-dialog.tsx@@ -58,7 +58,7 @@ function AlertDialogContent({data-slot="alert-dialog-content"data-size={size}className={cn(- "group/alert-dialog-content fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-popover-foreground ring-1 ring-foreground/10 shadow-2xl shadow-black/10 duration-200 ease-(--ease-out) outline-none data-[size=default]:max-w-xs data-[size=sm]:max-w-xs data-[size=default]:sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",+ "group/alert-dialog-content fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-popover-foreground ring-1 ring-foreground/10 shadow-2xl shadow-black/10 duration-200 ease-(--ease-out) outline-none data-[size=default]:max-w-xs data-[size=sm]:max-w-xs data-[size=default]:sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 max-sm:top-auto max-sm:bottom-0 max-sm:left-0 max-sm:max-h-[92dvh] max-sm:max-w-none max-sm:translate-x-0 max-sm:translate-y-0 max-sm:overflow-y-auto max-sm:rounded-b-none max-sm:rounded-t-2xl max-sm:pb-[max(1.25rem,env(safe-area-inset-bottom))] max-sm:data-open:slide-in-from-bottom max-sm:data-open:zoom-in-100 max-sm:data-closed:slide-out-to-bottom max-sm:data-closed:zoom-out-100 max-sm:duration-300 max-sm:ease-(--ease-drawer)",className)}{...props}diff --git a/src/components/ui/dialog.tsx b/src/components/ui/dialog.tsxindex 57d3df1..bec4e6b 100644--- a/src/components/ui/dialog.tsx+++ b/src/components/ui/dialog.tsx@@ -61,7 +61,7 @@ function DialogContent({<DialogPrimitive.Contentdata-slot="dialog-content"className={cn(- "fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-sm text-popover-foreground ring-1 ring-foreground/10 shadow-2xl shadow-black/10 duration-200 ease-(--ease-out) outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",+ "fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-sm text-popover-foreground ring-1 ring-foreground/10 shadow-2xl shadow-black/10 duration-200 ease-(--ease-out) outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 max-sm:top-auto max-sm:bottom-0 max-sm:left-0 max-sm:max-h-[92dvh] max-sm:max-w-none max-sm:translate-x-0 max-sm:translate-y-0 max-sm:overflow-y-auto max-sm:rounded-b-none max-sm:rounded-t-2xl max-sm:pb-[max(1.25rem,env(safe-area-inset-bottom))] max-sm:data-open:slide-in-from-bottom max-sm:data-open:zoom-in-100 max-sm:data-closed:slide-out-to-bottom max-sm:data-closed:zoom-out-100 max-sm:duration-300 max-sm:ease-(--ease-drawer)",className)}{...props}diff --git a/src/components/ui/drawer.tsx b/src/components/ui/drawer.tsxnew file mode 100644index 0000000..ddd8ab3--- /dev/null+++ b/src/components/ui/drawer.tsx@@ -0,0 +1,133 @@+"use client"++import * as React from "react"+import { cn } from "cn"+import { Drawer as DrawerPrimitive } from "vaul"++function Drawer({+ ...props+}: React.ComponentProps<typeof DrawerPrimitive.Root>) {+ return <DrawerPrimitive.Root data-slot="drawer" {...props} />+}++function DrawerTrigger({+ ...props+}: React.ComponentProps<typeof DrawerPrimitive.Trigger>) {+ return <DrawerPrimitive.Trigger data-slot="drawer-trigger" {...props} />+}++function DrawerPortal({+ ...props+}: React.ComponentProps<typeof DrawerPrimitive.Portal>) {+ return <DrawerPrimitive.Portal data-slot="drawer-portal" {...props} />+}++function DrawerClose({+ ...props+}: React.ComponentProps<typeof DrawerPrimitive.Close>) {+ return <DrawerPrimitive.Close data-slot="drawer-close" {...props} />+}++function DrawerOverlay({+ className,+ ...props+}: React.ComponentProps<typeof DrawerPrimitive.Overlay>) {+ return (+ <DrawerPrimitive.Overlay+ data-slot="drawer-overlay"+ className={cn(+ "fixed inset-0 z-50 bg-[rgba(20,20,18,0.28)] dark:bg-black/60 data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",+ className+ )}+ {...props}+ />+ )+}++function DrawerContent({+ className,+ children,+ ...props+}: React.ComponentProps<typeof DrawerPrimitive.Content>) {+ return (+ <DrawerPortal data-slot="drawer-portal">+ <DrawerOverlay />+ <DrawerPrimitive.Content+ data-slot="drawer-content"+ className={cn(+ "group/drawer-content fixed z-50 flex h-auto flex-col bg-popover text-sm text-popover-foreground 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-[88dvh] data-[vaul-drawer-direction=bottom]:rounded-t-2xl data-[vaul-drawer-direction=bottom]:pb-[env(safe-area-inset-bottom)] data-[vaul-drawer-direction=bottom]:border-t data-[vaul-drawer-direction=left]:inset-y-0 data-[vaul-drawer-direction=left]:left-0 data-[vaul-drawer-direction=left]:w-3/4 data-[vaul-drawer-direction=left]:rounded-r-xl data-[vaul-drawer-direction=left]:border-r data-[vaul-drawer-direction=right]:inset-y-0 data-[vaul-drawer-direction=right]:right-0 data-[vaul-drawer-direction=right]:w-3/4 data-[vaul-drawer-direction=right]:rounded-l-xl data-[vaul-drawer-direction=right]:border-l 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-xl data-[vaul-drawer-direction=top]:border-b data-[vaul-drawer-direction=left]:sm:max-w-sm data-[vaul-drawer-direction=right]:sm:max-w-sm",+ className+ )}+ {...props}+ >+ <div className="mx-auto mt-2.5 hidden h-1 w-10 shrink-0 rounded-full bg-segment group-data-[vaul-drawer-direction=bottom]/drawer-content:block" />+ {children}+ </DrawerPrimitive.Content>+ </DrawerPortal>+ )+}++function DrawerHeader({ className, ...props }: React.ComponentProps<"div">) {+ return (+ <div+ data-slot="drawer-header"+ className={cn(+ "flex flex-col gap-0.5 p-4 group-data-[vaul-drawer-direction=bottom]/drawer-content:text-center group-data-[vaul-drawer-direction=top]/drawer-content:text-center md:gap-0.5 md:text-left",+ className+ )}+ {...props}+ />+ )+}++function DrawerFooter({ className, ...props }: React.ComponentProps<"div">) {+ return (+ <div+ data-slot="drawer-footer"+ className={cn("mt-auto flex flex-col gap-2 p-4", className)}+ {...props}+ />+ )+}++function DrawerTitle({+ className,+ ...props+}: React.ComponentProps<typeof DrawerPrimitive.Title>) {+ return (+ <DrawerPrimitive.Title+ data-slot="drawer-title"+ className={cn(+ "t-16 font-medium text-fg",+ className+ )}+ {...props}+ />+ )+}++function DrawerDescription({+ className,+ ...props+}: React.ComponentProps<typeof DrawerPrimitive.Description>) {+ return (+ <DrawerPrimitive.Description+ data-slot="drawer-description"+ className={cn("t-14 leading-[1.4] text-fg-2", className)}+ {...props}+ />+ )+}++export {+ Drawer,+ DrawerPortal,+ DrawerOverlay,+ DrawerTrigger,+ DrawerClose,+ DrawerContent,+ DrawerHeader,+ DrawerFooter,+ DrawerTitle,+ DrawerDescription,+}diff --git a/src/components/ui/sheet.tsx b/src/components/ui/sheet.tsxnew file mode 100644index 0000000..d7001cd--- /dev/null+++ b/src/components/ui/sheet.tsx@@ -0,0 +1,147 @@+"use client"++import * as React from "react"+import { cn } from "cn"+import { Dialog as SheetPrimitive } from "radix-ui"++import { Button } from "@/components/ui/button"+import { XIcon } from "lucide-react"++function Sheet({ ...props }: React.ComponentProps<typeof SheetPrimitive.Root>) {+ return <SheetPrimitive.Root data-slot="sheet" {...props} />+}++function SheetTrigger({+ ...props+}: React.ComponentProps<typeof SheetPrimitive.Trigger>) {+ return <SheetPrimitive.Trigger data-slot="sheet-trigger" {...props} />+}++function SheetClose({+ ...props+}: React.ComponentProps<typeof SheetPrimitive.Close>) {+ return <SheetPrimitive.Close data-slot="sheet-close" {...props} />+}++function SheetPortal({+ ...props+}: React.ComponentProps<typeof SheetPrimitive.Portal>) {+ return <SheetPrimitive.Portal data-slot="sheet-portal" {...props} />+}++function SheetOverlay({+ className,+ ...props+}: React.ComponentProps<typeof SheetPrimitive.Overlay>) {+ return (+ <SheetPrimitive.Overlay+ data-slot="sheet-overlay"+ className={cn(+ "fixed inset-0 z-50 bg-[rgba(20,20,18,0.28)] duration-300 dark:bg-black/60 data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",+ className+ )}+ {...props}+ />+ )+}++function SheetContent({+ className,+ children,+ side = "right",+ showCloseButton = true,+ ...props+}: React.ComponentProps<typeof SheetPrimitive.Content> & {+ side?: "top" | "right" | "bottom" | "left"+ showCloseButton?: boolean+}) {+ return (+ <SheetPortal>+ <SheetOverlay />+ <SheetPrimitive.Content+ data-slot="sheet-content"+ data-side={side}+ className={cn(+ "fixed z-50 flex flex-col gap-4 bg-popover bg-clip-padding text-sm text-popover-foreground shadow-lg duration-300 ease-(--ease-drawer) data-closed:duration-200 data-[side=bottom]:inset-x-0 data-[side=bottom]:bottom-0 data-[side=bottom]:h-auto data-[side=bottom]:border-t data-[side=left]:inset-y-0 data-[side=left]:left-0 data-[side=left]:h-full data-[side=left]:w-3/4 data-[side=left]:border-r data-[side=right]:inset-y-0 data-[side=right]:right-0 data-[side=right]:h-full data-[side=right]:w-3/4 data-[side=right]:border-l data-[side=top]:inset-x-0 data-[side=top]:top-0 data-[side=top]:h-auto data-[side=top]:border-b data-[side=left]:sm:max-w-sm data-[side=right]:sm:max-w-sm data-open:animate-in data-[side=bottom]:data-open:slide-in-from-bottom data-[side=left]:data-open:slide-in-from-left data-[side=right]:data-open:slide-in-from-right data-[side=top]:data-open:slide-in-from-top data-closed:animate-out data-[side=bottom]:data-closed:slide-out-to-bottom data-[side=left]:data-closed:slide-out-to-left data-[side=right]:data-closed:slide-out-to-right data-[side=top]:data-closed:slide-out-to-top",+ className+ )}+ {...props}+ >+ {children}+ {showCloseButton && (+ <SheetPrimitive.Close data-slot="sheet-close" asChild>+ <Button+ variant="ghost"+ className="absolute top-3 right-3"+ size="icon-sm"+ >+ <XIcon+ />+ <span className="sr-only">Close</span>+ </Button>+ </SheetPrimitive.Close>+ )}+ </SheetPrimitive.Content>+ </SheetPortal>+ )+}++function SheetHeader({ className, ...props }: React.ComponentProps<"div">) {+ return (+ <div+ data-slot="sheet-header"+ className={cn("flex flex-col gap-0.5 p-4", className)}+ {...props}+ />+ )+}++function SheetFooter({ className, ...props }: React.ComponentProps<"div">) {+ return (+ <div+ data-slot="sheet-footer"+ className={cn("mt-auto flex flex-col gap-2 p-4", className)}+ {...props}+ />+ )+}++function SheetTitle({+ className,+ ...props+}: React.ComponentProps<typeof SheetPrimitive.Title>) {+ return (+ <SheetPrimitive.Title+ data-slot="sheet-title"+ className={cn(+ "font-heading text-base font-medium text-foreground",+ className+ )}+ {...props}+ />+ )+}++function SheetDescription({+ className,+ ...props+}: React.ComponentProps<typeof SheetPrimitive.Description>) {+ return (+ <SheetPrimitive.Description+ data-slot="sheet-description"+ className={cn("text-sm text-muted-foreground", className)}+ {...props}+ />+ )+}++export {+ Sheet,+ SheetTrigger,+ SheetClose,+ SheetContent,+ SheetHeader,+ SheetFooter,+ SheetTitle,+ SheetDescription,+}