AI Prompt Box

A chat input where how long you hold send sets how hard the AI thinks.

Dependencies

motion

Interaction Type

Type a prompt and tap send or press Enter to send it. Hold either one instead to charge it: the button fills with color and the bars light up as it climbs from Quick to Think to Think deeply. Letting go sends at that level. Press Escape or drag off the button to cancel a charge. When you send, the words rise out of the box.

Props

Options you can pass to customize this component.

Prop
Type
Description
onSubmit
(prompt: string, effort: PromptEffort) => void

Called on send with the trimmed prompt and the effort it was charged to. A tap sends at the first effort.

efforts
PromptEffort[]

The levels a hold climbs through, each an id, a label, and an optional hex color. Each level takes 650ms; pass one level to turn charging off.

status
idlestreaming

Streaming turns the send button into a stop button, ringed in the color of the effort it was sent at. You can still type, but sending waits until it is idle.

onStop
() => void

Called when the stop button is pressed while streaming.

placeholder
stringstring[]

Pass an array to rotate through them every 3.2 seconds while the box is empty.

hint
ReactNode

Shown next to the send button once there is text. Pass null to hide it.

actions
ReactNode

Buttons for the left side of the bottom row, like attach or web search.

value
string

Pass this to control the text. Pair it with onValueChange.

defaultValue
string

The text on first render.

onValueChange
(value: string) => void

Called with the new text on every edit, and with an empty string after a send.

disabled
boolean

Dims the box and blocks typing and sending.

inputRef
Ref<HTMLTextAreaElement>

A ref to the textarea, for focusing it after a send or on page load.

inputProps
TextareaHTMLAttributes

Extra props for the textarea, like name, id, autoFocus, or maxLength. Its key and blur handlers run before the box's own; call preventDefault in onKeyDown to stop Enter from sending.

className
string

Extra classes merged onto the root element (data-slot="prompt-box", with data-status). The width defaults to 560px, and the text grows to 192px before it scrolls.

Installation

npx shadcn@latest add swamimalode07/rare-ui/prompt-box

How to use

"use client"
import { useState } from "react"
import { PromptBox, type PromptBoxStatus } from "@/components/ui/prompt-box"
export function Chat() {
const [status, setStatus] = useState<PromptBoxStatus>("idle")
return (
<PromptBox
status={status}
placeholder={["Ask anything", "Plan a weekend in Kyoto"]}
onSubmit={async (prompt, effort) => {
setStatus("streaming")
// effort.id is "quick", "think", or "deep"
await sendToModel(prompt, effort.id)
setStatus("idle")
}}
onStop={() => setStatus("idle")}
/>
)
}

Source Code

Click the code icon in the top-right corner to view the source code.

Keep in mind

Most components here are recreations of great work from around the web. I don't claim to be the original creator - this is my attempt to reverse-engineer, replicate, and often add a few extra features. I've tried to credit everyone; if I missed someone, let me know.

Contact

Found a bug or issue? Feel free to drop a DM.

License & Usage

  • •MIT with the Commons Clause and an attribution requirement. Free to use, modify and ship in personal and commercial projects, closed source included. You own the code once it is in your project.
  • •Credit is required. Any project shipping a Rare UI component must credit Rare UI with a visible link back to rareui.com, in a footer, an about page, a credits screen or a README.
  • •Don't strip the credit or the copyright notice from the source you copied.
  • •Don't sell, sublicense or redistribute the components themselves, on their own, bundled into a template, kit, theme or paid course, or ported to another framework.
  • •Don't republish them. No mirrors, no re-uploads, no listing them as your own work.
  • •Don't repackage the registry as a competing component library.
  • •Don't claim authorship of a component or of Rare UI itself.
  • •The LICENSE file in the repository is the full text and governs. Ask first if your use doesn't fit these rules.
AI Prompt Box

What should we think about?