Conversation
Prompt Template
A saved prompt read as text, with each variable an inline pill — type, pick, step or attach, Tab to the next empty one.
1 variantMIT
Preview
Demo follow-up
Saved prompt · Sales · used 48 times
6 to fill
Write a follow-up to at after yesterday's demo. Answer the two SSO questions from the call using , keep the tone , stay under words, and close by offering a with our solutions engineer.
0 of 6≈ 64 tokens
Tabnext empty
6 of 6 variables left to fill.
Installation
Copies the component into components/ui and installs its dependencies and theme tokens.
pnpm dlx shadcn@latest add https://tuffui.com/r/prompt-template.jsonUsage
Pass your own data and wire the callbacks to your agent runtime.
import { PromptTemplate } from "@/components/ui/prompt-template";
// A saved prompt from the library, opened in the composer.
export function SavedPrompt({ prompt, recentFiles }: Props) {
const [values, setValues] = useState(prompt.lastValues ?? {});
return (
<PromptTemplate
title={prompt.name} // "Demo follow-up"
subtitle={`Saved prompt · used ${prompt.runs} times`}
template={prompt.body} // "Write a follow-up to {{contact}} at {{company}}…"
variables={[
{ name: "contact" },
{ name: "company" },
{ name: "attachment", type: "file", files: recentFiles },
{
name: "tone",
type: "select",
options: [{ value: "warm" }, { value: "direct" }, { value: "formal" }],
},
{ name: "length", type: "number", min: 50, max: 400, step: 10, defaultNumber: 150 },
]}
values={values}
onValuesChange={setValues}
onSend={(text) => sendMessage(text)}
onSaveAsNew={(v) => savePrompt({ ...prompt, defaults: v })}
onUploadFile={(name) => openFilePicker(name)}
/>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| template* | string | — | The saved prompt. Each `{{name}}` with a matching variable becomes an inline pill; line breaks are kept. A slot used twice shares one value. |
| variables* | PromptVariable[] | — | One per slot: `text` types inline, `select` opens a menu of options, `number` turns the pill into a stepper, `file` offers recent files and an upload. |
| values | Record<string, string> | — | Controlled values by variable name. Empty strings count as unfilled. |
| defaultValues | Record<string, string> | {} | Starting values when uncontrolled. |
| onValuesChange | (values: Record<string, string>) => void | — | Called on every keystroke, pick and step. |
| activeName | string | null | — | Controlled open slot, e.g. to let an agent fill the template in front of the user. Opened this way, editors never take focus. |
| onActiveChange | (name: string | null) => void | — | Called when a pill is opened or closed. Tab and Enter jump to the next empty slot; Esc closes the editor. |
| onSend | (prompt: string, values: Record<string, string>) => void | — | The primary button. Enabled once every slot is filled, and called with the resolved text. |
| onSaveAsNew | (values: Record<string, string>) => void | — | Shows "Save as new template" next to Send. |
| onUploadFile | (name: string) => void | — | Shows "Upload a file…" under the recent files of a `file` slot. |
| countTokens | (prompt: string) => number | about 4 characters a token | Token estimate for the resolved text. Attached files add their own `tokens` on top. |
| title | string | "Prompt template" | Header title, usually the template's name. |
| subtitle | string | — | Secondary line under the title. |
| icon | Icon | NotePencil | Phosphor icon in the header tile. |
| sendLabel | string | "Send" | Label of the primary button. |
| className | string | — | Extra classes for the root element. |
type PromptVariable = {
name: string; // matches {{name}}
type?: "text" | "select" | "number" | "file";
placeholder?: string; // shown in the empty pill, defaults to name
options?: { value: string; label?: string; hint?: string }[]; // select
min?: number; // number
max?: number;
step?: number;
defaultNumber?: number; // where the stepper starts
files?: PromptFile[]; // file: recent files
};
type PromptFile = {
name: string; // "northwind-call-notes.md"
meta?: string; // "PDF · 4 pages"
tokens?: number; // added to the token count once attached
};