Files
multica/packages/views/settings/components/settings-layout.tsx
Jiayuan Zhang 7803a5b9ea feat(ui): establish a role-named type scale and migrate ad-hoc font sizes (MUL-5451) (#6136)
tokens.css defined colours, radii and font families but not a single --text-*
step, so font sizes had no baseline to align to and grew wherever they were
needed: 51 distinct sizes across web + desktop, 370 written as arbitrary
values, six at half a pixel (10.5 / 11.5 / 12.5 / 13.5 / 14.5 / 15.5px).
text-xs and text-sm carried nearly all UI text while the range between them —
11, 13, 15px — could only be reached with arbitrary values. Hierarchy does not
come from having more sizes; past a handful, each extra size makes the
hierarchy blurrier.

Add ten role-named steps, each with its own line-height so leading cannot
fragment the way size did, and move every product-UI call site onto them.
Steps are named for what the text is for, not for a t-shirt size, because
that is what keeps the scale from drifting again.

Six steps deliberately keep the exact size/line-height pairs of the Tailwind
defaults they replace, so the ~1,900-call-site rename moves nothing on screen.
The visible changes are confined to former arbitrary values snapping to a step:
8/9/10px -> micro (11px) on badges and overlines; 17 -> 18; 22 -> 24; 30
(text-3xl) -> 36 on headings and stat numbers; 12.8px -> label (13px) on small
buttons and toggles. Half-pixel sizes are gone.

This supersedes #6108, which was reverted by #6116 because the sidebar group
labels rendered at the inherited 16px. The cause was not the scale but cn():
`text-<x>` is ambiguous in Tailwind, and tailwind-merge resolves it against a
table listing only the default sizes, so it filed every role step under
text-colour and dropped whichever of `text-caption` /
`text-sidebar-foreground/70` came first. Registering the steps as a font-size
class group restores the real conflict groups — size beats size, colour beats
colour, the two coexist — and a test pins the list against the scale, since
the failure is silent in source.

Hand-written CSS is covered too. The transcript kept a 12.5px body long after
every Tailwind call site was on the scale, so the "no half-pixel sizes" claim
was true of the classes and false of the product; the editor's prose, code and
mermaid ramps had the same blind spot, and seven of their eight values already
equalled a step exactly. All now reference var(--text-*). The guard test reads
raw `font-size:` declarations as well as class names, exempting only the 16px
iOS input-zoom workaround in base.css and the landing pages' marketing ramp.

apps/mobile (own NativeWind config) and apps/docs (fumadocs' own type system)
keep Tailwind's default scale and are untouched. Landing display type
(rem/clamp, 2.2-6.4rem) stays on its separate ramp, as do four decorative
emoji / serif-hero sizes.

Verified on a running local stack: pinned sidebar rows and group labels
measure 12px/16px, nav items 14px/20px — identical to pre-migration. An audit
of every rendered font size across the product surfaces finds nothing off the
scale; the only exceptions are avatar initials and emoji, which
actor-avatar.tsx sizes proportionally to the avatar diameter by design.

Co-authored-by: Lambda <lambda@multica.ai>
Co-authored-by: multica-agent <github@multica.ai>
2026-07-30 13:42:33 +08:00

190 lines
4.7 KiB
TypeScript

import type { ReactNode } from "react";
import { AlertCircle, Check, Loader2 } from "lucide-react";
import { Card, CardContent } from "@multica/ui/components/ui/card";
import { cn } from "@multica/ui/lib/utils";
export type SettingsSaveStatus = "idle" | "saving" | "saved" | "error";
export function SettingsTab({
title,
description,
children,
}: {
title: ReactNode;
description?: ReactNode;
children: ReactNode;
}) {
return (
<div className="space-y-8">
<header>
<h2 className="text-title-lg font-semibold tracking-tight">{title}</h2>
{description ? (
<p className="mt-1 max-w-2xl text-body leading-6 text-muted-foreground">
{description}
</p>
) : null}
</header>
{children}
</div>
);
}
export function SettingsSection({
title,
description,
action,
children,
className,
}: {
title?: ReactNode;
description?: ReactNode;
action?: ReactNode;
children: ReactNode;
className?: string;
}) {
return (
<section className={cn("space-y-3", className)}>
{title || description || action ? (
<div className="flex min-w-0 items-end justify-between gap-4 px-0.5">
<div className="min-w-0">
{title ? <h3 className="text-body font-semibold">{title}</h3> : null}
{description ? (
<p className="mt-1 text-caption leading-5 text-muted-foreground">
{description}
</p>
) : null}
</div>
{action ? <div className="shrink-0">{action}</div> : null}
</div>
) : null}
{children}
</section>
);
}
export function SettingsCard({
children,
className,
}: {
children: ReactNode;
className?: string;
}) {
return (
<Card className={cn("gap-0 py-0 shadow-none", className)}>
<CardContent className="divide-y divide-surface-border px-0">
{children}
</CardContent>
</Card>
);
}
/**
* Width tiers for the control column. Within a card, every text-entry
* control shares the `text` tier so their edges align; a row may only
* drop to a smaller tier when the field is deliberately short (a code,
* an enum select) — the difference must read as intentional. Pick a
* tier instead of adding per-row ad-hoc widths.
*/
const SETTINGS_CONTROL_WIDTHS = {
/** Text inputs and textareas — the standard control column. */
text: "sm:w-96",
/** Selects/pickers with long option labels (timezone, model). */
"select-wide": "sm:w-72",
/** Compact enum selects (theme, language). */
select: "sm:w-48",
/** Short fixed-format codes (issue prefix). */
code: "sm:w-40",
/** Unconstrained — non-input content like avatar uploads. */
none: "sm:max-w-none",
} as const;
export type SettingsControlSize = keyof typeof SETTINGS_CONTROL_WIDTHS;
export function SettingsRow({
label,
description,
children,
className,
size,
align = "center",
}: {
label: ReactNode;
description?: ReactNode;
children: ReactNode;
className?: string;
/** Control column width tier; omit for content-hugging controls (buttons, switches). */
size?: SettingsControlSize;
align?: "center" | "start";
}) {
return (
<div
className={cn(
"flex min-h-16 flex-col gap-3 px-4 py-3.5 sm:flex-row sm:justify-between sm:gap-8",
align === "center" ? "sm:items-center" : "sm:items-start",
className,
)}
>
<div className="min-w-0 flex-1">
<div className="text-body font-medium">{label}</div>
{description ? (
<div className="mt-0.5 text-caption leading-5 text-muted-foreground">
{description}
</div>
) : null}
</div>
<div
className={cn(
"w-full shrink-0 sm:w-auto sm:max-w-[56%]",
size ? SETTINGS_CONTROL_WIDTHS[size] : undefined,
)}
>
{children}
</div>
</div>
);
}
export function SettingsSaveState({
status,
savingLabel,
savedLabel,
errorLabel,
}: {
status: SettingsSaveStatus;
savingLabel: string;
savedLabel: string;
errorLabel: string;
}) {
if (status === "idle") return null;
const content =
status === "saving" ? (
<>
<Loader2 className="size-3 animate-spin" />
{savingLabel}
</>
) : status === "saved" ? (
<>
<Check className="size-3 text-success" />
{savedLabel}
</>
) : (
<>
<AlertCircle className="size-3 text-destructive" />
{errorLabel}
</>
);
return (
<span
role="status"
className={cn(
"inline-flex items-center gap-1.5 text-caption text-muted-foreground",
status === "error" && "text-destructive",
)}
>
{content}
</span>
);
}