<!-- index: /slotted/llms.txt -->
# floating-panel

`data-ui="floating-panel"` · A non-modal tool panel the reader drags over the page.

## Import

```tsx
import {
  FloatingPanel,
  FloatingPanelBody,
  FloatingPanelClose,
  FloatingPanelHandle,
  FloatingPanelTitle,
} from '@slotted/react';
```

## Minimal example

Example

```tsx
import { useState } from 'react';

import { Button } from '@slotted/react/button';
import {
  FloatingPanel,
  FloatingPanelBody,
  FloatingPanelClose,
  FloatingPanelHandle,
  FloatingPanelTitle,
} from '@slotted/react/floating-panel';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

export default function FloatingPanelBasic() {
  const [open, setOpen] = useState(false);

  return (
    <>
      <Button onClick={() => setOpen(true)}>Open shipping estimate</Button>

      <FloatingPanel onOpenChange={setOpen} open={open}>
        <FloatingPanelHandle>
          <FloatingPanelTitle>Shipping estimate</FloatingPanelTitle>
          <FloatingPanelClose />
        </FloatingPanelHandle>
        <FloatingPanelBody>
          <Stack gap={2}>
            <Text size="sm">Order 48213, 14 cases</Text>
            <Text size="sm">Freight $86.40</Text>
            <Text size="sm">Total $1,326.40</Text>
          </Stack>
        </FloatingPanelBody>
      </FloatingPanel>
    </>
  );
}
```

## Anatomy

| Part | Element | Required |
| --- | --- | --- |
| `root` | section | yes |
| `handle` | div | yes |
| `grip` | button | yes |
| `title` | h2 | no |
| `close` | button | no |
| `body` | div | yes |

## Props

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `open` | `boolean` | — | FloatingPanel | Whether the panel is drawn |
| `onOpenChange` | `(open: boolean) => void` | — | FloatingPanel | Asked with false on Escape inside the panel and on its close control |
| `defaultPlace` | `'top-start' \| 'top-end' \| 'bottom-start' \| 'bottom-end'` | bottom-end | FloatingPanel | The corner the panel stands in until its first move, in the reading direction, --slotted-floating-panel-inset from the edges |
| `place` | `{ x: number; y: number }` | — | FloatingPanel | A controlled place, the top-left corner in viewport pixels, drawn inside the viewport |
| `step` | `number` | 8 | FloatingPanel | Pixels an arrow key on the grip moves the panel |
| `largeStep` | `number` | 32 | FloatingPanel | Pixels an arrow key with Shift moves it |
| `onPlaceChange` | `(place) => void` | — | FloatingPanel | Fired once at the end of a move, by pointer or by key, for the application to store |
| `messages` | `PartialMessages<FloatingPanelMessages>` | — | FloatingPanel | Words laid over the catalog of the language in force: close, move |
| `native props` | `section, div, h2, button attributes` | — | every part | Reach the element each part renders |

## Rules

- The root is a region named by FloatingPanelTitle or an aria-label, never a dialog: nothing on the page is inert, no scrim takes a press, and focus is not trapped, so the panel is a tool beside the work rather than a step of it.
- The grip is a button named Move in the language in force; an arrow key moves the panel one step and Shift a larger one, so the panel can be put out of the way without a pointer.
- Escape inside the panel and the close control ask onOpenChange(false), and focus returns to the element that held it before the panel opened.
- The place is clamped by the viewport and the panel’s own size in the stylesheet, so a narrowed window or a stored place never leaves part of the tool out of reach.

## Tokens

`--slotted-border-strong`, `--slotted-border-subtle`, `--slotted-border-width-thin`, `--slotted-control-inner-size-md`, `--slotted-floating-panel-backdrop-filter`, `--slotted-floating-panel-border-color`, `--slotted-floating-panel-inset`, `--slotted-floating-panel-radius`, `--slotted-floating-panel-rule-color`, `--slotted-floating-panel-shadow`, `--slotted-floating-panel-surface`, `--slotted-focus-ring-color`, `--slotted-focus-ring-offset`, `--slotted-focus-ring-width`, `--slotted-font-family-heading`, `--slotted-font-family-sans`, `--slotted-font-size-sm`, `--slotted-font-weight-semibold`, `--slotted-radius-lg`, `--slotted-radius-sm`, `--slotted-shadow-lg`, `--slotted-space-2`, `--slotted-space-3`, `--slotted-space-5`, `--slotted-space-6`, `--slotted-surface-raised`, `--slotted-text`, `--slotted-text-muted`, `--slotted-tone-secondary-subtle-hover`, `--slotted-z-index-popover`

## Examples

### Playground

A calculator left open over a page that stays usable: drag the handle, press a button of the page under it, and close the panel with Escape.

Excerpt — not a complete module

```tsx
<FloatingPanel onOpenChange={setOpen} open={open}>
  <FloatingPanelHandle>
    <FloatingPanelTitle>Calculator</FloatingPanelTitle>
    <FloatingPanelClose />
  </FloatingPanelHandle>
  <FloatingPanelBody>…</FloatingPanelBody>
</FloatingPanel>;
```

### Moved by the keyboard, and stored where it was left

The grip takes focus; an arrow key moves the panel by step, eight pixels, and by largeStep, thirty-two, with Shift. onPlaceChange reports the end of every move, so the application stores the place and hands it back as place.

Excerpt — not a complete module

```tsx
<FloatingPanel onOpenChange={setOpen} onPlaceChange={setPlace} open={open} place={place}>
  …
</FloatingPanel>;
```

### What a reader meets

A region named by its title, not a dialog: the shortcuts an application holds back while a dialog is open keep working, and focus is never trapped. Escape inside it closes it and returns focus to where it was.

Excerpt — not a complete module

```tsx
<FloatingPanel aria-label="Notes" onOpenChange={setOpen} open={open}>
  …
</FloatingPanel>;
```

### corners.tsx

Example

```tsx
import { useState } from 'react';

import { Button } from '@slotted/react/button';
import {
  FloatingPanel,
  FloatingPanelBody,
  FloatingPanelClose,
  FloatingPanelHandle,
  FloatingPanelTitle,
} from '@slotted/react/floating-panel';
import type { FloatingCorner } from '@slotted/react/floating-panel';
import { Text } from '@slotted/react/typography';

const DOCKS: readonly { corner: FloatingCorner; name: string; status: string }[] = [
  { corner: 'top-start', name: 'Inbound dock', status: 'Door 3 free' },
  { corner: 'top-end', name: 'Outbound dock', status: '2 trucks waiting' },
  { corner: 'bottom-start', name: 'Cold storage', status: '3.8 °C' },
  { corner: 'bottom-end', name: 'Returns', status: '11 parcels to sort' },
];

export default function FloatingPanelCorners() {
  const [closed, setClosed] = useState<readonly FloatingCorner[]>(DOCKS.map((dock) => dock.corner));

  return (
    <>
      <Button onClick={() => setClosed([])}>Show all docks</Button>

      {DOCKS.map((dock) => (
        <FloatingPanel
          defaultPlace={dock.corner}
          key={dock.corner}
          onOpenChange={() => setClosed([...closed, dock.corner])}
          open={!closed.includes(dock.corner)}
        >
          <FloatingPanelHandle>
            <FloatingPanelTitle>{dock.name}</FloatingPanelTitle>
            <FloatingPanelClose />
          </FloatingPanelHandle>
          <FloatingPanelBody>
            <Text size="sm">{dock.status}</Text>
          </FloatingPanelBody>
        </FloatingPanel>
      ))}
    </>
  );
}
```

### label.tsx

Example

```tsx
import { useState } from 'react';

import { Button } from '@slotted/react/button';
import {
  FloatingPanel,
  FloatingPanelBody,
  FloatingPanelClose,
  FloatingPanelHandle,
} from '@slotted/react/floating-panel';
import { Text } from '@slotted/react/typography';

export default function FloatingPanelLabel() {
  const [open, setOpen] = useState(false);

  return (
    <>
      <Button onClick={() => setOpen(true)}>Open dispatch notes</Button>

      <FloatingPanel
        aria-label="Dispatch notes"
        defaultPlace="bottom-start"
        onOpenChange={setOpen}
        open={open}
      >
        <FloatingPanelHandle>
          <FloatingPanelClose />
        </FloatingPanelHandle>
        <FloatingPanelBody>
          <Text size="sm">Carrier pickup moved to 14:30 for order 48213.</Text>
        </FloatingPanelBody>
      </FloatingPanel>
    </>
  );
}
```

### messages.tsx

Example

```tsx
import { useState } from 'react';

import { Button } from '@slotted/react/button';
import {
  FloatingPanel,
  FloatingPanelBody,
  FloatingPanelClose,
  FloatingPanelHandle,
  FloatingPanelTitle,
} from '@slotted/react/floating-panel';
import { Text } from '@slotted/react/typography';

export default function FloatingPanelMessages() {
  const [open, setOpen] = useState(false);

  return (
    <>
      <Button onClick={() => setOpen(true)}>Open packing timer</Button>

      <FloatingPanel
        defaultPlace="top-start"
        messages={{ close: 'Dismiss the timer', move: 'Reposition the timer' }}
        onOpenChange={setOpen}
        open={open}
      >
        <FloatingPanelHandle>
          <FloatingPanelTitle>Packing timer</FloatingPanelTitle>
          <FloatingPanelClose />
        </FloatingPanelHandle>
        <FloatingPanelBody>
          <Text size="sm">Order 48213: 04:12 elapsed.</Text>
        </FloatingPanelBody>
      </FloatingPanel>
    </>
  );
}
```

### non-modal.tsx

Example

```tsx
import { useState } from 'react';

import { Button } from '@slotted/react/button';
import {
  FloatingPanel,
  FloatingPanelBody,
  FloatingPanelClose,
  FloatingPanelHandle,
  FloatingPanelTitle,
} from '@slotted/react/floating-panel';
import { Inline } from '@slotted/react/inline';
import { Text } from '@slotted/react/typography';

export default function FloatingPanelNonModal() {
  const [open, setOpen] = useState(false);
  const [picked, setPicked] = useState(0);

  return (
    <>
      <Inline>
        <Button onClick={() => setPicked(picked + 1)}>Pick one case</Button>
        <Button onClick={() => setOpen(true)} variant="outline">
          Open pick list
        </Button>
      </Inline>

      <FloatingPanel defaultPlace="bottom-start" onOpenChange={setOpen} open={open}>
        <FloatingPanelHandle>
          <FloatingPanelTitle>Pick list</FloatingPanelTitle>
          <FloatingPanelClose />
        </FloatingPanelHandle>
        <FloatingPanelBody>
          <Text size="sm">Cases picked for order 48213: {picked} of 14</Text>
        </FloatingPanelBody>
      </FloatingPanel>
    </>
  );
}
```

### place.tsx

Example

```tsx
import { useState } from 'react';

import { Button } from '@slotted/react/button';
import {
  FloatingPanel,
  FloatingPanelBody,
  FloatingPanelClose,
  FloatingPanelHandle,
  FloatingPanelTitle,
} from '@slotted/react/floating-panel';
import type { FloatingPlace } from '@slotted/react/floating-panel';
import { Inline } from '@slotted/react/inline';
import { Text } from '@slotted/react/typography';

export default function FloatingPanelPlace() {
  const [open, setOpen] = useState(false);
  const [place, setPlace] = useState<FloatingPlace | undefined>(undefined);

  return (
    <>
      <Inline>
        <Button onClick={() => setOpen(true)}>Open route notes</Button>
        <Button onClick={() => setPlace({ x: 32, y: 96 })} variant="outline">
          Pin to the top left
        </Button>
      </Inline>

      <FloatingPanel onOpenChange={setOpen} onPlaceChange={setPlace} open={open} place={place}>
        <FloatingPanelHandle>
          <FloatingPanelTitle>Route notes</FloatingPanelTitle>
          <FloatingPanelClose />
        </FloatingPanelHandle>
        <FloatingPanelBody>
          <Text size="sm">
            {place === undefined
              ? 'Not moved yet'
              : `Stored at x ${Math.round(place.x)}, y ${Math.round(place.y)}`}
          </Text>
        </FloatingPanelBody>
      </FloatingPanel>
    </>
  );
}
```

### steps.tsx

Example

```tsx
import { useState } from 'react';

import { Button } from '@slotted/react/button';
import {
  FloatingPanel,
  FloatingPanelBody,
  FloatingPanelClose,
  FloatingPanelHandle,
  FloatingPanelTitle,
} from '@slotted/react/floating-panel';
import { Text } from '@slotted/react/typography';

export default function FloatingPanelSteps() {
  const [open, setOpen] = useState(false);

  return (
    <>
      <Button onClick={() => setOpen(true)}>Open pallet tracker</Button>

      <FloatingPanel
        defaultPlace="top-end"
        largeStep={64}
        onOpenChange={setOpen}
        open={open}
        step={16}
      >
        <FloatingPanelHandle>
          <FloatingPanelTitle>Pallet tracker</FloatingPanelTitle>
          <FloatingPanelClose />
        </FloatingPanelHandle>
        <FloatingPanelBody>
          <Text size="sm">Focus Move, then press an arrow key: 16 px, or 64 px with Shift.</Text>
        </FloatingPanelBody>
      </FloatingPanel>
    </>
  );
}
```
