sheet.tsx
This file
Path
apps/web/src/components/ui/sheet.tsx
86 lines · 3.3 KiB · TypeScript
Last changed by
Review fixes for 1203oscabrielbefore adoption950d5e0
History of this fileTake it
Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 1–6why, one step back1"use client";23/**4 * A sheet: Base UI's dialog drawn against an edge of the screen. It slides5 * in over 200 ms (none under reduced motion, which the stylesheet's switch6 * turns off), traps focus while open, and closes on Escape, a press outsideReview fixes for 1203oscabrielbefore adoption950d5e0
lines 7–8why, one step back7 * or its Close button. The page behind dims in ink, without blur; the8 * sheet itself is flat paper parted from it by a hairline, with no shadow.Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 9–30why, one step back9 */10import { Dialog as DialogPrimitive } from "@base-ui/react/dialog";11import { cva } from "class-variance-authority";12import { cn } from "cn";13import { XIcon } from "lucide-react";14import type * as React from "react";1516import { Button } from "@/components/ui/button";1718function Sheet({ ...props }: DialogPrimitive.Root.Props) {19 return <DialogPrimitive.Root data-slot="sheet" {...props} />;20}2122function SheetTrigger({ ...props }: DialogPrimitive.Trigger.Props) {23 return <DialogPrimitive.Trigger data-slot="sheet-trigger" {...props} />;24}2526function SheetClose({ ...props }: DialogPrimitive.Close.Props) {27 return <DialogPrimitive.Close data-slot="sheet-close" {...props} />;28}2930const sheetVariants = cva(Review fixes for 1203oscabrielbefore adoption950d5e0
line 31why, one step back31 "bg-background text-foreground border-rule fixed z-50 flex flex-col overflow-hidden transition-transform duration-200 ease-[cubic-bezier(0.16,1,0.3,1)] outline-none",Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 32–86why, one step back32 {33 variants: {34 side: {35 bottom:36 "inset-x-0 bottom-0 max-h-[85dvh] border-t pb-[env(safe-area-inset-bottom)] data-ending-style:translate-y-full data-starting-style:translate-y-full",37 full: "inset-0 pb-[env(safe-area-inset-bottom)] data-ending-style:translate-y-full data-starting-style:translate-y-full",38 left: "inset-y-0 left-0 w-[min(20rem,calc(100vw-3rem))] border-r data-ending-style:-translate-x-full data-starting-style:-translate-x-full",39 right:40 "inset-y-0 right-0 w-[min(22rem,calc(100vw-3rem))] border-l data-ending-style:translate-x-full data-starting-style:translate-x-full",41 },42 },43 defaultVariants: { side: "left" },44 }45);4647function SheetContent({48 className,49 children,50 side = "left",51 title,52 ...props53}: DialogPrimitive.Popup.Props & {54 readonly side?: "bottom" | "full" | "left" | "right";55 /** The sheet's name, drawn in its head beside Close. */56 readonly title: React.ReactNode;57}) {58 return (59 <DialogPrimitive.Portal data-slot="sheet-portal">60 <DialogPrimitive.Backdrop61 className="fixed inset-0 z-50 bg-[color-mix(in_oklch,var(--foreground)_22%,transparent)] transition-opacity duration-200 data-ending-style:opacity-0 data-starting-style:opacity-0"62 data-slot="sheet-overlay"63 />64 <DialogPrimitive.Popup65 className={cn(sheetVariants({ side }), className)}66 data-slot="sheet-content"67 {...props}68 >69 <div className="border-rule flex h-12 shrink-0 items-center justify-between gap-3 border-b pr-2 pl-4">70 <DialogPrimitive.Title className="text-ui font-semibold">71 {title}72 </DialogPrimitive.Title>73 <DialogPrimitive.Close render={<Button size="sm" variant="ghost" />}>74 <XIcon aria-hidden="true" />75 Close76 </DialogPrimitive.Close>77 </div>78 <div className="min-h-0 flex-1 overflow-y-auto overscroll-contain">79 {children}80 </div>81 </DialogPrimitive.Popup>82 </DialogPrimitive.Portal>83 );84}8586export { Sheet, SheetClose, SheetContent, SheetTrigger };