Skip to Content

Answer Headline

The one-line answer a screen leads with: a question, a sentence with the deciding numbers bold, and an optional fact line.

Are we on track this month?

Yes. Revenue is 48,200, 12% ahead of plan.

Last month closed at 43,000.

import { AnswerHeadline, type AnswerHeadlineData } from "@dapplelight/signet-ui/components/answer-headline"

const onTrack: AnswerHeadlineData = {
  question: "Are we on track this month?",
  sentence: ["Yes. Revenue is ", { value: 48200 }, ", ", { value: 12 }, "% ahead of plan."],
  detail: ["Last month closed at ", { value: 43000 }, "."],
  tone: "good",
}

export function Demo() {
  return <AnswerHeadline headline={onTrack} renderValue={(n) => n.toLocaleString()} />
}

Installation

npm i @dapplelight/signet-ui

Usage

import { AnswerHeadline } from "@dapplelight/signet-ui/components/answer-headline"

<AnswerHeadline
  headline={{
    question: "Are we on track?",
    sentence: ["Revenue is ", { value: 48200 }, "."],
    tone: "good",
  }}
/>

Examples

Warn tone

Can we cover payroll?

Cash covers payroll for 5 more weeks.

Runway shortens if the Acme renewal slips past 30 Nov.

import {
  AnswerHeadline,
  AnswerHeadlineData,
} from "@dapplelight/signet-ui/components/answer-headline"

const atRisk: AnswerHeadlineData = {
  question: "Can we cover payroll?",
  sentence: ["Cash covers payroll for ", { value: 5 }, " more weeks."],
  detail: ["Runway shortens if the Acme renewal slips past 30 Nov."],
  tone: "warn",
}

<AnswerHeadline headline={atRisk} />

Neutral tone

How many people signed up this week?

342 new accounts.

import { AnswerHeadline } from "@dapplelight/signet-ui/components/answer-headline"

<AnswerHeadline
  headline={{
    question: "How many people signed up this week?",
    sentence: [{ value: 342 }, " new accounts."],
    tone: "neutral",
  }}
/>

Custom value rendering

Are we on track this month?

Yes. Revenue is $48,200, $12% ahead of plan.

Last month closed at $43,000.

import { AnswerHeadline } from "@dapplelight/signet-ui/components/answer-headline"
import { onTrack } from "./headlines"

<AnswerHeadline
  headline={onTrack}
  renderValue={(n) => `$${n.toLocaleString()}`}
/>

With controls

How many people signed up this week?

342 new accounts.

import { AnswerHeadline } from "@dapplelight/signet-ui/components/answer-headline"
import { Button } from "@dapplelight/signet-ui/components/button"
import { plain } from "./headlines"

<AnswerHeadline headline={plain}>
  <div className="flex gap-2">
    <Button size="sm" variant="outline">Week</Button>
    <Button size="sm" variant="ghost">Month</Button>
  </div>
</AnswerHeadline>

API Reference

AnswerHeadline

PropTypeDefaultDescription
headlineAnswerHeadlineDatarequiredThe question, sentence, optional detail and tone.
renderValue(value: number) => ReactNodelocale number, •••••• when maskedRenders each { value } segment. A custom one must mask itself.
classNamestring-Merged last.
childrenReactNode-Extra controls under the sentence, such as period pills or a link.

AnswerHeadlineData

PropTypeDefaultDescription
questionstringrequiredSmall muted line above the sentence. Also the section's aria-label.
sentenceAnswerSegment[]requiredText, or { value: number } rendered bold by renderValue.
detailAnswerSegment[]-Optional supporting line.
toneneutral | good | warnrequiredwarn renders amber. Never red, which means destructive.

Under the privacy mask, percentages in the text become ••%.

answerText

answerText(segments, format?) returns the plain text of a sentence for aria-labels, notifications and tests. format defaults to the locale number format.