Every component is rebuilt on @base-ui/react with a single prop API, token-only colours and dark mode, and 28 new components are added. Components - New: Field, FeaturedTextArea, NumberInput, Combobox, CheckboxGroup, Slider, ToggleGroup/Toggle, IconButton, Dialog/Modal, AlertDialog, Drawer/Sheet, Popover, InfoTip, DropdownMenu, Tabs, Breadcrumb, Pagination, Toast (Toaster, useToast), Progress, Meter, Skeleton, CountBadge, Avatar/AvatarGroup, Kbd, Separator, Table - Rewritten: Button, Input, FeaturedInput, TextArea, Select, FeaturedSelect (real ARIA combobox), NativeSelect, Checkbox, Radio, Switch, Tooltip, Accordion, Alert, Spinner, Badge, Card - Removed TextField (use Input) and sonner (use Toast) Foundations - Semantic tokens (surfaces, text, borders, status ramps) in src/styles/tokens.css, with class-based dark mode - Visible focus rings, linked labels/descriptions/errors, alert roles by severity, keyboard support from Base UI - Fixed the Classic Blue ramp; Emerald, Amber and Teal 500 steps now carry white text at AA - Library build (per-component ES modules, types, tokens.css, exports) Quality - Vitest, Testing Library and axe tests for every component (289 tests) - scripts/check-stories.mjs renders every story in Chrome and fails on errors or axe violations, including contrast; all 423 stories pass in light and dark mode and in all seven palettes - Storybook: controls for every prop, open states for every popup, light/dark toolbar, Introduction guides, docs/CONVENTIONS.md BREAKING CHANGE: component props changed across the kit; see CHANGELOG.md.
175 lines
6.4 KiB
Python
175 lines
6.4 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Generate the landing page's component catalogue from the built Storybook
|
|
index, so it cannot drift from the stories again.
|
|
|
|
Run it after `npm run build-storybook` and before `npm run build` when you
|
|
add or remove a component. It prints the entries to paste into
|
|
src/data/catalogue.ts and writes /tmp/component_catalogue.json.
|
|
|
|
python3 scripts/gen_catalogue.py # print entries
|
|
python3 scripts/gen_catalogue.py --patch # also rewrite src/data/catalogue.ts
|
|
|
|
Components are read from story titles (`Group/Name`), so a new component
|
|
appears here without editing this script; only DETAIL is hand-written.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import re
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
REPO = Path(__file__).resolve().parent.parent
|
|
IDX = REPO / "storybook-static" / "index.json"
|
|
CATALOGUE = REPO / "src" / "data" / "catalogue.ts"
|
|
OUT = Path("/tmp/component_catalogue.json")
|
|
|
|
# Group order on the landing page; matches the Storybook sidebar.
|
|
GROUP_ORDER = ["Actions", "Forms", "Overlays", "Navigation", "Feedback", "Display", "Layout"]
|
|
|
|
# One-line coverage summary per component. Anything missing falls back to
|
|
# its story count, so a new component never breaks the generator.
|
|
DETAIL = {
|
|
"Button": "Variants · colours · loading · icons",
|
|
"ToggleGroup": "Segmented · multiple · icon-only",
|
|
"Input": "Addons · icons · filled · underline",
|
|
"FeaturedInput": "Floating label · password · clearable",
|
|
"TextArea": "Auto-resize · character count",
|
|
"FeaturedTextArea": "Floating label · auto-resize",
|
|
"NumberInput": "Steppers · currency · min/max",
|
|
"Field": "Label · description · error wiring",
|
|
"Select": "Single · multiple · grouped · clearable",
|
|
"FeaturedSelect": "Floating label · searchable · actions",
|
|
"Combobox": "Search · chips · async",
|
|
"NativeSelect": "Native menu · groups",
|
|
"Checkbox": "Indeterminate · colours · sizes",
|
|
"CheckboxGroup": "Select all · horizontal",
|
|
"Radio": "Cards · horizontal · descriptions",
|
|
"Switch": "Icons · label position · colours",
|
|
"Slider": "Range · marks · formatted",
|
|
"Dialog": "Sizes · scrolling body · forms",
|
|
"AlertDialog": "Destructive · async confirm",
|
|
"Drawer": "Four sides · sizes",
|
|
"Popover": "Sides · arrow · rich content",
|
|
"Tooltip": "Sides · colours · InfoTip",
|
|
"DropdownMenu": "Shortcuts · submenus · checkable",
|
|
"Tabs": "Underline · pills · vertical",
|
|
"Accordion": "Multiple · variants · heading level",
|
|
"Breadcrumb": "Collapse · icons",
|
|
"Pagination": "Siblings · boundaries · sizes",
|
|
"Alert": "Soft · solid · outline · dismissible",
|
|
"Toast": "Promise · actions · placement",
|
|
"Spinner": "Sizes · colours",
|
|
"Progress": "Indeterminate · meter · formatted",
|
|
"Skeleton": "Text · circle · card loading",
|
|
"Badge": "Colours · dot · removable · count",
|
|
"Avatar": "Initials · status · groups",
|
|
"Kbd": "Key combinations",
|
|
"Table": "Sortable · striped · sticky header",
|
|
"Card": "Outline · elevated · media · link",
|
|
"Separator": "Labelled · dashed · vertical",
|
|
}
|
|
|
|
|
|
def collect():
|
|
if not IDX.is_file():
|
|
sys.exit(f"{IDX} not found - run: npm run build-storybook")
|
|
|
|
entries = json.loads(IDX.read_text())["entries"].values()
|
|
comps: dict[str, dict] = {}
|
|
for e in entries:
|
|
group, _, name = e["title"].partition("/")
|
|
if not name or group not in GROUP_ORDER:
|
|
continue # Introduction pages and anything outside the component groups
|
|
c = comps.setdefault(name, {"group": group, "doc": None, "count": 0})
|
|
if e["type"] == "docs":
|
|
c["doc"] = e["id"]
|
|
else:
|
|
c["count"] += 1
|
|
|
|
ordered = sorted(comps.items(), key=lambda kv: (GROUP_ORDER.index(kv[1]["group"]), kv[0].lower()))
|
|
out = []
|
|
for i, (name, c) in enumerate(ordered, start=1):
|
|
if not c["doc"]:
|
|
print(f" WARN {name}: no documentation page, skipped", file=sys.stderr)
|
|
continue
|
|
out.append({
|
|
"number": f"{i:02d}",
|
|
"group": c["group"],
|
|
"name": name,
|
|
"detail": DETAIL.get(name, f"{c['count']} stories"),
|
|
"href": f"/docs/?path=/docs/{c['doc']}",
|
|
"count": c["count"],
|
|
})
|
|
return out
|
|
|
|
|
|
def as_tsx(entries) -> str:
|
|
body = "".join(
|
|
" {\n"
|
|
f" number: '{e['number']}',\n"
|
|
f" group: '{e['group']}',\n"
|
|
f" name: '{e['name']}',\n"
|
|
f" detail: '{e['detail']}',\n"
|
|
f" href: '{e['href']}',\n"
|
|
" },\n"
|
|
for e in entries
|
|
)
|
|
return f"export const documentation: CatalogueEntry[] = [\n{body}]\n"
|
|
|
|
|
|
def as_counts(entries) -> str:
|
|
lines = []
|
|
for e in entries:
|
|
key = e["name"] if re.fullmatch(r"[A-Za-z][A-Za-z0-9]*", e["name"]) \
|
|
else f"'{e['name']}'"
|
|
lines.append(f" {key}: {e['count']},")
|
|
return ("export const storyCounts: Record<string, number> = {\n"
|
|
+ "\n".join(lines) + "\n}\n")
|
|
|
|
|
|
def patch_catalogue(entries) -> None:
|
|
src = CATALOGUE.read_text()
|
|
|
|
src, n = re.subn(r"export const documentation\b[^=]*= \[.*?\n\]\n",
|
|
lambda _: as_tsx(entries), src, count=1, flags=re.S)
|
|
if n == 0:
|
|
sys.exit(f"could not find the documentation array in {CATALOGUE}")
|
|
|
|
src, n2 = re.subn(r"export const storyCounts\b[^=]*= \{.*?\n\}\n",
|
|
lambda _: as_counts(entries), src, count=1, flags=re.S)
|
|
if n2 == 0:
|
|
sys.exit(f"could not find the storyCounts block in {CATALOGUE}")
|
|
|
|
CATALOGUE.write_text(src)
|
|
print(f"patched {CATALOGUE} with {len(entries)} components")
|
|
|
|
|
|
def main() -> None:
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument("--patch", action="store_true",
|
|
help="rewrite the catalogue and story counts in src/data/catalogue.ts")
|
|
args = ap.parse_args()
|
|
|
|
entries = collect()
|
|
if not entries:
|
|
sys.exit("no components with a documentation story were found")
|
|
|
|
total = sum(e["count"] for e in entries)
|
|
for e in entries:
|
|
print(f" {e['number']} {e['name']:<16} {e['group']:<12} "
|
|
f"{e['count']:>2} stories {e['href']}")
|
|
|
|
OUT.write_text(json.dumps(entries, indent=1))
|
|
print(f"\n{len(entries)} components, {total} stories -> {OUT}")
|
|
|
|
if args.patch:
|
|
patch_catalogue(entries)
|
|
print("now run: npm run build")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|