Floating panel
A tool that stays over the page while the page stays usable, moved by its handle and kept whole inside the viewport.
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> </> );}Installation
The packages are a 0.x beta on npm, and their public API changes between beta releases without deprecation. One line installs the binding and the default theme.
pnpm add @slotted/react @slotted/theme @slotted/themesimport { FloatingPanel, FloatingPanelBody, FloatingPanelClose, FloatingPanelHandle, FloatingPanelTitle } from '@slotted/react';A tool beside the work
A floating panel is a named region, not a dialog. It draws no scrim, traps no focus and makes nothing inert, so the page under it stays usable and the shortcuts an application holds back while a dialog is open keep working. A press outside the panel does nothing to it. Escape inside the panel and the close control ask onOpenChange(false) in React and emit openChange with false in Angular, and focus returns to the element that held it before the panel opened. Open the pick list, then press Pick one case while the panel stays open: the count in the panel goes up.
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> </> );}Corners
defaultPlace sets the corner the panel stands in until its first move: top-start, top-end, bottom-start or bottom-end. The corners follow the reading direction, so start is the right edge in a right-to-left language. The panel stands --slotted-floating-panel-inset from the edges, and bottom-end is the default. The panel itself is always position: fixed, so Show all docks opens four panels in the corners of the viewport, not of the preview.
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> ))} </> );}Moving the panel
A press on the handle drags the panel, with the pointer captured and no scroll of the page; the panel carries data-dragging while it moves. The grip at the start of the handle is a button named Move. An arrow key on the grip moves the panel one step, and Shift moves it a larger one. A move never takes the panel out of the viewport: the stylesheet clamps its place by the viewport and by the panel’s own size, so the panel stays whole when the window shrinks too. step sets the pixels of an arrow key, 8 by default, and largeStep sets the pixels of an arrow key with Shift, 32 by default. The panel below moves 16 and 64 pixels.
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> </> );}Storing the place
A move reports its end once, by pointer or by key: onPlaceChange in React, placeChange in Angular. The place is the panel’s top-left corner in viewport pixels. Pass it back as place to own the panel’s position, for example to restore it in the next session. A place outside the viewport is drawn inside it. Open the panel and drag it, or pin it to the top left.
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> </> );}A name without a title
The region is named by FloatingPanelTitle. A panel without a title takes its name from aria-label in React and label in Angular, and the title part can be left out. Use it for a tool whose body states its purpose, such as a note.
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
The grip and the close control carry names from the language in force: Move and Close. messages overlays one or both for a single panel with move and close.
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> </> );}Accessibility
- 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.
API
FloatingPanel
Props
openboolean- Whether the panel is drawn
onOpenChange(open: boolean) => void- Asked with false on Escape inside the panel and on its close control
defaultPlace'top-start' | 'top-end' | 'bottom-start' | 'bottom-end'Defaultbottom-end- 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 }- A controlled place, the top-left corner in viewport pixels, drawn inside the viewport
stepnumberDefault8- Pixels an arrow key on the grip moves the panel
largeStepnumberDefault32- Pixels an arrow key with Shift moves it
onPlaceChange(place) => void- Fired once at the end of a move, by pointer or by key, for the application to store
messagesPartialMessages<FloatingPanelMessages>- Words laid over the catalog of the language in force: close, move
native propssection, div, h2, button attributes- On every partReach the element each part renders
Parts
| Part | Element | Required | Purpose |
|---|---|---|---|
root | section | Yes | role="region", named by the title or an aria-label: a tool over the page that holds nobody, with no scrim and nothing made inert. Its place is clamped by the viewport and its own size. |
handle | div | Yes | The bar the panel is moved by: a press that moves drags it, with the pointer captured and no scroll of the page. |
grip | button | Yes | The handle’s focusable start, named Move in the language in force: an arrow key moves the panel one step, a larger one with Shift. |
title | h2 | No | The panel’s name, one line, which names the region when no aria-label does. |
close | button | No | Closes the panel; focus returns to the element that held it before it opened. |
body | div | Yes | What the tool holds. It scrolls when the panel is held shorter than it. |
Theming
Each token is a CSS custom property: set it in a theme, or on any element to retune every floating panel inside it.
Floating panel tokens
| Token | Default |
|---|---|
--slotted-floating-panel-backdrop-filter | none |
--slotted-floating-panel-border-color | var(--slotted-border-strong, CanvasText) |
--slotted-floating-panel-inset | var(--slotted-space-6, 16px) |
--slotted-floating-panel-radius | var(--slotted-radius-lg, 8px) |
--slotted-floating-panel-rule-color | var(--slotted-border-subtle, ButtonBorder) |
--slotted-floating-panel-shadow | var(--slotted-shadow-lg, none) |
--slotted-floating-panel-surface | var(--slotted-surface-raised, Canvas) |
Theme tokens it reads
| Token | Default |
|---|---|
--slotted-border-strong | Set per scheme by the theme |
--slotted-border-subtle | Set per scheme by the theme |
--slotted-border-width-thin | 1px |
--slotted-control-inner-size-md | comfortable 24px · compact 20px · dense 18px |
--slotted-focus-ring-color | Set per scheme by the theme |
--slotted-focus-ring-offset | var(--slotted-border-width-thick) |
--slotted-focus-ring-width | var(--slotted-border-width-thick) |
--slotted-font-family-heading | var(--slotted-font-family-sans) |
--slotted-font-family-sans | 'Geist Variable', ui-sans-serif, system-ui, sans-serif |
--slotted-font-size-sm | 0.8125rem |
--slotted-font-weight-semibold | 600 |
--slotted-radius-lg | 8px |
--slotted-radius-sm | 4px |
--slotted-shadow-lg | Set per scheme by the theme |
--slotted-space-2 | 0.25rem |
--slotted-space-3 | 0.375rem |
--slotted-space-5 | 0.75rem |
--slotted-space-6 | 1rem |
--slotted-surface-raised | Set per scheme by the theme |
--slotted-text | Set per scheme by the theme |
--slotted-text-muted | Set per scheme by the theme |
--slotted-tone-secondary-subtle-hover | Set per scheme by the theme |
--slotted-z-index-popover | 1100 |