refactor(ui): migrate the layout components off Tailwind utilities
Container, Columns, Grid, Divider, Image, Link, Typography and Kbd were built from utility classes and class: conditionals. That works only where Tailwind is present, and every variant cost a dozen conditional lines -- Divider spent eleven of them saying which token to paint the rule. They now carry wire-* classes with a local style block, and variants are data attributes the style block selects on. Divider went from eleven conditionals to five rules, and Typography lost thirteen. Behaviour is preserved rather than improved on. Container keeps columns and gap even though a container is not really a grid, because applications depend on them, and its columns default stays 2: the redesign contract test caught that changing it would silently reflow every Container already published. Additive only: Grid gains minItemWidth for an auto-fit track, Divider gains dashed and dotted variants, Image gains fit, and Link gains underline. Verified in a browser rather than by eye, since the pane cannot screenshot: track counts match the declared columns at desktop and collapse correctly below each breakpoint. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -3019,3 +3019,42 @@ test("custom scrollbar styles the scrollbar and drops its fake output", async ()
|
||||
expect(style).toContain("--scrollbar-thickness");
|
||||
expect(style).toContain("18rem");
|
||||
});
|
||||
|
||||
test("layout components ship their own styles instead of Tailwind utilities", () => {
|
||||
/*
|
||||
* These were built from utility classes and class: conditionals. That works
|
||||
* only where Tailwind is present, and a variant cost a dozen lines of
|
||||
* conditionals. They now carry wire-* classes, a local style block, and
|
||||
* data attributes the style block selects on.
|
||||
*/
|
||||
const migrated = [
|
||||
"Container",
|
||||
"Columns",
|
||||
"Grid",
|
||||
"Divider",
|
||||
"Image",
|
||||
"Link",
|
||||
"Typography",
|
||||
"Kbd",
|
||||
"LayoutSplitter",
|
||||
"CustomScrollbar",
|
||||
];
|
||||
const utility =
|
||||
/class:(grid-cols-|sm:|lg:|md:|max-w-|gap-[0-9]|px-[0-9]|py-[0-9]|border-l|bg-\[|h-0|text-xs|items-)/;
|
||||
|
||||
for (const name of migrated) {
|
||||
const source = readFileSync(uiComponentPath(name), "utf8");
|
||||
expect({ name, hasStyleBlock: /^\s{2}style \{/m.test(source) }).toEqual({
|
||||
name,
|
||||
hasStyleBlock: true,
|
||||
});
|
||||
expect({ name, usesUtilityConditionals: utility.test(source) }).toEqual({
|
||||
name,
|
||||
usesUtilityConditionals: false,
|
||||
});
|
||||
expect({ name, hasWireClass: /class='wire-[a-z-]+/.test(source) }).toEqual({
|
||||
name,
|
||||
hasWireClass: true,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user