# Sheet

A framed board that slides in from an edge with a springy settle. Use it for create and edit forms; the bottom sheet suits phones.

Docs: https://cozy-ui.solo.engineer/docs/components/sheet/

Install: `npx shadcn@latest add @cozy/sheet`

### Usage

```tsx
import { Sheet, SheetTrigger, SheetContent, SheetHeader, SheetTitle, SheetDescription, SheetFooter, SheetClose } from "@/components/ui/sheet"

<SheetContent side="bottom">…</SheetContent>
```

### Props

| Prop | Type | Default | Description |
|---|---|---|---|
| side | `"top" \| "right" \| "bottom" \| "left"` | `"right"` | Edge it slides from. |

### Example

```tsx
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch";
import { Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger } from "@/components/ui/sheet";

export default function SheetDemo() {
  return (
    <Sheet>
      <SheetTrigger asChild><Button variant="outline">Village settings</Button></SheetTrigger>
      <SheetContent>
        <SheetHeader>
          <SheetTitle>Village settings</SheetTitle>
          <SheetDescription>Changes are saved when you press Save.</SheetDescription>
        </SheetHeader>
        <div className="grid gap-2">
          <Label htmlFor="sheet-name">Village name</Label>
          <Input id="sheet-name" defaultValue="Cloudvale" />
        </div>
        <Label className="cursor-pointer"><Switch defaultChecked /> Let friends visit</Label>
        <Label className="cursor-pointer"><Switch /> Show my village on the map</Label>
        <SheetFooter>
          <SheetClose asChild><Button variant="secondary">Cancel</Button></SheetClose>
          <SheetClose asChild><Button>Save</Button></SheetClose>
        </SheetFooter>
      </SheetContent>
    </Sheet>
  );
}
```

### Source (components/ui/sheet.tsx)

```tsx
import * as React from "react";
import { Dialog as SheetPrimitive } from "radix-ui";
import { cn } from "@/lib/utils";
import { Button } from "./button";
import { CloseGlyph } from "./glyphs";

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 SheetContent({
  className,
  children,
  side = "right",
  showCloseButton = true,
  onOpenAutoFocus,
  ...props
}: React.ComponentProps<typeof SheetPrimitive.Content> & { side?: "top" | "right" | "bottom" | "left"; showCloseButton?: boolean }) {
  return (
    <SheetPrimitive.Portal>
      <SheetPrimitive.Overlay data-slot="sheet-overlay" className="cz-overlay" />
      <SheetPrimitive.Content
        onOpenAutoFocus={(e) => {
          // keep keyboard focus inside, but don't jump into (and select) the first field
          e.preventDefault();
          (e.currentTarget as HTMLElement | null)?.focus({ preventScroll: true });
          onOpenAutoFocus?.(e);
        }}
        tabIndex={-1}
        data-slot="sheet-content" className={cn("cz-sheet", `cz-sheet--${side}`, className)} {...props}>
        {children}
        {showCloseButton && (
          <SheetPrimitive.Close asChild>
            <Button variant="outline" size="icon-sm" className="cz-sheet__close" aria-label="Close">
              <CloseGlyph />
            </Button>
          </SheetPrimitive.Close>
        )}
      </SheetPrimitive.Content>
    </SheetPrimitive.Portal>
  );
}
function SheetHeader({ className, ...props }: React.ComponentProps<"div">) {
  return <div data-slot="sheet-header" className={cn("grid gap-2 pr-12", className)} {...props} />;
}
function SheetFooter({ className, ...props }: React.ComponentProps<"div">) {
  return <div data-slot="sheet-footer" className={cn("mt-auto flex flex-col-reverse gap-3 sm:flex-row sm:justify-end", className)} {...props} />;
}
function SheetTitle({ className, ...props }: React.ComponentProps<typeof SheetPrimitive.Title>) {
  return <SheetPrimitive.Title data-slot="sheet-title" className={cn("cz-dialog__title", className)} {...props} />;
}
function SheetDescription({ className, ...props }: React.ComponentProps<typeof SheetPrimitive.Description>) {
  return <SheetPrimitive.Description data-slot="sheet-description" className={cn("cz-dialog__description", className)} {...props} />;
}

export { Sheet, SheetTrigger, SheetClose, SheetContent, SheetHeader, SheetFooter, SheetTitle, SheetDescription };
```

npm: `import { Sheet, SheetTrigger, SheetClose, SheetContent, SheetHeader, SheetFooter, SheetTitle, SheetDescription } from "@0xtrou/cozy-ui"` (after `npm install @0xtrou/cozy-ui` and `import "@0xtrou/cozy-ui/styles.css"`).
