feat(design): every button on its family, the chip primitive, the lint rule (E28 S3b2)
The second half of the button sweep: the remaining hand-rolled buttons in
feature components, the design lab and the components/ui composites now
stand on Button, IconButton, Pressable, Chip or DragHandle.
- Chip + DismissibleChip (filter / token / tag / suggest / ghost, 24px
floor, 44 on touch) replace five chip geometries; FilterChipGroup
renders Chips; overflow lanes measure a mirror painted by chipClass.
- The Plex control row is IconButton's player rung (36, 20px glyph,
round, overlay; 44 on touch); the YT modal bar is on the sm rung with
pressed cycle toggles and names that survive a folded label.
- New variants: IconButton ghost-accent, danger-soft; Button warn on a
new state-warn utility. The .btn-{tone} recipes and btnCls are gone.
- Fixed on the way: membership rows (collection editor, Plex playlist
add) announce checked/mixed; a one-letter tag chip was 21px wide;
descriptionLinks moved out of lib/ (it renders components).
- local/button-primitive: a raw <button>/<FocusSafeButton> outside the
control-primitive files is a lint error (contract-tested, seen red).
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { ESLint } from "eslint";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
// `local/button-primitive` (eslint.config.js): one primitive per button family (docs/DESIGN.md, E28
|
||||
// S3b). 268 hand-rolled buttons were swept onto ui/Button, IconButton, Pressable, Chip and
|
||||
// DragHandle; this pins that the rule keeping a new one out actually fires, and where it stands down.
|
||||
const RULE = "local/button-primitive";
|
||||
const FRONTEND = fileURLToPath(new URL("../../", import.meta.url));
|
||||
|
||||
async function hits(source: string, filePath = "src/components/__probe.tsx"): Promise<number> {
|
||||
const eslint = new ESLint({ cwd: FRONTEND });
|
||||
const [result] = await eslint.lintText(source, { filePath });
|
||||
return (result?.messages ?? []).filter((m) => m.ruleId === RULE).length;
|
||||
}
|
||||
|
||||
describe("a hand-rolled button", () => {
|
||||
it("is refused in a feature component, the lab and lib, raw or focus-safe", async () => {
|
||||
const raw = 'export const A = () => <button className="px-3">x</button>;\n';
|
||||
expect(await hits(raw)).toBe(1);
|
||||
expect(await hits(raw, "src/design-lab/__probe.tsx")).toBe(1);
|
||||
expect(await hits(raw, "src/lib/__probe.tsx")).toBe(1);
|
||||
// …and in a ui/ COMPOSITE: a pager or a side panel is built from the primitives too.
|
||||
expect(await hits(raw, "src/components/ui/Pager.tsx")).toBe(1);
|
||||
expect(
|
||||
await hits(
|
||||
'import { FocusSafeButton } from "./ui/FocusSafeButton";\nexport const B = () => <FocusSafeButton>x</FocusSafeButton>;\n',
|
||||
),
|
||||
).toBe(1);
|
||||
});
|
||||
|
||||
it("is allowed only in a control primitive, and the primitives pass everywhere", async () => {
|
||||
for (const file of ["IconButton.tsx", "SegmentedToggle.tsx", "AnchoredPopover.tsx"])
|
||||
expect(
|
||||
await hits("export const C = () => <button>x</button>;\n", `src/components/ui/${file}`),
|
||||
).toBe(0);
|
||||
// Named like a primitive but outside ui/: still refused.
|
||||
expect(
|
||||
await hits("export const E = () => <button>x</button>;\n", "src/components/Button.tsx"),
|
||||
).toBe(1);
|
||||
expect(
|
||||
await hits(
|
||||
'import { Button } from "./ui/Button";\nexport const D = () => <Button>x</Button>;\n',
|
||||
),
|
||||
).toBe(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user