Keyframery

Alert

Alerts drop into place out of a blur on a spring while their icon pops into its tile and draws, and when dismissed they fade and fold their height away.

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/alert

This adds components/keyframery/alert.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 { CircleAlert } from "lucide-react"

import { Alert, AlertDescription, AlertTitle } from "@/components/keyframery/alert"

export default function Usage() {
  return (
    <Alert>
      <CircleAlert />
      <AlertTitle>Heads up</AlertTitle>
      <AlertDescription>Your card expires at the end of the month.</AlertDescription>
    </Alert>
  )
}

Anatomy

How the parts fit together:

Alert
├── AlertTitle
└── AlertDescription

Examples

Basic

An icon placed straight inside the alert pops into its tile and draws; the title and description rise in after it.

Destructive

variant="destructive" tints the icon tile, the title and the hairline for something that went wrong.

Dismissible

AlertClose dismisses it: the alert fades and folds its height away, so the page closes up. Control it with open and onOpenChange.

Motion

MoveWhat you see
UnfoldThe alert drops 12px into place out of a 6px blur, growing from 0.96 on a spring.
DrawThe icon pops into its tile, then its strokes draw themselves.
CascadeThe title and description rise in after the icon, one after the other.
HeightDismissed, it fades, blurs and folds its height to nothing, so what sits below closes up.

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

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

"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
--alert-faceAlert surfacebg-card
--alert-inkAlert texttext-card-foreground
--alert-mutedDescriptiontext-muted-foreground
--alert-radiusCornersrounded-[14px]
--alert-fontBody sizetext-[13px]
--alert-gapContent gapgap-y-1
--alert-inset-xSide paddingpx-4
--alert-inset-yVertical paddingpy-3.5

API reference

Every part takes className and children, along with the props of the element it renders. The parts are rendered by UI SDK, so they also take render, to draw your own element, and a function of their state for className and style.

Alert

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

Prop

Type

Other parts

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

  • AlertTitle: a <div>
  • AlertDescription: a <div>
  • AlertClose: a <button>

Keyboard

KeyWhat it does
TabMoves focus to the dismiss button, when there is one.
EnterDismisses the alert from its dismiss button.
SpaceDismisses the alert from its dismiss button.

Accessibility

Roles, keyboard and focus are declared on the component's UI SDK primitive, and state is announced through the matching ARIA attributes. More in Accessibility.

Built on UI SDK's core

UI SDK doesn't ship a alert, so this one is defined with its core: one definePrimitive in components/keyframery/core/alert-core.ts, with no React in it. UI SDK's adapters can render that same definition in Vue, Svelte, Solid and web components. To keep your own styling and take only the motion, import from @/components/keyframery/primitives/alert.

Questions

How does the animated Alert for UI SDK move?

Unfold: The alert drops 12px into place out of a 6px blur, growing from 0.96 on a spring. Draw: The icon pops into its tile, then its strokes draw themselves. Cascade: The title and description rise in after the icon, one after the other. Height: Dismissed, it fades, blurs and folds its height to nothing, so what sits below closes up.

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

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

UI SDK has no alert. How is this one built on UI SDK?

Its behaviour is one definition written with UI SDK's core (definePrimitive), in components/keyframery/core/alert-core.ts. Its parts are rendered by UI SDK's adapter, so they take render, state-based class names and data-slot, like every UI SDK component.

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

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

All components

On this page