Messages
Question Typer
Each question is typed out and its answer appears right under it, changing with every question.
"use client";
import { useRef } from "react";
import gsap from "gsap";
import { useGSAP } from "@gsap/react";
gsap.registerPlugin(useGSAP);
export type QuestionAnswer = { question: string; answer: string };
export type QuestionTyperProps = {
/** Each question is typed out, then its answer appears under it. */
items?: QuestionAnswer[];
/** Label above the answer. */
answerLabel?: string;
/** Accent color of the bar and the answer mark. */
accent?: string;
/** Replay forever with a pause between runs. */
loop?: boolean;
className?: string;
};
const TYPE = 0.045; // segundos por letra da pergunta
const WRITE = 0.022; // segundos por letra da resposta
export default function QuestionTyper({
items = [
{ question: "What color is a lime?", answer: "A lime is green." },
{ question: "How many days are in a week?", answer: "A week has seven days." },
{ question: "What is the capital of Brazil?", answer: "The capital of Brazil is Brasília." },
],
answerLabel = "Answer",
accent = "#1f5bff",
loop = true,
className = "",
}: QuestionTyperProps) {
const root = useRef<HTMLDivElement>(null);
useGSAP(
() => {
const q = gsap.utils.selector(root);
const questionEl = q("[data-question]")[0] as HTMLElement;
const answerEl = q("[data-answer]")[0] as HTMLElement;
const answerBox = q("[data-answer-box]")[0];
// Escreve um texto letra a letra num elemento, dentro da timeline.
const typeInto = (tl: gsap.core.Timeline, el: HTMLElement, text: string, from: number, to: number, perChar: number, at: number) => {
const state = { n: from };
tl.to(
state,
{
n: to,
duration: Math.max(0.05, Math.abs(to - from) * perChar),
ease: "none",
onUpdate: () => {
el.textContent = text.slice(0, Math.round(state.n));
},
},
at,
);
};
const tl = gsap.timeline({ repeat: loop ? -1 : 0, repeatDelay: 0.4 });
tl.set(answerBox, { autoAlpha: 0, y: 8, filter: "blur(6px)" }).add(() => {
questionEl.textContent = "";
answerEl.textContent = "";
}, 0);
let t = 0.3;
let firstDone = 0;
items.forEach(({ question, answer }, i) => {
typeInto(tl, questionEl, question, 0, question.length, TYPE, t);
t += question.length * TYPE + 0.35;
// A resposta muda junto com a pergunta: limpa a anterior e escreve a nova.
tl.add(() => {
answerEl.textContent = "";
}, t);
tl.to(answerBox, { autoAlpha: 1, y: 0, filter: "blur(0px)", duration: 0.5, ease: "expo.out" }, t);
typeInto(tl, answerEl, answer, 0, answer.length, WRITE, t + 0.15);
t += 0.15 + answer.length * WRITE;
if (i === 0) firstDone = t;
t += 1.6;
// Apaga para a próxima (na última, o loop recomeça do zero).
tl.to(answerBox, { autoAlpha: 0, y: -8, filter: "blur(6px)", duration: 0.3, ease: "power2.in" }, t);
typeInto(tl, questionEl, question, question.length, 0, 0.012, t);
t += Math.max(0.3, question.length * 0.012) + 0.25;
});
// Cursor piscando, fora da timeline principal.
gsap.to(q("[data-caret]"), { opacity: 0, duration: 0.5, repeat: -1, yoyo: true, ease: "steps(1)" });
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) tl.pause(firstDone);
},
{ scope: root, dependencies: [loop, items.map((it) => it.question + it.answer).join("|")] },
);
return (
<div ref={root} className={`w-full max-w-lg rounded-xl bg-[#14161a] p-6 text-[#ece8df] ${className}`}>
<div className="flex min-h-[46px] items-start gap-2.5 text-[17px] leading-snug">
<span className="w-[3px] shrink-0 self-stretch rounded-full" style={{ backgroundColor: accent }} />
<span className="min-w-0">
<span data-question />
<span data-caret className="ml-0.5 inline-block h-[18px] w-0.5 align-[-3px] bg-[#ece8df]" />
</span>
</div>
<div data-answer-box className="mt-4 min-h-[56px] rounded-lg bg-white/[0.04] px-3.5 py-3">
<p className="mb-1 flex items-center gap-1.5 text-[11px] font-semibold tracking-[0.12em] text-[#a9a294] uppercase">
<span className="h-1.5 w-1.5 rounded-full" style={{ backgroundColor: accent }} />
{answerLabel}
</p>
<p data-answer className="text-[15px] leading-snug text-[#ece8df]" />
</div>
</div>
);
}
Paste this into Claude Code inside your project. It installs the skills your agent needs, asks for your texts and colors, and recreates this animation in your stack.
SkillsGSAP skillsHyperFrames · optional, for video
Claude Code
Recreate the "Question Typer" animated component from Motionshelf (https://motionshelf-pi.vercel.app) in my current project, adapted to my brand. Answer me in the language I write to you in. Work in this order: 1. Tools: Check whether the official GSAP skills are installed (gsap-core, gsap-timeline, gsap-react). If they are not, ask me and then run `npx skills add https://github.com/greensock/gsap-skills` (choose Claude Code). If they do not show up in this session yet, read the SKILL.md files the installer created for gsap-timeline and gsap-react before writing code. 2. Project: Look at my project: framework (Next.js, Vite, plain HTML…), TypeScript or JavaScript, Tailwind or plain CSS. Build it as one component that fits this stack. In React use gsap and @gsap/react; in plain HTML use GSAP from npm or a CDN. 3. Ask me before coding: Ask me these in a single message, showing the example values as defaults: - the questions and the answer to each one - the label above the answer - the accent color - the language of the texts 4. The animation What it looks like: A dark card with a colored bar on the left. A question types itself out, and its answer appears under it in a box with a small label. Step by step: - The question types out at 0.045 s per letter, with a blinking caret (steps ease, its own loop outside the main timeline). - 0.35 s later the answer box rises in with a blur that clears, and the answer writes itself faster (0.022 s per letter). - After 1.6 s the answer box fades up and out and the question erases quickly; then the next question starts. After the last one, the loop restarts. Rules: - Use one GSAP timeline that loops forever with a short pause between runs (repeat: -1). If the step by step gives the pause, use that value; otherwise repeatDelay about 1.4 s. - Set every starting state with set() at the start of the timeline, never with from(): on the second loop from() starts from the wrong place. - Elements that appear later and would push the layout (new chat bubbles, new rows) stay display:none until their turn; elements that already have their place in the layout (a subtitle, a button) start hidden with autoAlpha 0, so nothing jumps. - If there is a cursor or pointer, it aims at the measured center of its target (getBoundingClientRect), never at fixed pixel coordinates; if the component is scaled, divide by the scale. - Blur only in the middle of a movement and always end at blur(0). - With prefers-reduced-motion, jump to the final frame and stop (tl.progress(1).pause()). - In React, use useGSAP from @gsap/react with a scope ref, so the timeline is cleaned up on unmount. - All example content stays generic (no real brands, logos or people). - With reduced motion, stop on the first question already answered. 5. Check: Run it and watch the first and the third loop (they must look the same). Check it at 390 px wide with no sideways scroll, with reduced motion turned on, and with a clean console. Tell me what you checked. 6. Video (optional): If I also want this as an MP4 (ads, stories, WhatsApp status), install the HyperFrames plugin with `claude plugin marketplace add heygen-com/hyperframes` and `claude plugin install hyperframes@hyperframes`, then use /hyperframes:hyperframes to render the same animation in 9:16, 1:1 or 16:9. Rendering needs FFmpeg installed, or render with --docker (downloads about 3.3 GB the first time). Ask me before installing. Shortcut: If I only want the ready-made component instead, it installs with `npx shadcn@latest add https://motionshelf-pi.vercel.app/r/question-typer.json`.
Other agentsUsing Cursor, Codex, Gemini CLI or another agent? This version tells it to find its own way to load the same skills before it starts.
Other agents
Recreate the "Question Typer" animated component from Motionshelf (https://motionshelf-pi.vercel.app) in my current project, adapted to my brand. Answer me in the language I write to you in. Work in this order: 1. Tools: These instructions were written for Claude Code, which uses "skills" (folders with a SKILL.md that teach it a technique). First find out how you load skills, rules or instructions, and get the same knowledge: (a) if your agent is supported by the skills installer, ask me and run `npx skills add https://github.com/greensock/gsap-skills --agent <your-agent>` (for example codex, opencode, antigravity); (b) otherwise copy the skill folders from https://github.com/greensock/gsap-skills into your skills or rules directory (in Cursor: Settings → Rules → Remote Rule (GitHub) → greensock/gsap-skills); (c) if you cannot load skills at all, open the SKILL.md files in https://github.com/greensock/gsap-skills and read them as instructions before coding. Tell me which path you used. 2. Project: Look at my project: framework (Next.js, Vite, plain HTML…), TypeScript or JavaScript, Tailwind or plain CSS. Build it as one component that fits this stack. In React use gsap and @gsap/react; in plain HTML use GSAP from npm or a CDN. 3. Ask me before coding: Ask me these in a single message, showing the example values as defaults: - the questions and the answer to each one - the label above the answer - the accent color - the language of the texts 4. The animation What it looks like: A dark card with a colored bar on the left. A question types itself out, and its answer appears under it in a box with a small label. Step by step: - The question types out at 0.045 s per letter, with a blinking caret (steps ease, its own loop outside the main timeline). - 0.35 s later the answer box rises in with a blur that clears, and the answer writes itself faster (0.022 s per letter). - After 1.6 s the answer box fades up and out and the question erases quickly; then the next question starts. After the last one, the loop restarts. Rules: - Use one GSAP timeline that loops forever with a short pause between runs (repeat: -1). If the step by step gives the pause, use that value; otherwise repeatDelay about 1.4 s. - Set every starting state with set() at the start of the timeline, never with from(): on the second loop from() starts from the wrong place. - Elements that appear later and would push the layout (new chat bubbles, new rows) stay display:none until their turn; elements that already have their place in the layout (a subtitle, a button) start hidden with autoAlpha 0, so nothing jumps. - If there is a cursor or pointer, it aims at the measured center of its target (getBoundingClientRect), never at fixed pixel coordinates; if the component is scaled, divide by the scale. - Blur only in the middle of a movement and always end at blur(0). - With prefers-reduced-motion, jump to the final frame and stop (tl.progress(1).pause()). - In React, use useGSAP from @gsap/react with a scope ref, so the timeline is cleaned up on unmount. - All example content stays generic (no real brands, logos or people). - With reduced motion, stop on the first question already answered. 5. Check: Run it and watch the first and the third loop (they must look the same). Check it at 390 px wide with no sideways scroll, with reduced motion turned on, and with a clean console. Tell me what you checked. 6. Video (optional): If I also want this as an MP4 (ads, stories, WhatsApp status), install the HyperFrames skills with `npx skills add heygen-com/hyperframes` (choose your agent) and render the same animation in 9:16, 1:1 or 16:9. Rendering needs FFmpeg installed, or render with --docker (downloads about 3.3 GB the first time). Ask me before installing. Shortcut: If I only want the ready-made component instead, it installs with `npx shadcn@latest add https://motionshelf-pi.vercel.app/r/question-typer.json`.
Install
npx shadcn@latest add https://motionshelf-pi.vercel.app/r/question-typer.jsonCopies the file into your project. Requires React 19, Tailwind CSS v4 and GSAP (installed as a dependency).
Props
| Name | Type | Default | Description |
|---|---|---|---|
| items | { question, answer }[] | three example pairs | Each question is typed out, then its answer appears under it. |
| answerLabel | string | "Answer" | Label above the answer. |
| accent | string | "#1f5bff" | Accent of the bar and the answer mark. |
| loop | boolean | true | Replay forever with a pause between runs. |
| className | string | "" | Extra classes for the outer element. |
Dependencies
- gsap
- @gsap/react