"use client"; import { AnimatePresence, motion, useReducedMotion } from "motion/react"; import { type ReactNode, useEffect } from "react"; import { cn } from "@/lib/utils"; export interface SheetProps { open: boolean; onClose: () => void; children: ReactNode; side?: "left" | "right" | "bottom"; className?: string; } export function Sheet({ open, onClose, children, side = "left", className, }: SheetProps) { const reduce = useReducedMotion(); useEffect(() => { if (!open) return; const onKey = (e: KeyboardEvent) => e.key === "Escape" && onClose(); document.addEventListener("keydown", onKey); return () => document.removeEventListener("keydown", onKey); }, [open, onClose]); const dir = side === "left" ? { initial: { x: "-100%" }, animate: { x: 0 } } : side === "right" ? { initial: { x: "100%" }, animate: { x: 0 } } : { initial: { y: "100%" }, animate: { y: 0 } }; return ( {open && (
{children} )} ); }