Impeccable

Coffee FAQ

Questions that open one at a time, with a chat box at the end that types a reply to anything. Use it near the bottom of a landing or pricing page.

FAQ sectionNo extra packagesLight + darkMobile
Frequently asked questions

Questions about Impeccable UI

Everything people ask before they install their first piece. Can't find yours? Ask it at the bottom.

  • Me, Vraj. I'm a designer who wanted pieces that feel made for your product. Every item is designed, checked and polished here before it ships.

  • A free library of animated React components, sections and page effects. Each one comes with its code and two prompts, so it fits your product instead of looking borrowed from another site.

  • Yes. Everything is under the MIT license, so you can use it in personal, client and commercial work. A credit is always nice, never required.

  • Copy the install command on its page (npm, pnpm, yarn or bun), or paste its Install prompt into your AI coding tool. Either way you get one file in your components folder.

  • Install adds the piece exactly as you see it here and only asks where it goes. Blend asks a few short questions first, then fits the colors, words and timing to your brand.

  • Yes. Every piece takes its colors from your theme, so it follows light and dark mode on its own, and each one is checked at phone, tablet and desktop sizes.

  • Still have a question?

    Ask it here. I usually reply in a second or two.

npx shadcn@latest add https://impeccableui.vercel.app/r/coffee-faq.json
Open any question, then type anything in the box at the bottom and press Enter. The dots type for about a second and a half, then I reply. My answer never changes, because there's no AI behind it, only an honest designer. More FAQ sections live in FAQ sections.

Run it in a project set up with shadcn. No other packages needed. Or open and copy the file into components/ui/coffee-faq.tsx.

Prompts

Paste one into Claude Code, Cursor or any AI coding tool. Install adds this exact section and asks only which page it goes on. Blend asks four short questions (where, your questions, what the chat answers and its face), then fits it to your product without changing the design.

# Coffee FAQ

A 1-file React section from Impeccable. Add it to this project so it works and looks exactly like the source below, in the one place I choose, and change nothing else.

An FAQ section: question rows that open one at a time, and a chat box at the end where your question becomes a new row, three dots type for a moment, then a reply writes itself in.

## Before you build: one question

Look through this project first: its pages and their sections (is there a landing, pricing or help page, and a footer?), and any FAQ content it already has. Then ask me this in one message and wait for my answer:

- **Which page should it go on, and between which sections?** Suggest the 1–3 best places from my pages (an FAQ usually sits near the end of a landing or pricing page, just above the footer or final call to action).
  *Why: it is a whole block of a page, so it needs one clear spot, and near the end is where visitors look for answers before they decide.*

Ask nothing else. If I say *skip*, use the best suggestion.

## Keep it as it is

The section is the design: the rows that open one at a time like a drawer, the chat box drawn as the last row, a question becoming a new open row that replaces the one asked before, the three typing dots and the reply arriving word by word. Keep them exactly as in the source. If something doesn't fit my project, tell me instead of changing it.

- Add only the section file and the one place I picked. If the project already has FAQ text, pass it in `items`; if not, keep the default questions (they are about Impeccable UI) and tell me they need replacing. Keep the default reply. Don't add packages, change other files, or restyle anything.
- Don't add the demo parts from the Impeccable website: the preview frame, its size buttons and fullscreen, and the hint text under it.

## Fastest path

If this project has a `components.json` (shadcn), run `npx shadcn@latest add https://impeccableui.vercel.app/r/coffee-faq.json`.
If the command succeeds, only fix import paths to match this project and skip ahead. If it fails or there is no `components.json`, build it by hand as below.

## Build it

- Stack: React 18 or 19 with TypeScript. No other packages: the icons are inline SVG and every animation is CSS.
- JavaScript project? Name the file `coffee-faq.jsx` and remove the type annotations; nothing else changes.
- Create this file, in this project's usual place for components:
  - `components/ui/coffee-faq.tsx`
- Keep these exports and their names: `CoffeeFaq`, `CoffeeFaqProps`, `CoffeeFaqItem`, `CoffeeFaqLabels`, `COFFEE_FAQ_ITEMS`.
- Keep `"use client"` at the top in Next.js App Router projects. In other setups it is harmless. A page that renders it can stay a server component; only the section itself is client code.
- Keep the CSS block and the tuning values at the top (`EASE`, `OPEN_EASE`, `OPEN_MS`, `REPLY_MS`, `JITTER_MS`, `WORD_STAGGER_MS`, `MAX_QUESTION`) exactly as written. They are the design: a 640px column, 56px rows 12px apart, rows that open in 420ms like a drawer, dots that type for 1.5 seconds give or take 250ms, reply words 45ms apart, and questions up to 280 characters.
- Keep the colors as theme variables: everything reads `--foreground` and `--background` (or `--fg` and `--bg`), and the corners read `--radius-lg`. Never swap them for fixed hex or pixel values.
- Keep the fallbacks: with `prefers-reduced-motion: reduce` rows open at once, nothing slides or blurs, the dots stand still (the wait stays) and the reply shows whole; every row is a real button with `aria-expanded` that Tab, Enter and Space reach; Enter in the box sends; each reply is read out by screen readers; the box's text is 16px so phones don't zoom in.

## Use it

```tsx
// app/pricing/page.tsx (the page I picked)
import { CoffeeFaq } from "@/components/ui/coffee-faq";

export default function PricingPage() {
  return (
    <main>
      {/* ...my existing sections... */}
      <CoffeeFaq />
      {/* ...my footer... */}
    </main>
  );
}
```

- Put it between the two sections I picked, full width. It paints the page background and pads itself (96px top and bottom, 64px on narrow screens), so don't wrap it in extra padding.
- `items` takes `{ question, answer }` objects; an answer can be text or markup with links.
- With no `onAsk`, nothing leaves the page: every question gets `reply` after the dots.

## Check

- It type-checks and the page renders with no console errors.
- Clicking a question opens its answer in under half a second and closes any other open row; clicking it again closes it. Typing a question and pressing Enter adds it as a new open row above the box (replacing any question I asked before, so only one stays), three dots type for about 1.5 seconds, then "My credits are over. Buy me a coffee." writes itself in word by word. The arrow does nothing while the box is empty or the dots are typing.
- It looks right in light and dark mode (check both): faint rows with a thin edge, the open row lifted in the page color, a solid send arrow in the text color.
- It works with a finger on a phone at 375px wide: nothing scrolls sideways, long questions wrap, the box doesn't zoom in when tapped and the keyboard's Send key sends.
- With `prefers-reduced-motion: reduce`, rows open at once, the dots stand still for the same wait, and the reply shows whole.
- Nothing else on the site looks or behaves differently.
- Finish with a short report: the files you added or changed, where it's placed, and every place where you had to do something differently from the source, and why.

## Source

The reference implementation. Copy it as-is, then apply only the changes listed above.

### `components/ui/coffee-faq.tsx`

```tsx
"use client";

/**
 * Coffee FAQ, from Impeccable.
 *
 * A centred FAQ section: a small label, a title, a line under it, then a stack
 * of question rows that open one at a time to show their answer. The last row
 * is a chat box in the same style: type any question and press Enter or the
 * arrow. Your question becomes a new open row above the box, three dots "type"
 * for about a second and a half, then the reply writes itself in, word by word.
 * Only your latest question stays: asking again folds the one before away.
 *
 *   - With no `onAsk`, every question gets the same reply (by default:
 *     "My credits are over. Buy me a coffee."). No AI and no network.
 *   - Give it `onAsk` and return a string (or a promise of one) to answer for
 *     real. The dots stay for at least `replyDelay` either way.
 *   - One question at a time: the arrow waits until the reply is in.
 *
 * No packages. Colors come from the page's own theme variables
 * (--foreground / --background, else --fg / --bg), so it follows light and dark mode.
 */

import { useEffect, useId, useRef, useState, type CSSProperties, type FormEvent, type ReactNode } from "react";

export type CoffeeFaqItem = {
  question: string;
  /** Plain text or your own markup (paragraphs, links). */
  answer: ReactNode;
};

export type CoffeeFaqProps = {
  /** The small pill above the title. Pass null to hide it. */
  eyebrow?: ReactNode;
  title?: ReactNode;
  /** The line under the title. Pass null to hide it. */
  description?: ReactNode;
  /** The questions and answers, top to bottom. */
  items?: CoffeeFaqItem[];
  /** Which row starts open (0 is the first). Leave out to start with all closed. */
  defaultOpen?: number;
  /** Show the chat box under the questions. */
  chat?: boolean;
  chatTitle?: ReactNode;
  chatDescription?: ReactNode;
  /** The face next to the replies and in the chat box, about 40px round. Defaults to the Impeccable mark. */
  avatar?: ReactNode;
  /** What every question gets back when there is no onAsk (or onAsk returns nothing). */
  reply?: string;
  /** How long the dots type before the reply shows, in ms (300 to 10000). A little is added or taken at random so it feels human. */
  replyDelay?: number;
  /** Called with each question. Return a string, or a promise of one, to answer with it. */
  onAsk?: (question: string) => string | void | Promise<string | void>;
  /** All the short texts. Pass only the ones you want to change. */
  labels?: Partial<CoffeeFaqLabels>;
  className?: string;
  style?: CSSProperties;
};

export type CoffeeFaqLabels = {
  /** The input's placeholder (and its label for screen readers). */
  placeholder: string;
  send: string;
  /** The tag on rows you asked. */
  you: string;
  /** Read out while the dots type. */
  typing: string;
  /** The reply when onAsk throws or its promise fails. */
  error: string;
};

const DEFAULT_LABELS: CoffeeFaqLabels = {
  placeholder: "Ask your own question",
  send: "Send",
  you: "You",
  typing: "Typing",
  error: "Something went wrong on my side. Try again in a moment.",
};

export const COFFEE_FAQ_ITEMS: CoffeeFaqItem[] = [
  {
    question: "Who makes it?",
    answer:
      "Me, Vraj. I'm a designer who wanted pieces that feel made for your product. Every item is designed, checked and polished here before it ships.",
  },
  {
    question: "What is Impeccable UI?",
    answer:
      "A free library of animated React components, sections and page effects. Each one comes with its code and two prompts, so it fits your product instead of looking borrowed from another site.",
  },
  {
    question: "Can I use it in client and paid projects?",
    answer:
      "Yes. Everything is under the MIT license, so you can use it in personal, client and commercial work. A credit is always nice, never required.",
  },
  {
    question: "How do I add something to my project?",
    answer:
      "Copy the install command on its page (npm, pnpm, yarn or bun), or paste its Install prompt into your AI coding tool. Either way you get one file in your components folder.",
  },
  {
    question: "What is the difference between Install and Blend?",
    answer:
      "Install adds the piece exactly as you see it here and only asks where it goes. Blend asks a few short questions first, then fits the colors, words and timing to your brand.",
  },
  {
    question: "Does it work in dark mode and on phones?",
    answer:
      "Yes. Every piece takes its colors from your theme, so it follows light and dark mode on its own, and each one is checked at phone, tablet and desktop sizes.",
  },
];

/* ---------- the design: keep as written ---------- */

const EASE = "cubic-bezier(.23,1,.32,1)"; // fast start, soft landing
const OPEN_EASE = "cubic-bezier(.32,.72,0,1)"; // rows opening and closing, like a drawer
const OPEN_MS = 420; // a row opening or closing
const REPLY_MS = 1500; // the dots type for this long by default...
const JITTER_MS = 250; // ...give or take this much, at random
const WORD_STAGGER_MS = 45; // between each word of the reply
const MAX_QUESTION = 280; // characters you can type

const CSS = `
.icf {
  --icf-fg: var(--foreground, var(--fg, CanvasText));
  --icf-bg: var(--background, var(--bg, Canvas));
  --icf-radius: var(--radius-lg, 8px);
  --icf-row: color-mix(in oklab, var(--icf-fg) 2.5%, var(--icf-bg));
  --icf-row-hover: color-mix(in oklab, var(--icf-fg) 4.5%, var(--icf-bg));
  --icf-line: color-mix(in oklab, var(--icf-fg) 9%, transparent);
  --icf-muted: color-mix(in oklab, var(--icf-fg) 62%, var(--icf-bg));
  --icf-faint: color-mix(in oklab, var(--icf-fg) 40%, var(--icf-bg));
  --icf-ring: color-mix(in oklab, var(--icf-fg) 35%, transparent);
  --icf-shadow: 0 1px 2px color-mix(in oklab, var(--icf-fg) 4%, transparent);
  --icf-lift: 0 1px 2px color-mix(in oklab, var(--icf-fg) 5%, transparent), 0 6px 16px -6px color-mix(in oklab, var(--icf-fg) 10%, transparent);
  container-type: inline-size;
  position: relative; box-sizing: border-box; width: 100%;
  color: var(--icf-fg); background: var(--icf-bg); font-family: inherit; -webkit-font-smoothing: antialiased;
}
.icf *, .icf *::before, .icf *::after { box-sizing: border-box; }
.icf-in { padding: 96px 24px; }
.icf-col { width: 100%; max-width: 640px; margin: 0 auto; }
.icf-head { text-align: center; }
.icf-eyebrow {
  display: inline-flex; align-items: center; height: 28px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--icf-line); background: var(--icf-row); box-shadow: var(--icf-shadow);
  font-size: 13px; line-height: 1; font-weight: 500;
}
.icf-title { margin: 16px 0 0; font-size: 40px; line-height: 1.1; font-weight: 600; letter-spacing: -.035em; text-wrap: balance; overflow-wrap: anywhere; }
.icf-desc { margin: 14px auto 0; max-width: 440px; font-size: 17px; line-height: 1.55; color: var(--icf-muted); text-wrap: pretty; overflow-wrap: anywhere; }
.icf-head + .icf-list { margin-top: 48px; }
.icf-list { margin: 0; padding: 0; list-style: none; }
.icf-item { display: grid; grid-template-rows: 1fr; }
.icf-cell { min-height: 0; }
.icf-item + .icf-item > .icf-cell > .icf-row { margin-top: 12px; }
.icf-enter { animation: icf-grow .52s ${EASE} both; }
.icf-enter > .icf-cell, .icf-leave > .icf-cell { overflow: hidden; }
@keyframes icf-grow { from { grid-template-rows: 0fr; opacity: 0; transform: translateY(8px) scale(.985); } }
.icf-leave { animation: icf-shrink .46s ${OPEN_EASE} both; pointer-events: none; }
@keyframes icf-shrink { to { grid-template-rows: 0fr; opacity: 0; transform: translateY(-6px) scale(.985); filter: blur(2px); } }

.icf-row {
  border: 1px solid var(--icf-line); border-radius: var(--icf-radius); background: var(--icf-row); box-shadow: var(--icf-shadow);
  transition: background-color .2s, box-shadow .3s ${EASE}, border-color .2s;
}
@media (hover: hover) { .icf-row:has(> .icf-h .icf-q:hover):not([data-open]) { background: var(--icf-row-hover); } }
.icf-row[data-open] { background: var(--icf-bg); box-shadow: var(--icf-lift); }
.icf-h { margin: 0; font: inherit; }
.icf-q {
  all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px;
  padding: 15px 16px 15px 20px; padding-inline: 20px 16px; border-radius: calc(var(--icf-radius) - 1px);
  font-size: 16px; line-height: 24px; font-weight: 500; text-align: start; cursor: pointer;
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.icf-q:focus-visible { outline: 2px solid var(--icf-ring); outline-offset: -2px; }
.icf-q-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.icf-you {
  flex: none; display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .02em; color: var(--icf-bg); background: var(--icf-fg);
  align-self: flex-start; margin-top: 2px; /* sits on the first line of a long question */
}
.icf-chev { flex: none; width: 20px; height: 20px; color: var(--icf-muted); transition: transform ${OPEN_MS}ms ${OPEN_EASE}, color .2s; }
.icf-row[data-open] .icf-chev { transform: rotate(180deg); color: var(--icf-fg); }

.icf-a { display: grid; grid-template-rows: 0fr; transition: grid-template-rows ${OPEN_MS}ms ${OPEN_EASE}; }
.icf-row[data-open] > .icf-a { grid-template-rows: 1fr; }
.icf-a-clip { min-height: 0; overflow: hidden; visibility: hidden; transition: visibility 0s ${OPEN_MS}ms; }
.icf-row[data-open] > .icf-a > .icf-a-clip { visibility: visible; transition-delay: 0s; }
.icf-a-body {
  padding: 0 52px 18px 20px; padding-inline: 20px 52px; font-size: 15px; line-height: 24px; color: var(--icf-muted);
  overflow-wrap: anywhere; opacity: 0; transform: translateY(-6px); filter: blur(3px);
  transition: opacity .16s, transform .3s ${EASE}, filter .16s;
}
.icf-row[data-open] .icf-a-body { opacity: 1; transform: none; filter: none; transition: opacity .32s .07s, transform .46s ${EASE} .05s, filter .32s .07s; }
.icf-a-body > p { margin: 0; }
.icf-a-body > p + p { margin-top: 10px; }
.icf-a-body a { color: var(--icf-fg); text-underline-offset: 3px; }

.icf-said { display: flex; align-items: flex-start; gap: 10px; }
.icf-face { flex: none; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 999px; overflow: hidden; background: var(--icf-fg); color: var(--icf-bg); }
.icf-face > svg { width: 46%; height: auto; }
.icf-face > img { width: 100%; height: 100%; object-fit: cover; }
.icf-reply { position: relative; flex: 1; min-width: 0; min-height: 24px; color: color-mix(in oklab, var(--icf-fg) 82%, var(--icf-bg)); }
.icf-dots { position: absolute; inset-block-start: 0; inset-inline-start: 0; display: flex; align-items: center; gap: 4px; height: 24px; color: var(--icf-fg); transition: opacity .2s, filter .2s; }
.icf-dots > i { width: 6px; height: 6px; border-radius: 999px; background: currentColor; opacity: .3; animation: icf-dot 1.2s ease-in-out infinite; }
.icf-dots > i:nth-child(2) { animation-delay: .15s; }
.icf-dots > i:nth-child(3) { animation-delay: .3s; }
@keyframes icf-dot { 0%, 60%, 100% { transform: none; opacity: .3; } 30% { transform: translateY(-3px); opacity: .9; } }
.icf-said[data-done] .icf-dots { opacity: 0; filter: blur(2px); }
.icf-w { display: inline-block; opacity: 0; }
.icf-said[data-done] .icf-w { animation: icf-word .5s ${EASE} both; animation-delay: calc(var(--i) * ${WORD_STAGGER_MS}ms + 80ms); }
@keyframes icf-word { from { opacity: 0; transform: translateY(4px); filter: blur(4px); } to { opacity: 1; transform: none; filter: none; } }

.icf-chat:focus-within { border-color: color-mix(in oklab, var(--icf-fg) 22%, transparent); box-shadow: var(--icf-lift), 0 0 0 3px color-mix(in oklab, var(--icf-fg) 6%, transparent); }
.icf-chat-head { display: flex; align-items: center; gap: 14px; padding: 18px 20px; }
.icf-chat-head .icf-face { width: 40px; height: 40px; }
.icf-chat-text { min-width: 0; }
.icf-chat-title { margin: 0; font-size: 16px; line-height: 24px; font-weight: 600; overflow-wrap: anywhere; }
.icf-chat-sub { margin: 2px 0 0; font-size: 14px; line-height: 20px; color: var(--icf-muted); overflow-wrap: anywhere; }
.icf-compose {
  position: relative; display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 9px 8px 20px; padding-inline: 20px 9px;
  border-top: 1px solid var(--icf-line); border-radius: 0 0 calc(var(--icf-radius) - 1px) calc(var(--icf-radius) - 1px); background: var(--icf-bg);
}
.icf-input {
  all: unset; box-sizing: border-box; flex: 1; min-width: 0; height: 40px; font: inherit; font-size: 16px; line-height: 24px; color: var(--icf-fg);
  caret-color: var(--icf-fg); transition: opacity .15s;
}
.icf-input::placeholder { color: var(--icf-faint); opacity: 1; }
.icf-input[data-hide] { opacity: 0; transition: none; }
.icf-ghost {
  position: absolute; inset-inline: 20px 60px; top: 50%; margin-top: -12px; height: 24px; font-size: 16px; line-height: 24px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; animation: icf-ghost .42s ${EASE} forwards;
}
@keyframes icf-ghost { to { opacity: 0; transform: translateY(-14px); filter: blur(3px); } }
.icf-send {
  all: unset; box-sizing: border-box; flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 999px;
  background: var(--icf-fg); color: var(--icf-bg); cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: transform .16s ${EASE}, background-color .2s, color .2s;
}
.icf-send:active:not([aria-disabled="true"]) { transform: scale(.92); }
.icf-send:focus-visible { outline: 2px solid var(--icf-ring); outline-offset: 2px; }
.icf-send[aria-disabled="true"] { cursor: default; background: color-mix(in oklab, var(--icf-fg) 8%, transparent); color: var(--icf-faint); }
.icf-send > svg { width: 18px; height: 18px; transition: transform .3s ${EASE}; }
@media (hover: hover) { .icf-send:not([aria-disabled="true"]):hover > svg { transform: translateY(-1px); } }
.icf-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

@container (max-width: 560px) {
  .icf-in { padding: 64px 16px; }
  .icf-title { font-size: 30px; }
  .icf-desc { font-size: 16px; }
  .icf-head + .icf-list { margin-top: 36px; }
  .icf-q { font-size: 15px; padding-inline: 16px 12px; }
  .icf-a-body { padding-inline: 16px 16px; }
  .icf-chat-head { padding: 16px; }
  .icf-compose { padding-inline-start: 16px; }
  .icf-ghost { inset-inline-start: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .icf *, .icf *::before, .icf *::after { transition-duration: 0s !important; transition-delay: 0s !important; animation: none !important; }
  .icf-said[data-done] .icf-w { opacity: 1; }
  .icf-dots > i { opacity: .6; }
  .icf-ghost { display: none; }
  .icf-enter > .icf-cell { overflow: visible; }
}
`;

/** The Impeccable mark: a pointy-top hexagon with three stripes cut across its top right. */
function DefaultAvatar() {
  const id = useId().replace(/:/g, "");
  return (
    <svg viewBox="0 0 69 80" aria-hidden="true">
      <defs>
        <mask id={`icf-cut-${id}`} maskUnits="userSpaceOnUse" x="0" y="0" width="69" height="80">
          <path d="M34.5 0 69 20v40L34.5 80 0 60V20z" fill="#fff" />
          <path d="M0-11.5 69 28.5M0-6 69 34M0-.5 69 39.5" stroke="#000" strokeWidth="4" />
        </mask>
      </defs>
      <path d="M34.5 0 69 20v40L34.5 80 0 60V20z" fill="currentColor" mask={`url(#icf-cut-${id})`} />
    </svg>
  );
}

function Chevron() {
  return (
    <svg className="icf-chev" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
      <path d="M18 9s-4.42 6-6 6-6-6-6-6" />
    </svg>
  );
}

function ArrowUp() {
  return (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
      <path d="M12 20V4M6 10s4.42-6 6-6 6 6 6 6" />
    </svg>
  );
}

type Asked = { id: string; question: string; reply: string | null; fresh: boolean; leaving?: boolean };

/** The reply, one span per word so the words can arrive one after another. */
function Words({ text }: { text: string }) {
  const words = text.split(/\s+/).filter(Boolean);
  return (
    <>
      {words.map((w, i) => (
        <span key={i}>
          <span className="icf-w" style={{ "--i": i } as CSSProperties}>
            {w}
          </span>
          {i < words.length - 1 ? " " : null}
        </span>
      ))}
    </>
  );
}

export function CoffeeFaq({
  eyebrow = "Frequently asked questions",
  title = "Questions about Impeccable UI",
  description = "Everything people ask before they install their first piece. Can't find yours? Ask it at the bottom.",
  items = COFFEE_FAQ_ITEMS,
  defaultOpen,
  chat = true,
  chatTitle = "Still have a question?",
  chatDescription = "Ask it here. I usually reply in a second or two.",
  avatar,
  reply = "My credits are over. Buy me a coffee.",
  replyDelay = REPLY_MS,
  onAsk,
  labels: labelOverrides,
  className,
  style,
}: CoffeeFaqProps) {
  const t = { ...DEFAULT_LABELS, ...labelOverrides };
  const uid = useId().replace(/:/g, "");
  const rowId = (i: number) => `icf-${uid}-q${i}`;
  const [open, setOpen] = useState<string | null>(
    typeof defaultOpen === "number" && defaultOpen >= 0 && defaultOpen < items.length ? rowId(defaultOpen) : null,
  );
  const [asked, setAsked] = useState<Asked[]>([]);
  const [text, setText] = useState("");
  const [busy, setBusy] = useState(false);
  const [ghost, setGhost] = useState<{ key: number; text: string } | null>(null);
  const [said, setSaid] = useState(""); // read out once a reply is in
  const count = useRef(0);
  const timers = useRef(new Set<number>());
  const alive = useRef(true);
  const composeRef = useRef<HTMLFormElement>(null);
  const inputRef = useRef<HTMLInputElement>(null);

  // Stop every timer when the section goes away, so nothing updates a gone component.
  useEffect(() => {
    alive.current = true;
    const live = timers.current;
    return () => {
      alive.current = false;
      live.forEach((id) => window.clearTimeout(id));
      live.clear();
    };
  }, []);

  const later = (fn: () => void, ms: number) => {
    const id = window.setTimeout(() => {
      timers.current.delete(id);
      if (alive.current) fn();
    }, ms);
    timers.current.add(id);
  };

  const toggle = (id: string) => setOpen((now) => (now === id ? null : id));

  const send = (e: FormEvent) => {
    e.preventDefault();
    const question = text.trim();
    if (!question || busy) return;
    const n = ++count.current;
    const id = `icf-${uid}-a${n}`;
    // Only the latest question stays, so the section never grows: the one before folds
    // away while the new one grows in its place (at once with reduced motion).
    const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
    setAsked((list) => [
      ...(reduce ? [] : list.map((a) => ({ ...a, leaving: true }))),
      { id, question, reply: null, fresh: true },
    ]);
    if (!reduce) later(() => setAsked((list) => list.filter((a) => !a.leaving)), 520);
    setOpen(id);
    setText("");
    setBusy(true);
    setSaid("");
    setGhost({ key: n, text: question });
    later(() => setGhost((g) => (g && g.key === n ? null : g)), 450);

    // Keep the box in view once the new row has pushed it down.
    later(() => composeRef.current?.scrollIntoView({ block: "nearest", behavior: reduce ? "auto" : "smooth" }), reduce ? 0 : 560);

    const base = Math.min(10000, Math.max(300, Number.isFinite(replyDelay) ? replyDelay : REPLY_MS));
    const wait = Math.max(300, base + (Math.random() * 2 - 1) * JITTER_MS);
    const start = Date.now();
    Promise.resolve()
      .then(() => onAsk?.(question))
      .then(
        (answer) => (typeof answer === "string" && answer.trim() ? answer.trim() : reply),
        (err) => {
          console.error(err);
          return t.error;
        },
      )
      .then((answer) => {
        later(() => {
          setAsked((list) => list.map((a) => (a.id === id ? { ...a, reply: answer } : a)));
          setBusy(false);
          setSaid(answer);
        }, Math.max(0, wait - (Date.now() - start)));
      });
  };

  const empty = !text.trim();

  return (
    <section className={className ? `icf ${className}` : "icf"} style={style}>
      <style>{CSS}</style>
      <div className="icf-in">
        <div className="icf-col">
          {(eyebrow != null || title != null || description != null) && (
            <div className="icf-head">
              {eyebrow != null && <span className="icf-eyebrow">{eyebrow}</span>}
              {title != null && <h2 className="icf-title">{title}</h2>}
              {description != null && <p className="icf-desc">{description}</p>}
            </div>
          )}

          <ul className="icf-list">
            {items.map((item, i) => {
              const id = rowId(i);
              const isOpen = open === id;
              return (
                <li key={id} className="icf-item">
                  <div className="icf-cell">
                  <div className="icf-row" data-open={isOpen || undefined}>
                    <h3 className="icf-h">
                      <button type="button" id={`${id}-btn`} className="icf-q" aria-expanded={isOpen} aria-controls={`${id}-panel`} onClick={() => toggle(id)}>
                        <span className="icf-q-text">{item.question}</span>
                        <Chevron />
                      </button>
                    </h3>
                    <div className="icf-a">
                      <div className="icf-a-clip">
                        <div id={`${id}-panel`} role="region" aria-labelledby={`${id}-btn`} className="icf-a-body">
                          {typeof item.answer === "string" ? <p>{item.answer}</p> : item.answer}
                        </div>
                      </div>
                    </div>
                  </div>
                  </div>
                </li>
              );
            })}

            {asked.map((a) => {
              const isOpen = open === a.id;
              const done = a.reply !== null;
              // While the dots type, the default reply is already laid out (hidden) so the row
              // doesn't jump when it arrives. A reply from onAsk isn't known yet, so it gets one line.
              const shown = a.reply ?? (onAsk ? "" : reply);
              return (
                <li
                  key={a.id}
                  className={a.leaving ? "icf-item icf-leave" : a.fresh ? "icf-item icf-enter" : "icf-item"}
                  aria-hidden={a.leaving || undefined}
                  onAnimationEnd={(e) => {
                    // Once it has grown in, stop clipping so its shadow shows.
                    if (e.target === e.currentTarget && !a.leaving)
                      setAsked((list) => list.map((x) => (x.id === a.id ? { ...x, fresh: false } : x)));
                  }}
                >
                  <div className="icf-cell">
                    <div className="icf-row" data-open={isOpen || undefined}>
                      <h3 className="icf-h">
                        <button type="button" id={`${a.id}-btn`} className="icf-q" aria-expanded={isOpen} aria-controls={`${a.id}-panel`} onClick={() => toggle(a.id)}>
                          <span className="icf-you">{t.you}</span>
                          <span className="icf-q-text">{a.question}</span>
                          <Chevron />
                        </button>
                      </h3>
                      <div className="icf-a">
                        <div className="icf-a-clip">
                          <div id={`${a.id}-panel`} role="region" aria-labelledby={`${a.id}-btn`} className="icf-a-body">
                            <div className="icf-said" data-done={done || undefined}>
                              <span className="icf-face" aria-hidden="true">
                                {avatar ?? <DefaultAvatar />}
                              </span>
                              <div className="icf-reply">
                                <span className="icf-dots" aria-hidden="true">
                                  <i />
                                  <i />
                                  <i />
                                </span>
                                {done ? <Words text={shown} /> : <span aria-hidden="true">{shown ? <Words text={shown} /> : null}</span>}
                                {!done && <span className="icf-sr">{t.typing}</span>}
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </li>
              );
            })}

            {chat && (
              <li className="icf-item">
                <div className="icf-cell">
                <div className="icf-row icf-chat">
                  <div className="icf-chat-head">
                    <span className="icf-face" aria-hidden="true">
                      {avatar ?? <DefaultAvatar />}
                    </span>
                    <div className="icf-chat-text">
                      {chatTitle != null && <p className="icf-chat-title">{chatTitle}</p>}
                      {chatDescription != null && <p className="icf-chat-sub">{chatDescription}</p>}
                    </div>
                  </div>
                  <form ref={composeRef} className="icf-compose" onSubmit={send}>
                    <label className="icf-sr" htmlFor={`icf-${uid}-input`}>
                      {t.placeholder}
                    </label>
                    <input
                      ref={inputRef}
                      id={`icf-${uid}-input`}
                      className="icf-input"
                      type="text"
                      name="question"
                      autoComplete="off"
                      enterKeyHint="send"
                      maxLength={MAX_QUESTION}
                      placeholder={t.placeholder}
                      value={text}
                      data-hide={ghost && !text ? "" : undefined}
                      onChange={(e) => setText(e.target.value)}
                    />
                    {ghost && (
                      <span key={ghost.key} className="icf-ghost" aria-hidden="true">
                        {ghost.text}
                      </span>
                    )}
                    <button type="submit" className="icf-send" aria-label={t.send} aria-disabled={empty || busy || undefined}>
                      <ArrowUp />
                    </button>
                  </form>
                </div>
                </div>
              </li>
            )}
          </ul>
          <p className="icf-sr" aria-live="polite">
            {said}
          </p>
        </div>
      </div>
    </section>
  );
}
```

Usage

Put it near the end of a page and give it your own questions.

import { CoffeeFaq } from "@/components/ui/coffee-faq";

const FAQS = [
  { question: "How long is the free trial?", answer: "14 days, no card needed." },
  { question: "Can I cancel any time?", answer: "Yes, from Settings, in one click." },
  { question: "Do you offer refunds?", answer: "Within 30 days, no questions asked." },
];

export function Faq() {
  return (
    <CoffeeFaq
      title="Questions about Acme"
      description="Can't find yours? Ask it at the bottom."
      items={FAQS}
      // No onAsk: every question gets the reply below after the dots.
      reply="Thanks! We'll email you an answer within a day."
    />
  );
}

One row is open at a time, and a question you ask becomes a new open row above the box. Asking again replaces it, so only your latest question stays and the section never keeps growing. With no onAsk, nothing leaves the page: every question gets reply. To answer for real later, return the answer from onAsk. Colors come from your theme: it reads --foreground and --background (or --fg and --bg) and --radius-lg for the corners, so it follows light and dark mode on its own. It pairs well with Hex Login, drawn from the same colors.

Props

PropDefaultWhat it does
items6 questions about Impeccable UIThe rows, top to bottom: { question, answer }. An answer can be text or your own markup with links.
eyebrow"Frequently asked questions"The small pill above the title. null hides it.
title"Questions about Impeccable UI"The big line.
descriptiona short lineThe line under the title. null hides it.
defaultOpen—Which row starts open (0 is the first). Leave it out to start with all closed.
chattrueShow the chat box under the questions.
chatTitle / chatDescription"Still have a question?"The two lines in the chat box.
avatarImpeccable markThe round face in the chat box and next to every reply. An <img> fills it.
reply"My credits are over. Buy me a coffee."What every question gets back when there is no onAsk.
replyDelay1500How long the dots type, in ms (300 to 10000), give or take 250ms so it feels human.
onAsk—Called with each question. Return a string, or a promise of one, to answer with it. The dots stay for at least replyDelay.
labels—Any of the short texts: placeholder, send, you, typing, error.
className / style—On the section itself. It fills its width and centres a 640px column.