Keyframery

Prompt Composer

The input box of an AI chat. It grows with the message, takes files by the paperclip, a drop or a paste, opens orders, people or commands at the caret after @ and /, and its Send key turns into a spinner and then Stop while the reply comes in.

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/prompt-composer

This adds components/keyframery/prompt-composer.tsx and its primitive to your project, and installs UI SDK, along with button, file-input, attachment, select, tooltip, trigger-menu, which it builds on. The motion tokens are added to your global CSS the first time you install a component.

Usage

import { PromptComposer } from "@/components/keyframery/prompt-composer"

export default function Usage() {
  return <PromptComposer placeholder="Ask anything…" onSubmit={({ text, attachments }) => console.log(text, attachments)} />
}

Examples

Mentions and commands

mentions open at the caret after @ and commands after / at the start of the message. Each item can carry an icon, a detail and a group; choosing one inserts its label.

Send and Stop

Pass the chat's status: "submitted" turns Send into a spinner and "streaming" into Stop, which calls onStop. A model picker shows when you pass models.

Uploads

Give upload and each file uploads as soon as it is attached, by the paperclip, a drop or a paste. Its card shows the progress, and Send waits until every file is up. maxLength makes the count read against the limit.

Motion

MoveWhat you see
FadeSend, the spinner and Stop cross-fade in place as the status changes; with more motion they also turn and blur through the swap and land with a pop.
PressSend, Stop and the toolbar buttons give under the pointer and spring back on release.
HeightThe row of files opens to its height when the first file arrives and closes as the last one leaves, so the text moves instead of jumping.
PopEach file pops in from smaller, its upload line fills along its foot, and it shrinks away when removed while the files after it close the gap.
UnfoldThe suggestions unfold from the caret, their rows cascade in, and one highlight glides between them as you arrow through.
RiseWhile files are dragged over the box, a drop layer fades in over it and its label rises; the box leans toward the files.
DirectionThe model picker's choice rises into place, and on a phone the models open as a sheet from the bottom.

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

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

"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
--prompt-composer-faceBox surface--background (dark: --card)
--prompt-composer-inkMessage text--foreground
--prompt-composer-sendSend button--primary
--prompt-composer-radiusBox corners18px
--prompt-composer-fontMessage size14px
--prompt-composer-paddingBox padding0.5rem

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.

PromptComposer

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

Prop

Type

PromptComposerCount

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

Prop

Type

PromptComposerDropzone

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

Prop

Type

PromptComposerInput

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

Prop

Type

PromptComposerSend

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

Prop

Type

Other parts

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

  • PromptComposerAttachments: a <div>
  • PromptComposerDrop: a <div>
  • PromptComposerToolbar: a <div>

Keyboard

KeyWhat it does
EnterSends the message. With submitOn="mod+enter" it starts a new line instead. While suggestions are open, it inserts the highlighted one. Nothing sends while an input method is composing.
Shift+EnterStarts a new line.
Cmd+Enter or Ctrl+EnterAlways sends.
@ or /Opens mentions at the caret, or commands at the start of the message.
ArrowDown, ArrowUpMove through the open suggestions; Tab or Enter inserts one, Escape closes them.
TabMoves from the message to attach, the model, your actions and Send.

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

Questions

How does the animated Prompt Composer for UI SDK move?

Fade: Send, the spinner and Stop cross-fade in place as the status changes; with more motion they also turn and blur through the swap and land with a pop. Press: Send, Stop and the toolbar buttons give under the pointer and spring back on release. Height: The row of files opens to its height when the first file arrives and closes as the last one leaves, so the text moves instead of jumping. Pop: Each file pops in from smaller, its upload line fills along its foot, and it shrinks away when removed while the files after it close the gap. Unfold: The suggestions unfold from the caret, their rows cascade in, and one highlight glides between them as you arrow through. Rise: While files are dragged over the box, a drop layer fades in over it and its label rises; the box leans toward the files. Direction: The model picker's choice rises into place, and on a phone the models open as a sheet from the bottom.

Do I need Motion or Framer Motion for the animated Prompt Composer?

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

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

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

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

All components

On this page