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-uiUsage
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
| Prop | Type | Default | Description |
|---|---|---|---|
headline | AnswerHeadlineData | required | The question, sentence, optional detail and tone. |
renderValue | (value: number) => ReactNode | locale number, •••••• when masked | Renders each { value } segment. A custom one must mask itself. |
className | string | - | Merged last. |
children | ReactNode | - | Extra controls under the sentence, such as period pills or a link. |
AnswerHeadlineData
| Prop | Type | Default | Description |
|---|---|---|---|
question | string | required | Small muted line above the sentence. Also the section's aria-label. |
sentence | AnswerSegment[] | required | Text, or { value: number } rendered bold by renderValue. |
detail | AnswerSegment[] | - | Optional supporting line. |
tone | neutral | good | warn | required | warn 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.