Keyframery

Approval

A person says yes or no to something an AI agent wants to do. The card shows the action, the control the agent would press, details and a risk level, with Approve and Deny; once answered it closes to one line. createApprovals() wires it to UI SDK's agent bridge, whose allow callback waits for the answer. The buttons sit inside data-agent-hidden, so an agent can read the card but can never approve its own request. createApprovals' allow also refuses any step aimed inside an approval card, and while it waits UI SDK holds the waiting agent's later act and query calls.

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

This adds components/keyframery/approval.tsx and its primitive to your project, and installs UI SDK, along with agent-content, badge, button, checkbox, textarea, which it builds on. The motion tokens are added to your global CSS the first time you install a component.

Usage

import { Approval } from "@/components/keyframery/approval"

export default function Usage() {
  return (
    <Approval
      title="Issue a refund"
      description="£84.00 back to Priya Shah's Visa ending 4242."
      target="Press “Refund order #1048”"
      risk="high"
      onApprove={() => {}}
      onDeny={() => {}}
    />
  )
}

Examples

Risk

risk is "low", "medium" or "high". It tints the shield and the label; at high risk Approve turns destructive and, with autoFocus, Deny takes the focus instead of Approve.

Asking why, and the answer

askReason opens a field before Deny goes through; onDeny gets what was typed. Once answered the card closes to one line: "Approved · 2s ago" or "Denied". Control it with status.

With UI SDK's agent bridge

createApprovals() gives you an allow for createAgent and registerTools. A step on a control marked data-agent-confirm becomes a request; render a card for each and the bridge waits until the person answers, or the agent's signal aborts (that denies it). The card's buttons are hidden from agents, so the agent can read the card but never answer it.

Motion

MoveWhat you see
FadeThe card fades in with a small rise when a request arrives; the extra rise and blur are flourish.
HeightOnce answered, the details and buttons close and the card becomes one line.
HeightWith askReason, Deny opens a reason field to its height.
DrawThe answer's tick or cross pops in and draws itself (flourish).
Direction"Approved · 2s ago" rises into the place the risk label leaves (the rise is flourish).

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

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

"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
--approval-faceCard surfacebg-card
--approval-accentRisk accentmuted-foreground / foreground / destructive by risk
--approval-successApproved answeroklch(0.62 0.16 150)
--approval-radiusCard cornersrounded-[14px]
--approval-fontDescription sizetext-[13px]
--approval-title-fontTitle sizetext-[14px]
--approval-insetCard padding14px

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.

Approval

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

Prop

Type

ApprovalActions

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

Prop

Type

ApprovalReveal

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

Prop

Type

Other parts

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

  • ApprovalBody: a <div>
  • ApprovalDescription: a <p>
  • ApprovalDetails: a <div>
  • ApprovalIcon: a <span>
  • ApprovalRisk: a <span>
  • ApprovalSummary: a <div>
  • ApprovalTarget: a <div>
  • ApprovalTitle: a <div>

Hooks

useApproval

Call it inside the component to read and change its state.

Prop

Type

Keyboard

KeyWhat it does
TabMoves between Always allow, Deny and Approve.
Enter or SpacePresses the focused button.
Cmd or Ctrl + EnterIn the reason field: denies with the reason.
EscapeIn the reason field: back to Approve and Deny.

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 approval, so this one is defined with its core: one definePrimitive in components/keyframery/core/approval-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/approval.

Questions

How does the animated Approval for UI SDK move?

Fade: The card fades in with a small rise when a request arrives; the extra rise and blur are flourish. Height: Once answered, the details and buttons close and the card becomes one line. Height: With askReason, Deny opens a reason field to its height. Draw: The answer's tick or cross pops in and draws itself (flourish). Direction: "Approved · 2s ago" rises into the place the risk label leaves (the rise is flourish).

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

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

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

Its behaviour is one definition written with UI SDK's core (definePrimitive), in components/keyframery/core/approval-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 Approval when someone turns on reduced motion?

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

All components

On this page