Components100 / 118
Prompt Composer
The ask-anything box of an AI product, lit by a travelling rim light. A white-hot light runs round its edge, burning pink into violet: it slides to the point nearest your cursor, reads along above your caret as you type, dips to the suggestion you point at and flickers by the mic. Sending draws your words into the send button, which fires a ring of light.
AIAIInputInputFormFormRim lightRim lightSpringsSpringsGSAPGSAP
Hi Maya
Where shall we begin?
Move around the box, then typeTry a suggestion, then send
Tweak
LIVELIVECopy
Usage
Follows your tweaks.
usage.tsx
import { PromptComposer } from "@/components/inreact/prompt-composer";
export function Ask() {
return (
<PromptComposer
name="Maya"
heading="Where shall we begin?"
models={["Nova 2", "Nova 2 mini", "Atlas reasoning"]}
onSend={async (prompt, model) => {
await fetch("/api/ask", { method: "POST", body: JSON.stringify({ prompt, model }) });
}}
/>
);
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/prompt-composer.jsonOr copy the source
Install the dependencies, then save this as components/inreact/prompt-composer.tsx.
terminal
npm install gsapcomponents/inreact/prompt-composer.tsx
"use client";
import { gsap } from "gsap";
import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState, type FormEvent, type KeyboardEvent } from "react";
/**
* Prompt Composer: the ask-anything box of an AI product, lit by a travelling rim light.
*
* A white-hot light runs round the edge of the box, burning pink into violet
* as it fades along the rim and glowing softly onto the page. It slides to
* the point of the edge nearest your cursor, sits above your caret and reads
* along as you type, dips down to whichever suggestion you point at, and
* parks by the mic and flickers like a voice while you dictate. Send, and
* your words are drawn into the send button, which fires a ring of light.
* The model sits inline ("Ask Nova 2 anything") with a springy picker; the
* suggestions type themselves in; the field grows with your text; Enter sends
* and Shift+Enter adds a line.
*
* <PromptComposer name="Maya" onSend={async (prompt, model) => { await ask(prompt, model) }} />
*/
export interface PromptComposerProps {
name?: string;
heading?: string;
models?: string[];
model?: string;
onModelChange?: (m: string) => void;
suggestions?: { label: string; prompt: string }[];
/** Called with the prompt and model; while its promise is pending the box shows a thinking state. */
onSend?: (prompt: string, model: string) => Promise<void> | void;
/** Called when the mic is toggled (wire your own speech input). */
onVoice?: (listening: boolean) => void;
className?: string;
}
const reduced = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const clamp = (a: number, b: number, v: number) => Math.max(a, Math.min(b, v));
/** The nearest point on the box's edge to (x, y), in the box's own px. */
function onRim(x: number, y: number, w: number, h: number) {
const cx = clamp(0, w, x), cy = clamp(0, h, y);
if (cx !== x || cy !== y) return { x: cx, y: cy }; // outside: the clamped point is on the edge
const d = [cy, h - cy, cx, w - cx]; // inside: push to the closest side
const m = Math.min(...d);
if (m === d[0]) return { x: cx, y: 0 };
if (m === d[1]) return { x: cx, y: h };
if (m === d[2]) return { x: 0, y: cy };
return { x: w, y: cy };
}
export function PromptComposer({
name = "Maya",
heading = "Where shall we begin?",
models = ["Nova 2", "Nova 2 mini", "Atlas reasoning"],
model,
onModelChange,
suggestions = [
{ label: "Create an image", prompt: "Create an image of a quiet harbour at dawn, soft pastel light, film grain" },
{ label: "Compose music", prompt: "Compose a calm piano loop in D major for focused work" },
{ label: "Help me learn", prompt: "Explain how vaccines train the immune system, like I'm curious but new to biology" },
{ label: "Plan my day", prompt: "Plan a balanced day for me with deep work, a walk and time to read" },
],
onSend = () => new Promise((r) => setTimeout(r, 1400)),
onVoice,
className,
}: PromptComposerProps) {
const id = useId();
const [inner, setInner] = useState(model ?? models[0]);
const cur = model ?? inner;
const [text, setText] = useState("");
const [menu, setMenu] = useState(false);
const [listening, setListening] = useState(false);
const [thinking, setThinking] = useState(false);
const rootRef = useRef<HTMLDivElement>(null);
const boxRef = useRef<HTMLFormElement>(null);
const rimRef = useRef<HTMLDivElement>(null);
const glowRef = useRef<HTMLDivElement>(null);
const taRef = useRef<HTMLTextAreaElement>(null);
const sendRef = useRef<HTMLButtonElement>(null);
const micRef = useRef<HTMLButtonElement>(null);
const ringRef = useRef<HTMLSpanElement>(null);
const menuRef = useRef<HTMLDivElement>(null);
const modelBtnRef = useRef<HTMLButtonElement>(null);
const chipsRef = useRef<HTMLDivElement>(null);
const headRef = useRef<HTMLHeadingElement>(null);
const hiRef = useRef<HTMLSpanElement>(null);
const phRef = useRef<HTMLSpanElement>(null);
const [focused, setFocused] = useState(false);
const [idea, setIdea] = useState(0);
// where the light wants to be, and how bright it is
const light = useRef({ mode: "idle" as "idle" | "near" | "caret" | "chip" | "send" | "mic", tx: 0, ty: 0, boost: 0, lastKey: 0 });
/* ---- the rim light: a spring that runs round the edge ---- */
useEffect(() => {
const root = rootRef.current, box = boxRef.current, rim = rimRef.current, glow = glowRef.current;
if (!root || !box || !rim || !glow) return;
const still = reduced();
const L = light.current;
const s = { x: box.offsetWidth * 0.5, y: 0, vx: 0, vy: 0, i: 0.8, focus: 0, time: 0 };
const onMove = (e: PointerEvent) => {
if (L.mode === "send" || L.mode === "mic" || L.mode === "chip") return;
if (performance.now() - L.lastKey < 1400 && document.activeElement === taRef.current) return; // reading along with the caret
const r = box.getBoundingClientRect();
const px = e.clientX - r.left, py = e.clientY - r.top;
const far = Math.max(0, -px, px - r.width, -py, py - r.height);
if (far > 180) return void (L.mode = "idle");
const p = onRim(px, py, r.width, r.height);
L.mode = "near";
L.tx = p.x;
L.ty = p.y;
};
// only movement over this component steers the light (never other pointers elsewhere on the page)
root.addEventListener("pointermove", onMove, { passive: true });
const onLeaveRoot = () => L.mode === "near" && (L.mode = "idle");
root.addEventListener("pointerleave", onLeaveRoot);
const tick = (_t: number, ms: number) => {
const dt = Math.min(ms / 1000, 1 / 30);
s.time += dt;
const w = box.offsetWidth, h = box.offsetHeight;
if (L.mode === "idle") {
// drifting slowly along the top edge
L.tx = w * (0.5 + 0.36 * Math.sin(s.time * 0.32));
L.ty = 0;
}
// a slightly underdamped spring: the light overshoots a touch round a corner and settles
if (still) (s.x = L.tx), (s.y = L.ty);
else
for (let k = 0; k < 2; k++) {
s.vx += (80 * (L.tx - s.x) - 14.5 * s.vx) * (dt / 2);
s.vy += (80 * (L.ty - s.y) - 14.5 * s.vy) * (dt / 2);
s.x += s.vx * (dt / 2);
s.y += s.vy * (dt / 2);
}
const focused = document.activeElement === taRef.current;
s.focus += ((focused ? 1 : 0) - s.focus) * (1 - Math.exp(-dt * 6));
L.boost *= Math.exp(-dt * 3.2);
const flicker = L.mode === "mic" && !still ? 0.25 * (0.5 + 0.5 * Math.sin(s.time * 23) * Math.sin(s.time * 7.3)) : 0;
const target = 0.92 + 0.22 * s.focus + L.boost + flicker;
s.i += (target - s.i) * (1 - Math.exp(-dt * 10));
const R = Math.max(w, h) * (0.85 + 0.15 * s.focus);
const a = (v: number) => Math.min(1, v * Math.min(1.25, s.i)).toFixed(3);
const g = `radial-gradient(${R.toFixed(1)}px circle at ${s.x.toFixed(1)}px ${s.y.toFixed(1)}px, rgba(255,255,255,${a(1)}) 0, rgba(255,214,246,${a(0.95)}) 6%, rgba(255,92,207,${a(0.9)}) 17%, rgba(162,75,255,${a(0.8)}) 36%, rgba(96,64,255,${a(0.45)}) 62%, rgba(70,50,210,${a(0.16)}) 85%, rgba(70,50,210,0.08) 100%)`;
rim.style.background = g;
// the soft glow it casts onto the page, behind the box
const G = 40;
glow.style.background = `radial-gradient(${(R * 0.75).toFixed(1)}px circle at ${(s.x + G).toFixed(1)}px ${(s.y + G).toFixed(1)}px, rgba(255,120,220,${a(0.72)}), rgba(150,80,255,${a(0.45)}) 45%, transparent 75%)`;
glow.style.opacity = Math.min(1, 0.6 + 0.35 * s.i).toFixed(3);
// the heading above is lit from below by the same light: its words blush where the light passes under them
const head = headRef.current;
if (head) {
const hb = head.getBoundingClientRect(), bb = box.getBoundingClientRect();
const z = bb.width / Math.max(1, w); // the component may be scaled
const lx = (bb.left - hb.left) / z + s.x, ly = (bb.top - hb.top) / z + s.y;
const near = Math.max(0, 1 - s.y / Math.max(1, h)); // strongest while the light is on the top edge
const k = (0.5 + 0.5 * near) * Math.min(1.15, s.i);
head.style.backgroundImage = `radial-gradient(${(w * 0.36).toFixed(0)}px ${(h * 1.15).toFixed(0)}px at ${lx.toFixed(1)}px ${ly.toFixed(1)}px, rgba(255,120,215,${Math.min(1, k).toFixed(3)}), rgba(205,150,255,${Math.min(1, k * 0.8).toFixed(3)}) 38%, rgba(255,255,255,1) 78%), linear-gradient(#fff, #fff)`;
}
};
gsap.ticker.add(tick);
return () => {
gsap.ticker.remove(tick);
root.removeEventListener("pointermove", onMove);
root.removeEventListener("pointerleave", onLeaveRoot);
};
}, []);
// the light sits above the caret while you type
const followCaret = useCallback(() => {
const ta = taRef.current, box = boxRef.current;
if (!ta || !box) return;
const L = light.current;
L.lastKey = performance.now();
if (L.mode === "send" || L.mode === "mic") return;
const before = ta.value.slice(0, ta.selectionStart ?? ta.value.length).split("\n").pop() ?? "";
const cs = getComputedStyle(ta);
const ctx = document.createElement("canvas").getContext("2d")!;
ctx.font = `${cs.fontWeight} ${cs.fontSize} ${cs.fontFamily}`;
const tw = ta.clientWidth - parseFloat(cs.paddingLeft) - parseFloat(cs.paddingRight);
const wpx = ctx.measureText(before).width % Math.max(1, tw);
const tr = ta.getBoundingClientRect(), br = box.getBoundingClientRect();
L.mode = "caret";
L.tx = clamp(8, br.width - 8, tr.left - br.left + parseFloat(cs.paddingLeft) + wpx);
L.ty = 0;
L.boost = Math.min(0.45, L.boost + 0.16);
}, []);
// while the box is empty, the placeholder rolls through ideas
const ideas = ["anything…", "to plan a trip…", "to draft an email…", "for a recipe…", "to explain an idea…"];
useEffect(() => {
if (text || focused || reduced()) return;
const id = window.setInterval(() => {
const el = phRef.current;
if (!el) return;
gsap.to(el, {
yPercent: -60, opacity: 0, filter: "blur(4px)", duration: 0.32, ease: "power2.in",
onComplete: () => {
setIdea((i) => (i + 1) % ideas.length);
gsap.fromTo(el, { yPercent: 60, opacity: 0, filter: "blur(4px)" }, { yPercent: 0, opacity: 1, filter: "blur(0px)", duration: 0.55, ease: "back.out(2)" });
},
});
}, 2600);
return () => window.clearInterval(id);
}, [text, focused]); // eslint-disable-line react-hooks/exhaustive-deps
// the box lifts a touch while you write in it
useEffect(() => {
const box = boxRef.current;
if (!box || reduced()) return;
gsap.to(box, { y: focused ? -3 : 0, duration: 0.6, ease: focused ? "back.out(2.2)" : "power3.out", overwrite: "auto" });
}, [focused]);
// the field grows with the text
useLayoutEffect(() => {
const ta = taRef.current;
if (!ta) return;
ta.style.height = "auto";
ta.style.height = `${Math.min(ta.scrollHeight, 220)}px`;
}, [text]);
// greeting: words rise in one after another
useEffect(() => {
const root = rootRef.current;
if (!root || reduced()) return;
gsap.fromTo(root.querySelectorAll("[data-word]"), { yPercent: 70, opacity: 0, rotate: 4 }, { yPercent: 0, opacity: 1, rotate: 0, duration: 0.8, ease: "back.out(1.8)", stagger: 0.06, delay: 0.1, clearProps: "transform" });
gsap.fromTo(root.querySelectorAll("[data-chip]"), { y: 10, opacity: 0, scale: 0.9 }, { y: 0, opacity: 1, scale: 1, duration: 0.6, ease: "back.out(2.2)", stagger: 0.06, delay: 0.45 });
}, []);
// the send button wakes up when there is something to send
const hasText = text.trim().length > 0;
useEffect(() => {
const b = sendRef.current;
if (!b || reduced()) return;
gsap.to(b, { scale: hasText ? 1 : 0.88, opacity: hasText || thinking ? 1 : 0.5, duration: 0.45, ease: hasText ? "back.out(3)" : "power2.out", overwrite: "auto" });
}, [hasText, thinking]);
const send = async (e?: FormEvent) => {
e?.preventDefault();
const prompt = text.trim();
if (!prompt || thinking) return;
const box = boxRef.current, ta = taRef.current, btn = sendRef.current;
const L = light.current;
setMenu(false);
if (box && ta && btn && !reduced()) {
const br = box.getBoundingClientRect(), bb = btn.getBoundingClientRect(), tr = ta.getBoundingClientRect();
// the light rushes to the send button…
L.mode = "send";
L.tx = bb.left - br.left + bb.width / 2;
L.ty = br.height;
L.boost = 0.9;
// …and the words are drawn into it
const ghost = document.createElement("div");
ghost.textContent = prompt;
Object.assign(ghost.style, { position: "absolute", left: `${tr.left - br.left}px`, top: `${tr.top - br.top}px`, width: `${tr.width}px`, font: getComputedStyle(ta).font, color: "#fff", whiteSpace: "pre-wrap", pointerEvents: "none", transformOrigin: `${bb.left - tr.left + bb.width / 2}px ${bb.top - tr.top + bb.height / 2}px` });
box.appendChild(ghost);
gsap.to(ghost, { scale: 0.05, opacity: 0, filter: "blur(4px)", duration: 0.5, ease: "power3.in", onComplete: () => ghost.remove() });
// the button squashes, then fires a ring of light
gsap.timeline()
.to(btn, { scaleX: 1.12, scaleY: 0.86, duration: 0.1, ease: "power2.out" }, 0.38)
.to(btn, { scaleX: 1, scaleY: 1, duration: 0.7, ease: "elastic.out(1, 0.35)" }, 0.48);
if (ringRef.current) gsap.fromTo(ringRef.current, { scale: 0.6, opacity: 0.9 }, { scale: 3.2, opacity: 0, duration: 0.8, ease: "power2.out", delay: 0.45 });
gsap.fromTo(box, { scaleY: 1 }, { keyframes: [{ scaleY: 0.975, duration: 0.12, ease: "power2.out", delay: 0.42 }, { scaleY: 1, duration: 0.6, ease: "elastic.out(1, 0.4)" }] });
}
setText("");
setThinking(true);
try {
await onSend(prompt, cur);
} finally {
setThinking(false);
L.mode = "idle";
}
};
const onKey = (e: KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing) {
e.preventDefault();
void send();
}
};
// a suggestion types itself into the box
const typeIn = (prompt: string, el: HTMLElement) => {
const ta = taRef.current, root = rootRef.current;
if (!ta || !root) return;
ta.focus();
if (reduced()) return setText(prompt);
gsap.fromTo(el, { scale: 0.9 }, { scale: 1, duration: 0.6, ease: "elastic.out(1, 0.4)" });
// follow-through: the chip's label lifts off and arcs up into the box
const rr = root.getBoundingClientRect(), cr = el.getBoundingClientRect(), tr = ta.getBoundingClientRect();
const z = rr.width / Math.max(1, root.offsetWidth);
const fly = document.createElement("span");
fly.textContent = el.textContent;
Object.assign(fly.style, { position: "absolute", left: `${(cr.left - rr.left) / z + 16}px`, top: `${(cr.top - rr.top) / z + 9}px`, font: getComputedStyle(el).font, color: "#fff", whiteSpace: "nowrap", pointerEvents: "none", zIndex: "30" });
root.appendChild(fly);
const dx = (tr.left - cr.left) / z - 16, dy = (tr.top - cr.top) / z - 2;
const o = { t: 0 };
gsap.to(o, {
t: 1, duration: 0.6, ease: "power2.inOut",
onUpdate: () => {
const t = o.t, arc = -Math.sin(t * Math.PI) * 46; // a lob, not a straight line
fly.style.transform = `translate(${(dx * t).toFixed(1)}px, ${(dy * t + arc).toFixed(1)}px) scale(${(1 - 0.15 * t).toFixed(3)})`;
fly.style.opacity = String(t > 0.75 ? (1 - t) / 0.25 : 1);
},
onComplete: () => fly.remove(),
});
window.setTimeout(() => runType(prompt), 480);
};
const runType = (prompt: string) => {
const o = { n: 0 };
gsap.to(o, {
n: prompt.length,
duration: Math.min(1.4, prompt.length * 0.018),
ease: "none",
onUpdate: () => {
setText(prompt.slice(0, Math.round(o.n)));
requestAnimationFrame(followCaret);
},
});
};
const chipLight = (el: HTMLElement | null) => {
const box = boxRef.current, L = light.current;
if (!box) return;
if (!el) return void (L.mode === "chip" && (L.mode = "idle"));
const br = box.getBoundingClientRect(), cr = el.getBoundingClientRect();
L.mode = "chip";
L.tx = clamp(10, br.width - 10, cr.left - br.left + cr.width / 2);
L.ty = br.height;
};
const toggleMic = () => {
const next = !listening;
setListening(next);
onVoice?.(next);
const L = light.current, box = boxRef.current, mic = micRef.current;
if (next && box && mic) {
const br = box.getBoundingClientRect(), mr = mic.getBoundingClientRect();
L.mode = "mic";
L.tx = mr.left - br.left + mr.width / 2;
L.ty = br.height;
} else L.mode = "idle";
};
// model menu: springs open, closes on outside click or Escape
useLayoutEffect(() => {
const m = menuRef.current;
if (!m) return;
if (reduced()) return void gsap.set(m, { autoAlpha: menu ? 1 : 0 });
if (menu) {
gsap.fromTo(m, { autoAlpha: 0, y: -8, scale: 0.88, filter: "blur(6px)" }, { autoAlpha: 1, y: 0, scale: 1, filter: "blur(0px)", duration: 0.5, ease: "back.out(1.8)", overwrite: true });
gsap.fromTo(m.querySelectorAll("[role=menuitemradio]"), { opacity: 0, y: -4 }, { opacity: 1, y: 0, duration: 0.35, ease: "power2.out", stagger: 0.04, delay: 0.05 });
} else gsap.to(m, { autoAlpha: 0, y: -6, scale: 0.94, filter: "blur(4px)", duration: 0.2, ease: "power2.in", overwrite: true });
}, [menu]);
useEffect(() => {
if (!menu) return;
const away = (e: PointerEvent) => !menuRef.current?.contains(e.target as Node) && !modelBtnRef.current?.contains(e.target as Node) && setMenu(false);
const esc = (e: globalThis.KeyboardEvent) => e.key === "Escape" && (setMenu(false), modelBtnRef.current?.focus());
window.addEventListener("pointerdown", away);
window.addEventListener("keydown", esc);
return () => {
window.removeEventListener("pointerdown", away);
window.removeEventListener("keydown", esc);
};
}, [menu]);
// a highlight that glides between the options on a soft spring
const glideTo = (el: HTMLElement | null) => {
const hi = hiRef.current;
if (!hi) return;
if (!el) return void gsap.to(hi, { opacity: 0, duration: 0.25, overwrite: "auto" });
const first = hi.style.opacity === "0" || !hi.style.opacity;
gsap.to(hi, { top: el.offsetTop, height: el.offsetHeight, opacity: 1, duration: first || reduced() ? 0 : 0.45, ease: "back.out(1.6)", overwrite: "auto" });
};
const pick = (m: string) => {
if (model === undefined) setInner(m);
onModelChange?.(m);
setMenu(false);
if (modelBtnRef.current && !reduced()) gsap.fromTo(modelBtnRef.current, { scale: 0.9 }, { scale: 1, duration: 0.5, ease: "back.out(3)" });
};
const iconBtn = "grid size-9 cursor-pointer place-items-center rounded-full border-0 bg-transparent text-white/75 outline-none transition-colors duration-200 hover:bg-white/[0.08] hover:text-white focus-visible:ring-2 focus-visible:ring-white/40";
return (
<div ref={rootRef} className={["w-full max-w-[640px] text-white", className].filter(Boolean).join(" ")}>
<div className="mb-5 px-1">
<div className="flex items-center gap-2 text-[17px] font-medium text-white/90">
<svg viewBox="0 0 24 24" width="22" height="22" aria-hidden="true">
<defs>
<linearGradient id={`${id}-mark`} x1="0" y1="0" x2="1" y2="1">
<stop offset="0" stopColor="#ff8ad8" />
<stop offset="1" stopColor="#7b5cff" />
</linearGradient>
</defs>
<path d="M4 4h6l4 6-4 10H4l4-10z M14 4h6l-4 6 4 10h-6l-4-10z" fill={`url(#${id}-mark)`} />
</svg>
<span className="overflow-hidden">
<span data-word className="inline-block">
Hi {name}
</span>
</span>
</div>
<h2 ref={headRef} className="mt-1 bg-white bg-clip-text text-[34px] leading-tight font-medium tracking-[-0.025em] text-transparent">
{heading.split(" ").map((w, i) => (
<span key={i} className="inline-block overflow-hidden pb-[0.08em] align-bottom">
<span data-word className="inline-block">
{w}
</span>
</span>
))}
</h2>
</div>
<form ref={boxRef} onSubmit={send} className="relative isolate z-10 rounded-[22px] p-4 pt-3.5" style={{ transformOrigin: "50% 100%" }}>
{/* the light it casts onto the page, and the lit rim itself (a 1.5px ring) */}
<div ref={glowRef} aria-hidden="true" className="pointer-events-none absolute -inset-[40px] -z-10" style={{ filter: "blur(26px)" }} />
{/* the box's own dark body sits above the glow, so the light stays outside and on the rim */}
<div aria-hidden="true" className="pointer-events-none absolute inset-0 -z-[5] rounded-[22px] bg-[#0c0c10]" style={{ boxShadow: "inset 0 1px 18px rgba(255,140,220,0.05)" }} />
<div
ref={rimRef}
aria-hidden="true"
className="pointer-events-none absolute inset-0 rounded-[22px] p-[1.75px]"
style={{ WebkitMask: "linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)", WebkitMaskComposite: "xor", mask: "linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0)" }}
/>
<div className="flex flex-wrap items-start gap-x-1.5">
<span className="pt-[7px] text-[14px] text-white/45">Ask</span>
<span className="relative pt-[3px]">
<button
ref={modelBtnRef}
type="button"
aria-haspopup="menu"
aria-expanded={menu}
onClick={() => setMenu((m) => !m)}
className="flex h-7 cursor-pointer items-center gap-1 rounded-full border-0 bg-transparent px-1.5 text-[14px] font-semibold text-white outline-none transition-colors hover:bg-white/[0.08] focus-visible:ring-2 focus-visible:ring-white/40"
>
{cur}
<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" style={{ transform: menu ? "rotate(180deg)" : "none", transition: "transform .4s cubic-bezier(.34,1.56,.64,1)" }}>
<path d="M6 9l6 6 6-6" />
</svg>
</button>
<div
ref={menuRef}
role="menu"
onPointerLeave={() => glideTo(null)}
className="invisible absolute top-full left-0 z-50 mt-2 w-52 origin-top-left rounded-[16px] bg-[#17171d] p-1.5 opacity-0"
style={{ boxShadow: "0 1px 0 rgba(255,255,255,0.06) inset, 0 24px 50px -18px rgba(0,0,0,0.9), 0 10px 24px -12px rgba(120,60,200,0.35)" }}
>
<span ref={hiRef} aria-hidden="true" className="pointer-events-none absolute right-1.5 left-1.5 rounded-[10px] opacity-0" style={{ background: "linear-gradient(90deg, rgba(255,120,220,0.16), rgba(140,90,255,0.12))", top: 6, height: 34 }} />
{models.map((m) => (
<button
key={m}
type="button"
role="menuitemradio"
aria-checked={m === cur}
onClick={() => pick(m)}
onPointerEnter={(e) => glideTo(e.currentTarget)}
onFocus={(e) => glideTo(e.currentTarget)}
className="relative flex h-[34px] w-full cursor-pointer items-center justify-between rounded-[10px] border-0 bg-transparent px-3 text-left text-[13px] text-white/85 outline-none transition-colors duration-200 hover:text-white focus-visible:text-white"
>
{m}
{m === cur && (
<svg viewBox="0 0 16 16" width="13" height="13" aria-hidden="true">
<path d="M3 8.5l3.2 3L13 4.5" fill="none" stroke="#ff8ad8" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" />
</svg>
)}
</button>
))}
</div>
</span>
{/* the field and its rolling placeholder share one box, so the placeholder sits exactly where text begins */}
<span className="relative min-w-[8rem] flex-1">
<textarea
ref={taRef}
rows={1}
value={text}
aria-label={`Ask ${cur}`}
onChange={(e) => {
setText(e.target.value);
followCaret();
}}
onKeyDown={onKey}
onFocus={() => setFocused(true)}
onBlur={() => setFocused(false)}
onKeyUp={followCaret}
onClick={followCaret}
className="relative z-[1] block min-h-[34px] w-full resize-none border-0 bg-transparent py-[7px] text-[14px] leading-[20px] text-white outline-none"
/>
{!text && (
<span aria-hidden="true" className="pointer-events-none absolute top-[7px] left-0 overflow-hidden text-[14px] leading-[20px] text-white/40">
<span ref={phRef} className="inline-block will-change-transform">
{ideas[idea]}
</span>
</span>
)}
</span>
</div>
<div className="mt-6 flex items-center justify-between">
<div className="flex items-center gap-0.5">
<button type="button" aria-label="Attach" className={iconBtn}>
<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" strokeWidth="1.9" strokeLinecap="round" aria-hidden="true">
<path d="M12 5v14M5 12h14" />
</svg>
</button>
<button type="button" aria-label="Options" className={iconBtn}>
<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" aria-hidden="true">
<path d="M4 7h10M18 7h2M4 17h4M12 17h8" />
<circle cx="16" cy="7" r="2" />
<circle cx="10" cy="17" r="2" />
</svg>
</button>
</div>
<div className="flex items-center gap-2">
<button ref={micRef} type="button" aria-label={listening ? "Stop dictation" : "Dictate"} aria-pressed={listening} onClick={toggleMic} className={iconBtn}>
{listening ? (
<span className="flex h-4 items-center gap-[3px]" aria-hidden="true">
{[0, 1, 2, 3].map((i) => (
<span key={i} className="w-[3px] rounded-full bg-[#ff8ad8]" style={{ height: "100%", animation: `pc-bar 0.9s ${i * 0.12}s ease-in-out infinite` }} />
))}
</span>
) : (
<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" aria-hidden="true">
<rect x="9" y="3" width="6" height="11" rx="3" />
<path d="M5.5 11a6.5 6.5 0 0 0 13 0M12 17.5V21" />
</svg>
)}
</button>
<span className="relative">
<span ref={ringRef} aria-hidden="true" className="pointer-events-none absolute inset-0 rounded-full opacity-0" style={{ boxShadow: "0 0 0 2px rgba(255,138,216,0.9)" }} />
<button
ref={sendRef}
type="submit"
aria-label={thinking ? "Thinking" : "Send"}
disabled={!hasText && !thinking}
className="grid size-9 cursor-pointer place-items-center rounded-full border-0 bg-white text-[#0c0c10] outline-none focus-visible:ring-2 focus-visible:ring-white/60 disabled:cursor-default"
style={{ opacity: 0.5, transform: "scale(0.88)" }}
>
{thinking ? (
<span className="block size-4 rounded-full border-2 border-[#0c0c10]/25 border-t-[#0c0c10]" style={{ animation: "pc-spin 0.8s linear infinite" }} aria-hidden="true" />
) : (
<svg viewBox="0 0 24 24" width="17" height="17" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<path d="M12 19V5M5.5 11.5 12 5l6.5 6.5" />
</svg>
)}
</button>
</span>
</div>
</div>
<style>{`@keyframes pc-bar{0%,100%{transform:scaleY(.3)}50%{transform:scaleY(1)}}@keyframes pc-spin{to{transform:rotate(360deg)}}`}</style>
</form>
<div ref={chipsRef} className="relative z-0 mt-4 flex flex-wrap justify-center gap-2">
{suggestions.map((sg) => (
<button
key={sg.label}
data-chip
type="button"
onPointerEnter={(e) => chipLight(e.currentTarget)}
onPointerLeave={() => chipLight(null)}
onFocus={(e) => chipLight(e.currentTarget)}
onBlur={() => chipLight(null)}
onClick={(e) => typeIn(sg.prompt, e.currentTarget)}
className="h-9 cursor-pointer rounded-full border-0 bg-white/[0.07] px-4 text-[13px] text-white/70 outline-none transition-colors duration-200 hover:bg-white/[0.12] hover:text-white focus-visible:ring-2 focus-visible:ring-white/40"
>
{sg.label}
</button>
))}
</div>
</div>
);
}
export default PromptComposer;
One prompt, any AI agent
Paste into Claude Code, Codex, Cursor or Windsurf. It carries your tweaks and the full source, so the agent installs it exactly.
Props
7 propsname / headingstringThe greeting and the line under it.modelsstring[]Models in the inline picker.model / onModelChangestring / (m) => voidControlled model.suggestions{ label, prompt }[]Chips that type their prompt into the box.onSend(prompt, model) => Promise<void> | voidSend; while its promise is pending the box shows a thinking state.onVoice(listening) => voidCalled when the mic is toggled.classNamestringExtra classes.