import * as React from "react" import * as SheetPrimitive from "@radix-ui/react-dialog" import { escapeBelongsToCombobox } from "../../lib/overlayEscape" import { useReturnFocus } from "../../lib/overlayFocus" import { XIcon } from "lucide-react" import { getAkashicPortalContainer } from "../../lib/getAkashicPortalContainer" import { cn } from "../../lib/utils" // ABOVE A FLOATING WINDOW, for the same mechanism as `ui/dialog` - this IS `@radix-ui/react-dialog` // with a different animation, so it traps focus and blocks pointer events outside itself exactly the same // way. A sheet opened from inside a floating window and painted underneath it does not merely look wrong; // it deadlocks the window. See `lib/stackingLayers.ts`. import { Z_MODAL_CLASS } from "../../lib/stackingLayers" // True under a Sheet, so a record display can tell a sheet from a routed page. const InSheetContext = React.createContext(false) function Sheet({ children, ...props }: React.ComponentProps) { return ( {children} ) } function SheetTrigger({ ...props }: React.ComponentProps) { return } function SheetClose({ ...props }: React.ComponentProps) { return } function SheetPortal({ container, ...props }: React.ComponentProps) { const portalContainer = container ?? getAkashicPortalContainer() ?? undefined return ( ) } function SheetOverlay({ className, ...props }: React.ComponentProps) { return ( ) } function SheetContent({ className, children, side = "right", showCloseButton = true, onEscapeKeyDown, onOpenAutoFocus, onCloseAutoFocus, ...props }: React.ComponentProps & { side?: "top" | "right" | "bottom" | "left" showCloseButton?: boolean }) { const returnFocus = useReturnFocus(onOpenAutoFocus, onCloseAutoFocus) return ( { if (escapeBelongsToCombobox(event)) { event.preventDefault() return } onEscapeKeyDown?.(event) }} {...returnFocus} {...props} > {children} {showCloseButton && ( Close )} ) } function SheetHeader({ className, ...props }: React.ComponentProps<"div">) { return (
) } function SheetFooter({ className, ...props }: React.ComponentProps<"div">) { return (
) } function SheetTitle({ className, ...props }: React.ComponentProps) { return ( ) } function SheetDescription({ className, ...props }: React.ComponentProps) { return ( ) } // A record display's body: the sheet's description inside a Sheet, and a plain block on a routed page, // where Radix's Description throws for want of a Dialog. function SheetBody({ className, children }: { className?: string; children?: React.ReactNode }) { const inSheet = React.useContext(InSheetContext) return inSheet ? {children} :
{children}
} export { Sheet, SheetBody, SheetTrigger, SheetClose, SheetContent, SheetHeader, SheetFooter, SheetTitle, SheetDescription, }