> A guide to [@fabiocv/ui](https://ui.fabio.cv/). Every guide is listed at https://ui.fabio.cv/llms.txt.

# Drawer

A [Base UI Drawer](https://base-ui.com/react/components/drawer) that rises from
the bottom like an iOS sheet, exported from `@fabiocv/ui/drawer`.

```tsx
import { Drawer, DrawerProvider } from '@fabiocv/ui/drawer';

<DrawerProvider>{page}</DrawerProvider>;

<Drawer.Root>
  <Drawer.Trigger render={<Button>Open</Button>} />
  <Drawer.Popup>
    <Drawer.Title>House of Maserati</Drawer.Title>
  </Drawer.Popup>
</Drawer.Root>;
```

`DrawerProvider` wraps the page once, so the page steps back while any drawer
is open. `Drawer.Root` takes Base UI's props, such as `open` and `onOpenChange`.

- It is for a page's worth of content, such as a project. The sheet is as tall as
  what is in it, and has both of its tabs however short that is.
- It has no padding of its own past `2px`. Lay out what is inside on
  [the grid's columns](https://ui.fabio.cv/grid/index.md).
- A control inside that closes it sets `open` to `false`. There is no part for
  one.
- The sheet sits on the grid's width, `48px` below the top of the window and
  above its bottom on a phone, `96px` from tablet up. On desktop it spans the
  middle 20 of the grid's 24 columns. Surface ground in light, Surface subtle in
  dark, `8px` corners, and `2px` padding at the sides and bottom.
- The window scrolls the whole sheet, with its bar on the window's right edge.
  It doesn't bounce past either end, which would move the tab off its cut.
- While a drawer is on screen the page is locked and drops the gutter it keeps
  for its scrollbar, so the drawer covers the whole window. The page keeps the
  gutter's width as a margin, so it doesn't move.
- A `40px` close tab with `8px` corners sits in the sheet's top-right corner,
  cut out of it like the image card's tag: a `2px` gap and `8px` fillets. Under
  the pointer its ground turns Surface subtle in light and Surface sunken in
  dark.
- A highlight inside it, such as a `Button`'s, steps to Surface sunken in dark,
  where the sheet is Surface subtle.
- As the sheet scrolls, the tab and its cut stay still at the top inset. The
  tab is sticky and the cut is a mask on the window, so the browser holds both
  in place with no script. The window itself rises, follows a swipe and
  leaves, so the sheet, the tab and the cut always move as one, even when the
  sheet is scrolled while it rises.
- A `40px` go-to-top tab with an arrow up sits in the sheet's bottom-right
  corner, cut out of it the same way, at full size like the close tab. It
  scrolls the sheet back to its top. `topLabel` names it, `Go to top` by
  default.
- `closeTab` and `topTab` take `onClick` and `onPointerEnter` for each tab, such
  as the sounds it plays.
- Opens and closes on a spring of `0.45s` and `1`, with no overshoot. The page
  scales to `96%` about the middle of the window, dims and blurs `4px`, over
  its own Surface ground, so no edge shows around it.
- A drawer that is open when the page loads is in the page's HTML, at rest over
  the stepped-back page, so it shows from the first paint. Until the script
  runs, the sheet does not scroll and the page is held where it was: at its top,
  or after a reload, where the page sat under the open drawer, which the
  drawer keeps in the history entry. Base UI then takes it over with nothing
  moving, and it closes on the same spring.
- Swipe the sheet down to close it. The sheet follows the finger, and the page
  and dimming follow its progress. From a scrolled sheet, the swipe scrolls
  first and closes once the content is at its top. A flick closes it quicker.
- Scrolled, the sheet leaves with an edge at the window's top, so closing never
  brings back what is above the window. The tab leaves with it, in its cut.
- Escape, a click on the page and the close tab close it. Focus stays inside
  while it is open and returns to the trigger after. The page does not scroll
  behind it.
- With reduced motion the sheet only fades and the page does not scale.

## Types of `@fabiocv/ui/drawer`

```ts
/** Wraps the page, which steps back while a drawer is open. Its own export, so a server component can render it. */
export declare function DrawerProvider({ children }: {
    children: ReactNode;
}): import("react").JSX.Element;

/** What a tab takes beyond its name, such as the sounds it plays. */
export type DrawerTabProps = Pick<ComponentProps<'button'>, 'onClick' | 'onPointerEnter'>;

export type DrawerPopupProps = {
    children: ReactNode;
    /** Accessible name of the close button. */
    closeLabel?: string;
    /** Accessible name of the go-to-top button. */
    topLabel?: string;
    /** Handlers for the close tab. */
    closeTab?: DrawerTabProps;
    /** Handlers for the go-to-top tab. */
    topTab?: DrawerTabProps;
};

declare function Root<Payload>(props: BaseDrawer.Root.Props<Payload>): import("react").JSX.Element;

/** A sheet that rises over the dimmed page. The window scrolls it as one; the close tab stays put. */
declare function Popup({ children, closeLabel, topLabel, closeTab, topTab, }: DrawerPopupProps): import("react").JSX.Element;

/**
 * A Base UI Drawer: a sheet that rises from the bottom over the page, which
 * steps back. Swipe it down, press Escape or click outside it to close it.
 */
export declare const Drawer: {
    Root: typeof Root;
    Trigger: BaseDrawer.Trigger;
    Popup: typeof Popup;
    Title: BaseDrawer.Title;
    Description: BaseDrawer.Description;
};
```

## Examples

### Default

```tsx
<Drawer.Root>
  <Drawer.Trigger render={<Button>Open</Button>} />
  <Drawer.Popup>
    <div style={{ minHeight: '80vh', padding: 'var(--spacing-48)' }}>
      <Drawer.Title>House of Maserati</Drawer.Title>
    </div>
  </Drawer.Popup>
</Drawer.Root>
```

See it at https://ui.fabio.cv/drawer/.
