# Question card (Notchset): prompt.md (v1.1.0)

- id: `question-card` · version 1.1.0 · component · free
- category: AI
- build: one set of files for every shadcn style
- install: `npx shadcn@latest add https://notchset.dev/r/question-card.json`
- npm dependencies: lucide-react@^1
- registry dependencies: utils, https://notchset.dev/r/notchset-foundation.json, @notchset/button, @notchset/radio-group, @notchset/status-glyph-run, @notchset/stream-adapters, @notchset/text-field
- docs: https://notchset.dev/components/question-card
- The install command carries everything this item needs (files, CSS, tokens, npm and registry dependencies). Prefer it to copying source by hand.

An agent asks in the run's own place and waits: a choice among a few, a short form from a flat schema, or a link to sign in. Accept is worded for the job, beside Decline and, with its handler, Cancel run. Answered it folds to one line with Change and focus moves there; declining ends the step, not the run..

## Build it
- Stack: React 18.3 or 19, TypeScript, Tailwind CSS v4 utility classes on the foundation's roles, a components.json (imports use its aliases).
- Packages: `lucide-react@^1` beyond `react` and `react-dom`.
- Files: `components/ui/notchset/question-card.tsx`; shared code: `lib/notchset/feedback.ts`, `lib/notchset/icons.ts`, `lib/notchset/words.ts`.
- Registry dependencies, installed with it automatically: shadcn `utils` (cn), `notchset-foundation`, `button`, `radio-group`, `status-glyph-run`, `stream-adapters`, `text-field`.
- Builds: one set of files, the same for every shadcn style.
- Exports to keep: `QUESTION_CARD_LABELS`, `QuestionCard`, and every exported type.
- CSS: the install adds the notchset foundation (its roles, keyframes and motion switch, reading your shadcn tokens for colour) to your global stylesheet once. Nothing to import by hand.
- Re-running `add` (or `--overwrite`) re-applies those rules: put overrides in your own CSS, never in the installed rules.
- Colours: every part reads the foundation's roles (`--ns-canvas`, `--ns-ink`, `--ns-line`, `--ns-signal` …), which read your shadcn tokens (`--background`, `--foreground`, `--border`, `--destructive` …), plus the optional `--success` and `--warning`. Retheme on `:root` or any container; never add Tailwind colour classes inside the component.
- This item reads `--ns-bezel`, `--ns-ease`, `--ns-ease-panel`, `--ns-ink`, `--ns-ink-2`, `--ns-ink-3`, `--ns-radius`, `--ns-radius-full`, `--ns-radius-lg`, `--ns-radius-xl`, `--ns-raised`, `--ns-signal`, `--ns-text-body`, `--ns-text-small`, `--ns-time-panel`, `--ns-warn`, `--ns-warn-ink`, `--ns-weight-medium`, `--ns-well`.
- Retune it (on any ancestor) with the foundation's roles and hooks: `--ns-agent-b`, `--ns-agent-c`, `--ns-agent-d`, `--ns-agent-drift`, `--ns-agent-fill`, `--ns-agent-h1`, `--ns-agent-h2`, `--ns-agent-h3`, `--ns-agent-shift`, `--ns-avatar-card`, `--ns-avatar-lg`, `--ns-avatar-md`, `--ns-avatar-sm`, `--ns-avatar-xs`, `--ns-bad`, `--ns-bad-ink`, `--ns-band`, `--ns-band-edge`, `--ns-band-grade`, `--ns-band-optimal`, `--ns-banner-beat`, `--ns-banner-radius`, `--ns-beat`, `--ns-beat-ease`, `--ns-bezel`, `--ns-bloom-close`, `--ns-bloom-open`, `--ns-bloom-rise`, `--ns-btn-bad`, `--ns-btn-bad-hover`, `--ns-btn-bad-line`, `--ns-btn-bezel`, `--ns-btn-chosen`, `--ns-btn-gone`, `--ns-btn-morph`, `--ns-btn-ok`, `--ns-btn-press`, `--ns-btn-release`, `--ns-btn-result`, `--ns-btn-roll`, `--ns-btn-stagger`, `--ns-btn-stagger-step`, `--ns-btn-tick`, `--ns-btn-tonal`, `--ns-btn-tonal-edge`, `--ns-btn-tonal-hover`, `--ns-bulk-clear`, `--ns-button`, `--ns-button-field-inset`, `--ns-button-lg`, `--ns-button-sm`, `--ns-canvas`, `--ns-card-tilt`, `--ns-cat-1`, `--ns-cat-2`, `--ns-cat-3`, `--ns-cat-4`, `--ns-cat-5`, `--ns-cat-6`, `--ns-check`, `--ns-check-round`, `--ns-cheer-1`, `--ns-cheer-2`, `--ns-cheer-3`, `--ns-cheer-edge`, `--ns-cheer-fold`, `--ns-cheer-glow`, `--ns-cheer-lift`, `--ns-chip`, `--ns-chip-pick`, `--ns-control`, `--ns-control-lg`, `--ns-control-pad`, `--ns-control-sm`, `--ns-corner`, `--ns-danger`, `--ns-deep`, `--ns-deep-ink`, `--ns-deep-ink-2`, `--ns-deep-line`, `--ns-depth-card`, `--ns-depth-lift`, `--ns-depth-surface`, `--ns-dialog`, `--ns-dialog-grow`, `--ns-dialog-lg`, `--ns-dialog-max`, `--ns-dialog-shrink`, `--ns-dialog-sm`, `--ns-dialog-top`, `--ns-dock-bottom`, `--ns-drop`, `--ns-ease`, `--ns-ease-arrive`, `--ns-ease-breathe`, `--ns-ease-drum`, `--ns-ease-exit`, `--ns-ease-fling`, `--ns-ease-glide`, `--ns-ease-grow`, `--ns-ease-move`, `--ns-ease-panel`, `--ns-ease-pop`, `--ns-ease-press`, `--ns-ease-spring`, `--ns-ebg-arm`, `--ns-ebg-lit`, `--ns-emoji`, `--ns-emoji-md`, `--ns-emoji-sm`, `--ns-field`, `--ns-field-edge`, `--ns-field-h`, `--ns-fill`, `--ns-fill-time`, `--ns-flood-arc`, `--ns-flood-aurora`, `--ns-flood-behind-1`, `--ns-flood-behind-2`, `--ns-flood-bloom`, `--ns-flood-deep`, `--ns-flood-dial-bloom`, `--ns-flood-glass`, `--ns-flood-grain`, `--ns-flood-image`, `--ns-flood-ink`, `--ns-flood-ink-low`, `--ns-flood-light`, `--ns-flood-mid`, `--ns-flood-pale`, `--ns-flood-pane`, `--ns-flood-pane-edge`, `--ns-flood-pill-ink`, `--ns-flood-ribbon`, `--ns-flood-ribbon-core`, `--ns-flood-shadow`, `--ns-flood-sheen`, `--ns-flood-wash`, `--ns-font-body`, `--ns-font-display`, `--ns-font-mono`, `--ns-font-script`, `--ns-glass`, `--ns-glass-blur`, `--ns-glass-shadow`, `--ns-glow`, `--ns-glyph-pad`, `--ns-grain`, `--ns-gutter`, `--ns-header`, `--ns-help-max`, `--ns-hit`, `--ns-hover`, `--ns-icon`, `--ns-icon-lg`, `--ns-icon-sm`, `--ns-icon-stroke`, `--ns-info`, `--ns-info-ink`, `--ns-ink`, `--ns-ink-2`, `--ns-ink-3`, `--ns-ink-4`, `--ns-layer-bar`, `--ns-layer-modal`, `--ns-layer-panel`, `--ns-layer-popup`, `--ns-layer-sticky`, `--ns-layer-tip`, `--ns-layer-toast`, `--ns-layer-zoom`, `--ns-lead-body`, `--ns-lead-figure`, `--ns-lead-large`, `--ns-lead-meta`, `--ns-lead-small`, `--ns-lead-sub`, `--ns-lead-title`, `--ns-leading`, `--ns-leading-prose`, `--ns-leading-title`, `--ns-lift`, `--ns-light-1`, `--ns-light-2`, `--ns-light-3`, `--ns-light-spread`, `--ns-light-strength`, `--ns-line`, `--ns-line-soft`, `--ns-lit-edge`, `--ns-map-grass`, `--ns-map-water`, `--ns-mark-edge`, `--ns-mark-lifted`, `--ns-mark-rest`, `--ns-mark-swap`, `--ns-marker`, `--ns-marker-ink`, `--ns-mc-place`, `--ns-mc-roll`, `--ns-measure`, `--ns-menu-dy`, `--ns-menu-lit`, `--ns-menu-pad`, `--ns-menu-row`, `--ns-menu-rule`, `--ns-mesh`, `--ns-mesh-frost`, `--ns-nest-inset`, `--ns-nest-outer`, `--ns-nest-r`, `--ns-notch-ease`, `--ns-ok`, `--ns-ok-ink`, `--ns-on-fill`, `--ns-orb-body`, `--ns-orb-cool`, `--ns-orb-core`, `--ns-orb-dawn`, `--ns-orb-deep`, `--ns-orb-edge`, `--ns-orb-grain`, `--ns-orb-ground`, `--ns-orb-halo`, `--ns-orb-inner`, `--ns-orb-key`, `--ns-orb-lift`, `--ns-orb-limb`, `--ns-orb-limb-from`, `--ns-orb-rim`, `--ns-orb-skin-hi`, `--ns-orb-skin-lo`, `--ns-orb-skin-mid`, `--ns-orb-warm`, `--ns-palette-min`, `--ns-panel`, `--ns-panel-room`, `--ns-panel-w`, `--ns-panel-w-lg`, `--ns-pick-slot`, `--ns-pill-prop`, `--ns-play-fill`, `--ns-play-fill-color`, `--ns-play-lift`, `--ns-play-lift-y`, `--ns-play-open`, `--ns-play-open-content`, `--ns-play-press`, `--ns-play-press-box`, `--ns-play-reduced`, `--ns-play-ring`, `--ns-play-roll`, `--ns-play-shake`, `--ns-play-spring`, `--ns-play-swap`, `--ns-play-swap-blur`, `--ns-press-min`, `--ns-press-scale`, `--ns-press-x`, `--ns-press-y`, `--ns-primary-hover`, `--ns-primary-press`, `--ns-prism-edge`, `--ns-prism-glint`, `--ns-prism-sheen`, `--ns-prism-tint`, `--ns-pulse`, `--ns-radius`, `--ns-radius-2xl`, `--ns-radius-button`, `--ns-radius-button-lg`, `--ns-radius-button-sm`, `--ns-radius-card`, `--ns-radius-check`, `--ns-radius-control`, `--ns-radius-control-sm`, `--ns-radius-float`, `--ns-radius-full`, `--ns-radius-lg`, `--ns-radius-mark`, `--ns-radius-menu-row`, `--ns-radius-modal`, `--ns-radius-pill`, `--ns-radius-sm`, `--ns-radius-xl`, `--ns-radius-xs`, `--ns-raised`, `--ns-ramp-1`, `--ns-ramp-2`, `--ns-ramp-3`, `--ns-ramp-4`, `--ns-ramp-5`, `--ns-ramp-shine`, `--ns-range`, `--ns-rest-1`, `--ns-rest-2`, `--ns-rest-3`, `--ns-rise`, `--ns-row`, `--ns-row-compact`, `--ns-row-hue`, `--ns-scrim`, `--ns-search-h`, `--ns-segment`, `--ns-segment-inset`, `--ns-segment-lift`, `--ns-segment-sm`, `--ns-selected`, `--ns-series`, `--ns-series-core`, `--ns-series-glint`, `--ns-series-tint`, `--ns-shadow-dialog`, `--ns-shadow-float`, `--ns-shadow-lift`, `--ns-shadow-panel`, `--ns-sheet`, `--ns-sheet-back`, `--ns-sheet-bottom`, `--ns-sheet-drop`, `--ns-sheet-rise`, `--ns-shift`, `--ns-side`, `--ns-signal`, `--ns-signal-ink`, `--ns-signal-wash`, `--ns-sk-figure`, `--ns-sk-land`, `--ns-sk-p`, `--ns-sk-p0`, `--ns-sk-p1`, `--ns-sk-p2`, `--ns-sk-p3`, `--ns-sk-p4`, `--ns-sk-p5`, `--ns-sk-p6`, `--ns-sk-p7`, `--ns-sk-read`, `--ns-sk-sweep`, `--ns-skeleton`, `--ns-skeleton-bone`, `--ns-skeleton-bone-light`, `--ns-skeleton-light`, `--ns-slab`, `--ns-slab-edge`, `--ns-slab-ink`, `--ns-sleep-awake`, `--ns-sleep-deep`, `--ns-sleep-light`, `--ns-sleep-rem`, `--ns-space-1`, `--ns-space-2`, `--ns-space-3`, `--ns-space-4`, `--ns-space-5`, `--ns-space-6`, `--ns-space-8`, `--ns-space-section`, `--ns-stack-fan`, `--ns-stack-fan-gap`, `--ns-stack-fan-lag`, `--ns-stack-on`, `--ns-stagger-item`, `--ns-stagger-mark`, `--ns-stagger-max`, `--ns-standing-critical`, `--ns-standing-in`, `--ns-standing-out`, `--ns-state-doing`, `--ns-state-done`, `--ns-state-review`, `--ns-state-todo`, `--ns-step`, `--ns-step-from`, `--ns-step-sign`, `--ns-swipe-surface`, `--ns-switch-h`, `--ns-switch-w`, `--ns-text-body`, `--ns-text-control`, `--ns-text-control-lg`, `--ns-text-display`, `--ns-text-editorial`, `--ns-text-empty`, `--ns-text-figure`, `--ns-text-giant`, `--ns-text-heading`, `--ns-text-headline`, `--ns-text-input`, `--ns-text-large`, `--ns-text-lede`, `--ns-text-meta`, `--ns-text-record`, `--ns-text-sentence`, `--ns-text-small`, `--ns-text-sub`, `--ns-text-title`, `--ns-theme-fade`, `--ns-tile-shadow`, `--ns-time-born`, `--ns-time-color`, `--ns-time-confirm`, `--ns-time-dialog`, `--ns-time-fling`, `--ns-time-flip`, `--ns-time-glide`, `--ns-time-grow`, `--ns-time-hold`, `--ns-time-menu`, `--ns-time-page`, `--ns-time-panel`, `--ns-time-quick`, `--ns-time-roll`, `--ns-time-settle`, `--ns-time-snap`, `--ns-time-spin`, `--ns-time-spring`, `--ns-time-sweep`, `--ns-time-toast`, `--ns-tint`, `--ns-tint-c`, `--ns-tint-ease`, `--ns-tint-fill`, `--ns-tint-gap`, `--ns-tint-h1`, `--ns-tint-h2`, `--ns-tint-h3`, `--ns-tint-ink`, `--ns-tint-row`, `--ns-tip-fold`, `--ns-tip-grow`, `--ns-toast-bottom`, `--ns-toast-gap`, `--ns-toast-left`, `--ns-toast-lift`, `--ns-toast-peek`, `--ns-toast-scale`, `--ns-toast-w`, `--ns-touch`, `--ns-tracking-body`, `--ns-tracking-caps`, `--ns-tracking-control`, `--ns-tracking-display`, `--ns-tracking-headline`, `--ns-tracking-sub`, `--ns-tracking-title`, `--ns-warn`, `--ns-warn-ink`, `--ns-wash-clay`, `--ns-wash-dusk`, `--ns-wash-graphite`, `--ns-wash-ink`, `--ns-wash-sage`, `--ns-wash-sand`, `--ns-weight-light`, `--ns-weight-medium`, `--ns-weight-regular`, `--ns-weight-strong`, `--ns-well`, `--ns-width-lg`, `--ns-width-md`, `--ns-width-sm`, `--ns-width-xl`.
- Never add Tailwind colour classes inside the component.

```tsx
import { CompanyMark } from "@/components/ui/notchset/company-mark";
```

## Parts
- A single export that takes props.

## Match the original
- Read `components/ui/notchset/question-card.tsx` as the reference implementation before changing or recreating anything, and match it: sizes, colours per theme, motion timings, copy and behaviour.
- If you deviate (a prop you can't honour, a style you changed, a dependency you swapped), say so in your reply, part by part.
- Keep the accessibility contract, the keyboard map and the motion levels listed below.

## Use it when
- When a run cannot go on without a person's answer (which page, which account, a sign-in).

### Not when
- Approving a step's effect is the gate in that step's tool row; a whole form a person fills on their own is a form, each answer its own field.

## Built from
- button (`button`), installed with it: reuse it, don't rebuild it
- radio-group (`radio-group`), installed with it: reuse it, don't rebuild it
- status-glyph-run (`status-glyph-run`), installed with it: reuse it, don't rebuild it
- stream-adapters (`stream-adapters`), installed with it: reuse it, don't rebuild it
- text-field (`text-field`), installed with it: reuse it, don't rebuild it
- Feedback (shared helper, ships with it)
- Icons (shared helper, ships with it)
- Words (shared helper, ships with it)

## Mistakes
- A modal for the question: it asks where the run is
- Declining ends the run: it ends the step
- Accept as a bare "Submit": word it for the job

## Usage

```tsx
"use client";
import * as React from "react";
import { CompanyMark } from "@/components/ui/notchset/company-mark";
import { useLessMotion } from "@/lib/notchset/motion";
import { QuestionCard } from "@/components/ui/notchset/question-card";
import type { Question, QuestionAnswer } from "@/components/ui/notchset/stream-adapters";
import { brandGlyph } from "./brands";
import { useSelfPlay } from "./self-play";

/*
 * The card alone: an agent drafting a launch note has stopped to ask which Notion page to post it to, and waits. On
 * view the card arrives with its amber edge and a pick lands on the second page; it rests there, waiting on you.
 * Post here folds it to one line with Change; Change opens it again. Nothing is sent anywhere.
 */
const CHOICE: Question = {
  id: "q1",
  mode: "choice",
  message: "Post the launch note to which Notion page?",
  options: [
    { value: "launch", label: "Launch · November", detail: "Read by the whole team" },
    { value: "changelog", label: "Changelog", detail: "Public, on the site" },
    { value: "updates", label: "Team updates", detail: "Only this team" },
  ],
};
const notion = <CompanyMark name="Notion" color="#191919" glyph={brandGlyph("notion")} size="xs" />;

export default function QuestionCardDemo() {
  const question = CHOICE;
  const root = React.useRef<HTMLDivElement>(null);
  const play = useSelfPlay(root, { beats: [0, 700], off: useLessMotion() });
  const [answer, setAnswer] = React.useState<QuestionAnswer | null>(null);
  const [gen, setGen] = React.useState(0);

  /* the arrival: the card comes in on its own rise, then a pick lands on the second page (at once with less motion) */
  const step = play.step;
  React.useEffect(() => {
    if (step !== 1 || play.mine) return;
    const t = window.setTimeout(() => root.current?.querySelectorAll<HTMLElement>("[data-live] [data-slot=question-card] [role=radio]")[1]?.click());
    return () => window.clearTimeout(t);
  }, [step, play.mine]);

  const picked = question.options?.find((o) => o.value === answer?.values?.choice)?.label;
  const accepted = answer?.action === "accept";
  return (
    <div ref={root} onPointerDownCapture={play.handOver} onKeyDownCapture={play.handOver} className="grid w-[min(100%,480px)] grid-cols-[minmax(0,1fr)]">
      {/* the waiting card, unseen, holds the stage's height when the card folds */}
      <div aria-hidden="true" ref={(el) => void (el && (el.inert = true))} className="invisible col-start-1 row-start-1 min-w-0">
        <QuestionCard question={{ ...question, id: "hold" }} accept="Post here" onAnswer={() => {}} />
      </div>
      <div data-live="" className="col-start-1 row-start-1 min-w-0 self-center">
        <QuestionCard
          key={gen}
          question={question}
          accept="Post here"
          onAnswer={setAnswer}
          answered={answer ? { action: answer.action, label: accepted ? (picked ?? "") : "the note waits", mark: accepted ? notion : undefined } : undefined}
          onReopen={() => (setAnswer(null), setGen((g) => g + 1))}
        />
      </div>
    </div>
  );
}
```

This example also uses `company-mark` (https://notchset.dev/components/company-mark). Installing this item doesn't bring them; to paste the example as it is: `npx shadcn@latest add https://notchset.dev/r/question-card.json https://notchset.dev/r/company-mark.json`.

## Props

| Prop | Type | Default | What it does |
|---|---|---|---|
| `onFeedback` | `(e: FeedbackEvent) => void` |  | called once per move, for your sound or haptics |
| `question` | `Question` |  | what the agent asks, as the stream sent it: a choice, a form or a link |
| `onAnswer` | `(answer: QuestionAnswer) => void` |  | what the person did: accept (with the choice or the form's values), decline or cancel |
| `answered` | `{ action: QuestionAnswer["action"]; label: string; mark?: React.ReactNode }` |  | once answered, the line it folds to: the action and the answer in words ("Launch · November", "booking skipped") |
| `touches` | `{ mark?: React.ReactNode; title: string; detail?: string \| undefined }` |  | the record the answer acts on, read under the ask: its mark, its name and one line ("draft · 412 words") |
| `columns` | `1 \| "auto"` |  | kept for hosts written against the cards; the choices are always one per row |
| `onReopen` | `() => void` |  | unfold an answered card to answer again (Change, Ask again) |
| `onCancelRun` | `() => void` |  | stop the whole run: with it the card offers Cancel run beside Decline |
| `accept` | `string` |  | the Accept button's words, worded for the job: "Post here", "Connect Calendly" |
| `service` | `{ mark?: React.ReactNode; detail?: string \| undefined }` |  | a link's service: its mark and one line on what it will do ("Reads your free times · books one event") |
| `labels` | `Partial<QuestionCardLabels>` |  | its words, over the English defaults |

Full docs: https://notchset.dev/components/question-card

## Customising
- Colours: every part reads the foundation's roles (`--ns-canvas`, `--ns-ink`, `--ns-line`, `--ns-signal` …), which read your shadcn tokens (`--background`, `--foreground`, `--border`, `--destructive` …), plus the optional `--success` and `--warning`. Retheme on `:root` or any container; never add Tailwind colour classes inside the component.
- Dark mode follows the `.dark` class or `data-theme="dark"` on an ancestor (the shadcn and next-themes conventions).
- Update later: Commit or stash local changes first (or copy the files), so the update can be undone. Read https://notchset.dev/r/changelog.json for the new versions: a major version, an entry marked breaking or a merge says what to change. Then re-run the install with `--overwrite`, on a branch. It replaces the component's files, the shared helper files they import, and the item's CSS rules in the global stylesheet, so review the whole diff (components, shared files, CSS), re-apply your own edits, and run the app's typecheck, tests and build.

## Keyboard

| Keys | Action |
|---|---|
| ↑ ↓ | move between the choices |
| Tab | reaches Accept, Decline and Cancel run |

## Performance

- Plain markup; the form keeps its values in one state; nothing loads until asked.

## Responsive

- phone and desktop
- dark (tokens)
- reduced motion: it appears and folds without the rise

## Motion inventory

| Interaction | What moves |
|---|---|
| grows in place of the waiting step | ns-rise on --ns-time-panel, --ns-ease-panel. Reduced motion: it appears. |
| folds to its one line | ns-fade on --ns-time-panel, --ns-ease. Reduced motion: it swaps. |

## Accessibility contract (preserve when editing)
- A group named by its question; the choice is a radio group, the form's fields are labelled; folding moves focus to the answered line and unfolding to the first control; a sign-in says it opens a new window.
- Waiting is said in words, never by the warn edge alone.

## Install

```bash
# npm
npx shadcn@latest add https://notchset.dev/r/question-card.json
# pnpm
pnpm dlx shadcn@latest add https://notchset.dev/r/question-card.json
# yarn
yarn dlx shadcn@latest add https://notchset.dev/r/question-card.json
# bun
bunx --bun shadcn@latest add https://notchset.dev/r/question-card.json
```

Or add the `@notchset` registry to components.json and run `npx shadcn@latest add @notchset/question-card`. Every components.json style gets the same files.

### Manual

1. Install the packages: `npm install lucide-react@^1`.
2. Copy `components/ui/notchset/question-card.tsx`, `lib/notchset/feedback.ts`, `lib/notchset/icons.ts`, `lib/notchset/words.ts` from https://notchset.dev/r/question-card.json (each file's `content`, at its `target`), keeping the `@/` path alias of your tsconfig.
3. Add what it builds on: shadcn `utils` (cn), `notchset-foundation`, `button`, `radio-group`, `status-glyph-run`, `stream-adapters`, `text-field`.

## Continue the workflow

- [Change set](https://notchset.dev/components/change-set)
- [Checkpoint rail](https://notchset.dev/components/checkpoint-rail)
- [Message](https://notchset.dev/components/message)

## Source

### components/ui/notchset/question-card.tsx

```tsx
// Notchset question-card 1.1.0 · https://notchset.dev/changelog
"use client";
import * as React from "react";
import { ExternalLink } from "@/lib/notchset/icons";
import { cn } from "@/lib/utils";
import { Button } from "@/components/ui/notchset/button";
import { RadioGroup } from "@/components/ui/notchset/radio-group";
import { StatusGlyphRun } from "@/components/ui/notchset/status-glyph-run";
import type { Question, QuestionAnswer } from "@/components/ui/notchset/stream-adapters";
import { TextField } from "@/components/ui/notchset/text-field";
import { fill } from "@/lib/notchset/words";
import type { FeedbackProps } from "@/lib/notchset/feedback";

/*
 * Question card: an agent asks mid-run and waits, in the run's own place (it grows where the waiting step was, never
 * a modal). Three kinds, as the stream sends them (Question, stream-adapters): a choice among a few ("Post the launch
 * note to which Notion page?"), a short form from a flat schema, or a link to sign in ("Connect Calendly to book the
 * review", opened in a new window). It offers Accept (worded for the job: "Post here", "Connect Calendly"), Decline
 * and, when the host passes its handler, Cancel run. Waiting it wears the waiting glyph and the warn edge; answered it folds to
 * one line ("Answered: Launch · November" with Change, or "Declined: booking skipped" with Ask again) and focus moves
 * to that line, so the person keeps their place. Declining ends the step, not the run. The host owns the run and
 * whether it was answered (`answered`); the card reports what the person did through onAnswer.
 *
 * What it is blocked on reads under the ask: `touches` names the record the answer acts on (the launch note, a draft,
 * 412 words), and each choice's detail says what picking it will do ("Whole company · 214 people get an email"). The
 * choices are a ruled list, one per row, a dot filling on the pick. Enter on a choice or a field
 * accepts. Folded, an accepted answer reads as a chip, with its mark when `answered.mark` is given.
 *
 *   <QuestionCard question={q} accept="Post here" onAnswer={reply} answered={a && { action: a.action, label: "Launch" }} />
 */
type QuestionCardLabels = {
  waiting: string;
  accept: string;
  decline: string;
  cancel: string;
  answered: string;
  declined: string;
  change: string;
  askAgain: string;
  opens: string;
};
const QUESTION_CARD_LABELS: QuestionCardLabels = {
  waiting: "Waiting on you",
  accept: "Accept",
  decline: "Decline",
  cancel: "Cancel run",
  answered: "Answered: {answer}",
  declined: "Declined: {answer}",
  change: "Change",
  askAgain: "Ask again",
  opens: "Opens sign-in in a new window",
};
type QuestionCardProps = FeedbackProps & {
  /** what the agent asks, as the stream sent it: a choice, a form or a link */
  question: Question;
  /** what the person did: accept (with the choice or the form's values), decline or cancel */
  onAnswer: (answer: QuestionAnswer) => void;
  /** once answered, the line it folds to: the action and the answer in words ("Launch · November", "booking skipped") */
  answered?: { action: QuestionAnswer["action"]; label: string; mark?: React.ReactNode } | undefined;
  /** the record the answer acts on, read under the ask: its mark, its name and one line ("draft · 412 words") */
  touches?: { mark?: React.ReactNode; title: string; detail?: string | undefined } | undefined;
  /** kept for hosts written against the cards; the choices are always one per row */
  columns?: 1 | "auto" | undefined;
  /** unfold an answered card to answer again (Change, Ask again) */
  onReopen?: (() => void) | undefined;
  /** stop the whole run: with it the card offers Cancel run beside Decline */
  onCancelRun?: (() => void) | undefined;
  /** the Accept button's words, worded for the job: "Post here", "Connect Calendly" */
  accept?: string | undefined;
  /** a link's service: its mark and one line on what it will do ("Reads your free times · books one event") */
  service?: { mark?: React.ReactNode; detail?: string | undefined } | undefined;
  /** its words, over the English defaults */
  labels?: Partial<QuestionCardLabels> | undefined;
  className?: string | undefined;
};

function QuestionCard({ question: q, onAnswer, answered, onReopen, onCancelRun, accept, service, touches, labels, className, onFeedback }: QuestionCardProps) {
  const L = { ...QUESTION_CARD_LABELS, ...labels };
  const [choice, setChoice] = React.useState<string | null>(q.options?.[0]?.value ?? null);
  const [values, setValues] = React.useState<Record<string, unknown>>(() => Object.fromEntries(Object.entries(q.schema?.properties ?? {}).map(([k, f]) => [k, f.default ?? ""])));
  const line = React.useRef<HTMLDivElement>(null);
  const card = React.useRef<HTMLDivElement>(null);
  /* folding or unfolding moves focus to what is there now, so the person keeps their place; only when they were
     there: an answer that arrives from elsewhere never takes their focus */
  const inside = React.useRef(false);
  const first = React.useRef(true);
  const isAnswered = !!answered;
  React.useEffect(() => {
    if (first.current) return void (first.current = false);
    if (!inside.current) return;
    (isAnswered ? line.current : card.current?.querySelector<HTMLElement>("[role=radio][aria-checked=true],input,button"))?.focus({ preventScroll: true });
  }, [isAnswered]);
  const track = { onFocusCapture: () => void (inside.current = true), onBlurCapture: (e: React.FocusEvent) => void (inside.current = !!e.relatedTarget && e.currentTarget.contains(e.relatedTarget as Node)) };

  if (answered) {
    const yes = answered.action === "accept";
    const [before, after = ""] = (yes ? L.answered : L.declined).split("{answer}");
    return (
      <div
        ref={line}
        tabIndex={-1}
        {...track}
        data-slot="question-card"
        data-state={answered.action}
        className={cn("flex min-h-11 min-w-0 items-center gap-2.5 rounded-[var(--ns-radius-lg)] bg-[var(--ns-raised)] ps-3 pe-1.5 shadow-[var(--ns-bezel)] outline-hidden [animation:ns-fade_var(--ns-time-panel)_var(--ns-ease)] focus-visible:shadow-[0_0_0_2px_var(--ns-signal),var(--ns-bezel)]", className)}
      >
        <StatusGlyphRun state={yes ? "done" : "stopped"} label={q.message} />
        {yes ? (
          <span className="flex min-w-0 flex-1 items-center gap-1.5 text-[length:var(--ns-text-body)] text-[var(--ns-ink-2)]">
            <span className="shrink-0 whitespace-pre">{before}</span>
            <span data-slot="question-chip" className="inline-flex min-w-0 items-center gap-1.5 rounded-[var(--ns-radius-full)] bg-[var(--ns-well)] py-0.5 ps-2 pe-2.5 text-[length:var(--ns-text-small)] font-[number:var(--ns-weight-medium)] text-[var(--ns-ink)] has-[[data-mark]]:ps-1.5">
              {answered.mark && (
                <span data-mark="" className="inline-flex shrink-0">
                  {answered.mark}
                </span>
              )}
              <span className="truncate">{answered.label}</span>
            </span>
            {after.trim() && <span className="shrink-0">{after.trim()}</span>}
          </span>
        ) : (
          <span className="min-w-0 flex-1 truncate text-[length:var(--ns-text-body)] text-[var(--ns-ink)]">{fill(L.declined, { answer: answered.label })}</span>
        )}
        {onReopen && (
          <Button size="sm" intent="ghost" onClick={() => (onFeedback?.("press"), onReopen?.())} className="ms-auto text-[var(--ns-ink-2)]">
            {yes ? L.change : L.askAgain}
          </Button>
        )}
      </div>
    );
  }

  const ready = q.mode === "choice" ? choice !== null : q.mode === "form" ? (q.schema?.required ?? []).every((k) => String(values[k] ?? "").trim() !== "") : true;
  const send = () => {
    onFeedback?.("send");
    if (q.mode === "link" && q.url) window.open(q.url, "_blank", "noopener");
    onAnswer({ action: "accept", values: q.mode === "choice" ? { choice } : q.mode === "form" ? values : undefined });
  };
  return (
    <div
      ref={card}
      {...track}
      role="group"
      aria-label={q.message}
      data-slot="question-card"
      data-state="waiting"
      data-mode={q.mode}
      onKeyDown={(e) => {
        /* Enter accepts from a choice or a field; an action button keeps its own Enter */
        if (e.key !== "Enter" || q.mode === "link" || e.defaultPrevented || !ready || (e.target as HTMLElement).closest("button:not([role=radio]),a,textarea")) return;
        e.preventDefault();
        send();
      }}
      className={cn(
        "flex min-w-0 flex-col gap-3 rounded-[var(--ns-radius-xl)] bg-[var(--ns-raised)] p-4 shadow-[0_0_0_1px_color-mix(in_oklab,var(--ns-warn)_45%,transparent),var(--ns-bezel)] [animation:ns-rise_var(--ns-time-panel)_var(--ns-ease-panel)]",
        className,
      )}
    >
      <span className="flex items-center gap-2 text-[length:var(--ns-text-small)] text-[var(--ns-warn-ink)]">
        <StatusGlyphRun state="waiting" label={q.message} size="sm" />
        {L.waiting}
      </span>
      {q.mode === "link" ? (
        <div className="flex min-w-0 items-start gap-3">
          {service?.mark && <span className="grid size-9 shrink-0 place-items-center">{service.mark}</span>}
          <span className="flex min-w-0 flex-col gap-0.5">
            <span className="text-[length:var(--ns-text-body)] font-[number:var(--ns-weight-medium)] text-[var(--ns-ink)]">{q.message}</span>
            {service?.detail && <span className="text-[length:var(--ns-text-small)] text-[var(--ns-ink-3)]">{service.detail}</span>}
          </span>
        </div>
      ) : (
        <p className="m-0 font-[number:var(--ns-weight-medium)] text-[var(--ns-ink)]">{q.message}</p>
      )}
      {touches && (
        <div data-slot="question-touches" className="-mt-1 flex min-w-0 items-center gap-2.5 rounded-[var(--ns-radius)] bg-[var(--ns-well)] px-2.5 py-2 text-[length:var(--ns-text-small)]">
          {touches.mark && <span className="inline-flex shrink-0">{touches.mark}</span>}
          <span className="min-w-0 flex-1 truncate">
            <span className="font-[number:var(--ns-weight-medium)] text-[var(--ns-ink)]">{touches.title}</span>
            {touches.detail && <span className="text-[var(--ns-ink-3)]">{` · ${touches.detail}`}</span>}
          </span>
        </div>
      )}
      {q.mode === "choice" && q.options && (
        <div className="min-w-0 [container-type:inline-size]">
          <RadioGroup label={q.message} value={choice} onValueChange={(v) => (onFeedback?.("select"), setChoice(v))} options={q.options.map((o) => ({ value: o.value, label: o.label, hint: o.detail }))} />
        </div>
      )}
      {q.mode === "form" && q.schema && (
        <div className="flex flex-col gap-3">
          {Object.entries(q.schema.properties).map(([k, f]) => (
            <TextField
              key={k}
              label={f.title ?? k}
              hint={f.description}
              required={q.schema?.required?.includes(k)}
              type={f.type === "number" || f.type === "integer" ? "number" : "text"}
              value={String(values[k] ?? "")}
              onValueChange={(v: string) => setValues((x) => ({ ...x, [k]: f.type === "number" || f.type === "integer" ? (v === "" ? "" : Number(v)) : v }))}
            />
          ))}
        </div>
      )}
      <div className="flex flex-wrap items-center gap-2">
        <Button size="sm" intent="primary" disabled={!ready} onClick={send}>
          {q.mode === "link" && <ExternalLink aria-hidden />}
          {accept ?? L.accept}
        </Button>
        <Button size="sm" intent="secondary" onClick={() => (onFeedback?.("press"), onAnswer({ action: "decline" }))}>
          {L.decline}
        </Button>
        {onCancelRun && (
          <Button size="sm" intent="ghost" onClick={() => (onFeedback?.("press"), onCancelRun?.())} className="ms-auto text-[var(--ns-ink-2)]">
            {L.cancel}
          </Button>
        )}
      </div>
      {q.mode === "link" && <span className="sr-only">{L.opens}</span>}
    </div>
  );
}

export { QUESTION_CARD_LABELS, QuestionCard, type QuestionCardLabels, type QuestionCardProps };
```

### lib/notchset/feedback.ts

```tsx
// Notchset question-card 1.1.0 · https://notchset.dev/changelog
export type FeedbackEvent = "press" | "toggle-on" | "toggle-off" | "open" | "close" | "select" | "success" | "error" | "add" | "remove" | "send";
export type FeedbackProps = {
  /** called once per move, for your sound or haptics */
  onFeedback?: ((e: FeedbackEvent) => void) | undefined;
};
```

### lib/notchset/icons.ts

```tsx
// Notchset question-card 1.1.0 · https://notchset.dev/changelog
/** Every piece imports its icons from here: swap the icon set in this one file. */
export * from "lucide-react";
```

### lib/notchset/words.ts

```tsx
// Notchset question-card 1.1.0 · https://notchset.dev/changelog
import * as React from "react";

/* Built-in words and figures, one way for every piece. */

/** The locale a piece writes in when the app passes none: English at launch, the same on the server and in the browser. */
export const DEFAULT_LOCALE = "en-US";

/** A count's words by the locale's plural rule: `other` always, any of the locale's other forms as it needs them. */
export type Plural = { other: string } & Partial<Record<Intl.LDMLPluralRule, string>>;

/** A whole number (or any figure) in the locale's digits and grouping. */
export function formatCount(n: number, locale: string = DEFAULT_LOCALE, options?: Intl.NumberFormatOptions): string {
  return new Intl.NumberFormat(locale, options).format(n);
}

/** A sentence with its `{name}` blanks filled; a blank with no value is left as written. */
export function fill(sentence: string, vars: Readonly<Record<string, string | number>>): string {
  return sentence.replace(/\{(\w+)\}/g, (blank, name: string) => (name in vars ? String(vars[name]) : blank));
}

/** The same, where a blank is a node (a name in ink): the sentence's own words stay in order around it. */
export function fillNodes(sentence: string, vars: Readonly<Record<string, React.ReactNode>>): React.ReactNode {
  return sentence.split(/(\{\w+\})/).map((part, i) => {
    const name = /^\{(\w+)\}$/.exec(part)?.[1];
    return name !== undefined && name in vars ? React.createElement(React.Fragment, { key: i }, vars[name]) : part;
  });
}

/** A count's sentence by the locale's plural rule, `{count}` written in the locale ("1 message", "4 messages"). */
export function plural(locale: string | undefined, n: number, forms: Plural, vars: Readonly<Record<string, string | number>> = {}): string {
  const loc = locale ?? DEFAULT_LOCALE;
  const rule = new Intl.PluralRules(loc).select(n);
  return fill(forms[rule] ?? forms.other, { count: formatCount(n, loc), ...vars });
}
```

The foundation (the tokens listed above, keyframes and motion levels) installs once with the first component; its CSS is public at https://notchset.dev/r/notchset-foundation.json.
