import { Paragraph, SizableText, YStack } from '@hanzo/gui' import type { ReactNode } from 'react' import { measure } from './panel' import { paint } from '../material/paint' import { weight } from '../material/weight' /** * Something the reader has to know before going on, said beside the work rather * than over it. * * A heading and a sentence, stacked, with a rule down the side saying which * kind it is. The alert this replaces laid the two out as siblings across a * row, which reads well on a full-width page and collapses in a column: the * heading takes a narrow strip and wraps over four lines while the sentence * starts two-thirds of the way across and overhangs the box. * * The rule carries the tone and the words do not. A banner filled with its own * hue is the loudest thing on any screen it appears on, which is how a reader * learns to stop reading them; the ink stays on the ladder so the sentence is * as legible in a caution as in a remark, and the hue does the one job of * saying which it is. */ const { plain, quiet, line } = paint /** * The three a screen actually draws. * * A remark, a caution and a refusal, which are the three states anything gets * told: this is worth knowing, this will go wrong, this went wrong. A fourth * for success is not here because a thing that worked is said by the thing * itself changing, not by a box appearing beside it. */ export type Tone = 'note' | 'warn' | 'bad' const RULE = { note: line, warn: paint.warn, bad: paint.bad, } as const /** * The same three, to anything that cannot see the rule. * * The hue is the whole of what separates them on screen, and a hue reaches no * screen reader and no reader who cannot tell the caution's neutral from the * refusal's red — both of which this ladder draws at the same lightness, * because attention is not a hue in this brand and so the two can only ever * differ by chroma. Said in the role, the three are three distinct things to * every reader: a remark is a note, a caution is advisory and is read out when * the reader gets to it, a refusal is read out when it appears. * * Roles rather than words, because this package ships no copy — a sentence * naming the tone would be English written into every language. */ const SAYS = { note: 'note', warn: 'status', bad: 'alert', } as const /** The mark's track and the words' track. A grid, so the sentence starts on the * same rule whether or not this notice carries a glyph. */ const WITH = 'auto minmax(0, 1fr)' export function Notice({ title, tone = 'note', mark, list, children, }: { title: ReactNode /** Which of the three this is. A remark unless said otherwise. */ tone?: Tone /** A glyph at the leading edge, drawn by the caller in the tone's colour. */ mark?: ReactNode /** * Several statements rather than one — everything still missing, every reason * an action would be refused. They arrive as values so the list is a real * list, which is what a screen reader counts and steps through, and so a * caller cannot put one inside the sentence below: a `ul` is not a nesting a * `p` allows, and a browser handed that pair keeps neither. */ list?: readonly ReactNode[] children?: ReactNode }) { const words = ( {title} {children ? ( {children} ) : null} {list?.length ? ( // The marker, stated, and the room it hangs in. A `list-item` box whose // `list-style-type` has been reset draws nothing at all, and statements // with no marks in front of them read as consecutive paragraphs — which // is the one thing a list is not, and the whole reason these arrive as // values rather than as a sentence. On the element, because the engine // has no knob for this one and drops a prop it does not know. {list.map((said, at) => ( } display="list-item" size="$2" color={quiet} > {said} ))} ) : null} ) return ( {mark ? ( {mark} {words} ) : ( words )} ) }