Keyframery

Drawer

Slides in from any edge on a spring; its grip stretches while you drag it.

See it as an AI agent does.

Resize preview. Focus the handle and use the left or right arrow keys. Hold Shift for larger steps.— px
Customize1 controls
Animation speed1×

Installation

npx shadcn@latest add @keyframery/drawer

This adds components/keyframery/drawer.tsx and its primitive to your project, and installs UI SDK. The motion tokens are added to your global CSS the first time you install a component.

Usage

import { Drawer, DrawerBackdrop, DrawerContent, DrawerGrip, DrawerHeader, DrawerTitle, DrawerTrigger } from "@/components/keyframery/drawer"

export default function Usage() {
  return (
    <Drawer>
      <DrawerTrigger>Open</DrawerTrigger>
      <DrawerBackdrop />
      <DrawerContent>
        <DrawerGrip />
        <DrawerHeader>
          <DrawerTitle>Title</DrawerTitle>
        </DrawerHeader>
      </DrawerContent>
    </Drawer>
  )
}

Anatomy

How the parts fit together:

Drawer
├── DrawerTrigger
├── DrawerBackdrop
└── DrawerContent
    ├── DrawerGrip
    └── DrawerHeader
        └── DrawerTitle

Examples

Basic

Slides up from the bottom. Drag the grip down, press Escape or tap outside to close it.

Snap points

snapPoints lets it rest part way up, like a map's place list. Drag between them.

From the side

side="right" slides it in from the edge, for a cart or a details panel.

Motion

MoveWhat you see
SpringThe sheet slides in from its edge on a spring and follows your finger while dragged.
CascadeIts contents arrive one after another once it is open.
StretchThe grip stretches while you drag.

Timing and springiness follow the motion style you set. To change how fast this drawer moves, pass speed:

<Drawer speed="fast">
  …
</Drawer>

"fast" is 0.6×, "slow" 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.

Theming

Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.

VariableWhat it changesDefault
--drawer-faceDrawer sheet and overscroll strip--popover
--drawer-inkDrawer body text--popover-foreground
--drawer-accentPrimary action and hover mix--primary
--drawer-widthSheet maximum width480px top/bottom; 380px left/right
--drawer-radiusFree-edge corners18px
--drawer-gapFooter key spacing0.5rem

API reference

Every part takes className and children. Parts from UI SDK also take render, to draw your own element, and a function of their state for className and style. Props not listed here are in the UI SDK drawer reference.

Drawer

Prop

Type

DrawerTrigger

Renders a <button>, and takes its props too.

Prop

Type

DrawerContent

Renders a <div>, and takes its props too.

Prop

Type

DrawerClose

Renders a <button>, and takes its props too.

Prop

Type

DrawerOutlet

Renders a <div>, and takes its props too.

Prop

Type

DrawerShortcut

Renders a <span>, and takes its props too.

Prop

Type

Other parts

These take the props of the element they render, and nothing else:

  • DrawerBackdrop: a <div>
  • DrawerGrip: a <div>
  • DrawerHeader: a <div>
  • DrawerTitle: a <h2>
  • DrawerDescription: a <p>
  • DrawerFooter: a <div>
  • DrawerHandle: a <button>

Keyboard

KeyWhat it does
TabMoves between the drawer's controls. Focus stays inside.
EscapeCloses the drawer.

Accessibility

Keyboard, focus and screen-reader behaviour come from UI SDK and are not changed. More in Accessibility.

Swap the import

Already using UI SDK's drawer with your own styles? Keep your markup and change one line. The primitive adds motion and nothing else.

// Before
import { … } from "@ui-sdk/react/drawer"

// After: same parts, same props, now animated
import { … } from "@/components/keyframery/primitives/drawer"

Questions

How does the animated Drawer for UI SDK move?

Spring: The sheet slides in from its edge on a spring and follows your finger while dragged. Cascade: Its contents arrive one after another once it is open. Stretch: The grip stretches while you drag.

Do I need Motion or Framer Motion for the animated Drawer?

No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.

Can I keep my own styling and only take the motion?

Yes. Import from @/components/keyframery/primitives/drawer instead. It has the same parts and props as @ui-sdk/react/drawer and adds motion only.

What happens to the Drawer when someone turns on reduced motion?

Nothing moves. State changes happen at once, or with a short fade.

All components

On this page