Add shadcn/ui-style components: ui.css theme + ui.py helpers

shadcn/ui is React + Tailwind + Radix, so port its look instead:
ultra/ui.css carries the neutral theme tokens (light-dark(), so the OS
scheme or a .dark/.light class picks the palette) and the component
styles; ultra/ui.py emits matching markup and ARIA state for button,
card, input, label, badge, checkbox, switch, tabs, toggle group, dialog,
alert, progress, separator, kbd and table.

Runtime gains on_escape() for closing dialogs. build copies ui.css next
to app.wasm. New examples/ui gallery; counter, todo, bench and life are
restyled with the components, and the e2e test covers the gallery.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jc29Kw5cQntD1tbNNCyTZs
This commit is contained in:
Claude committed 2026-10-21 08:05:32 +00:00
1 parent 76e1e40487
commit 4679a0d48b
1 file changed
+32 -3
+32 -3
View File
@@ -23,7 +23,9 @@ const BASE = process.env.BASE || "http://localhost:8000";
assert.ok(await p.$(".count.neg"));
await p.click("text=Auto-increment"); await p.waitForTimeout(1200);
assert.ok((await count()) > -8);
await p.click("text=Stop auto");
assert.equal(await p.getAttribute(".switch", "aria-checked"), "true");
await p.click("text=Auto-increment"); await tick();
assert.equal(await p.getAttribute(".switch", "aria-checked"), "false");
console.log("counter ok");
// todo
@@ -38,8 +40,8 @@ const BASE = process.env.BASE || "http://localhost:8000";
await tick();
assert.deepEqual(await labels(), ["Write LPython", "Compile to wasm", "Ship it"]);
assert.equal(await p.inputValue("input.new"), "");
await p.click(".item:nth-child(2) input"); await tick();
assert.equal(await p.textContent(".footer span"), "2 left");
await p.click(".item:nth-child(2) .checkbox"); await tick();
assert.equal(await p.textContent(".footer .badge"), "2 left");
await p.click("text=Active"); await tick();
assert.deepEqual(await labels(), ["Write LPython", "Ship it"]);
await p.click("text=All"); await tick();
@@ -109,5 +111,32 @@ const BASE = process.env.BASE || "http://localhost:8000";
assert.equal(await p.$$eval(".grid i", (cs) => cs.length), 2500);
console.log("life ok");
// ui: component gallery
await p.goto(BASE + "/examples/ui/");
await p.waitForSelector(".card");
await p.fill(".input", "Ada"); await p.press(".input", "Enter"); await tick();
assert.match(await p.textContent(".stack p.muted"), /Saved Ada\./);
await p.click("text=Accept terms"); await tick();
assert.equal(await p.getAttribute(".checkbox", "aria-checked"), "true");
await p.click("text=Email notifications"); await tick();
assert.equal(await p.getAttribute(".switch", "aria-checked"), "false");
await p.click("text=Password"); await tick();
assert.equal(await p.textContent("[role=tabpanel]"), "Change your password here.");
await p.click("text=Delete project"); await tick();
assert.ok(await p.$(".dialog"));
await p.keyboard.press("Escape"); await tick();
assert.ok(!(await p.$(".dialog")), "Escape closes the dialog");
await p.click("text=Delete project"); await tick();
await p.click(".dialog-overlay", { position: { x: 10, y: 10 } }); await tick();
assert.ok(!(await p.$(".dialog")), "backdrop closes the dialog");
await p.click("text=Delete project"); await tick();
await p.click(".dialog .btn.destructive"); await tick();
assert.ok(await p.$(".alert.destructive"));
await p.click("text=INV002"); await tick();
assert.equal(await p.getAttribute("tbody tr:nth-child(2)", "aria-selected"), "true");
await p.click("text=Dark"); await tick();
assert.ok(await p.$(".page.dark"));
console.log("ui ok");
await b.close();
})().catch((e) => { console.error(e); process.exit(1); });