From 9056ea2c7cf2c13232499b57a49210bc8c453d2d Mon Sep 17 00:00:00 2001 From: Menghuan1918 Date: Sat, 14 Nov 2026 00:15:44 +0800 Subject: [PATCH] feat(ui): shared page-pattern layer (facts, rows, states, fields, choices) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The clue surface carried 31 hand-written fact rows, 14 list-row shells, 10 empty states, 14 error+retry blocks, 15 stacked fields, 6 choice groups, 11 status footers and 9 action bars — 968 lines of CSS in ten near-identical families that had already drifted apart (four spellings of the retry row, three different "selected" pictures). These eight components own those shapes once, on the same token-only contract as the global kit: flat fills, one 1px border language, no shadow, no resting state painted, native keyboard semantics (a navigating title is a real + ) + : {title}} + {subtitle !== undefined && {subtitle}} + + {meta !== undefined && {meta}} + {actions !== undefined && {actions}} + + ) +} + +/** A text title must not inherit the button's pointer cursor. */ +const TITLE_TEXT = { cursor: 'inherit' } as const + +/** Props of {@link EmptyState}. */ +export interface EmptyStateProps { + readonly icon?: ReactNode + readonly title: ReactNode + readonly description?: ReactNode + readonly actions?: ReactNode + /** `page` centres in a whole pane; `well` is the compact block inside a list. */ + readonly tone?: 'page' | 'well' + readonly className?: string +} + +/** The one empty state: glyph, one-line title, optional description, actions. */ +export function EmptyState({ icon, title, description, actions, tone = 'well', className }: EmptyStateProps): ReactNode { + return ( +
+ {icon !== undefined && {icon}} + {title} + {description !== undefined && {description}} + {actions !== undefined && {actions}} +
+ ) +} + +/** Props of {@link ErrorBlock}. */ +export interface ErrorBlockProps { + readonly message: ReactNode + /** A sanitized second line (a reason code, a dependency id) — never a secret. */ + readonly detail?: ReactNode + readonly retryLabel?: string + readonly onRetry?: () => void + /** A retry already in flight: the button stays, disabled, and says so. */ + readonly busy?: boolean + readonly className?: string +} + +/** + * Error + its retry, as ONE block. + * + * The retry belongs to the message: separated, a reader can miss which line it + * belongs to, and the four hand-written spellings this replaces had already + * drifted in exactly that way (two put the button above, two below). + */ +export function ErrorBlock({ message, detail, retryLabel, onRetry, busy, className }: ErrorBlockProps): ReactNode { + return ( +
+ + {message} + {detail !== undefined && {detail}} + + {onRetry !== undefined && retryLabel !== undefined && ( + + {/* The kit's own action recipe: a retry is a button, not a fifth + spelling of one. */} + {retryLabel} + + )} +
+ ) +} + +/** Props of {@link Field}. */ +export interface FieldProps { + readonly label: ReactNode + readonly description?: ReactNode + readonly error?: ReactNode + readonly htmlFor?: string + /** `stacked` (default) puts the label above; `inline` puts it beside. */ + readonly layout?: 'stacked' | 'inline' + readonly children: ReactNode + readonly className?: string +} + +/** + * A labelled control with its description and its error. + * + * Replaces the 15 stacked label+control blocks that each re-declared the same + * three typographic rungs. The label is a real `