@behavioral-agentic-design-system/core 0.42.0 → 0.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/package.json +25 -9
- package/scripts/a11y-lint.cjs +25 -1
- package/scripts/check-spec.mjs +73 -0
- package/scripts/deal-directions.mjs +186 -0
- package/scripts/health-report.mjs +20 -14
- package/scripts/lib/counted-lint.mjs +100 -0
- package/scripts/lib/marketing-library.mjs +129 -0
- package/scripts/lib/on-system.mjs +249 -0
- package/scripts/lib/random.mjs +22 -0
- package/scripts/lib/spec-parse.d.mts +25 -0
- package/scripts/lib/spec-parse.mjs +188 -0
- package/scripts/lib/tells.mjs +128 -0
- package/scripts/lint-css-vars.mjs +175 -0
- package/scripts/lint-html-nesting.mjs +116 -0
- package/scripts/lint-live-ctas.mjs +138 -0
- package/scripts/on-system-score.mjs +95 -0
- package/scripts/slop-rules.mjs +1 -1
- package/scripts/source-images.mjs +180 -0
- package/scripts/ux-tells.mjs +78 -0
- package/src/api/brand-colors.ts +3 -0
- package/src/api/brand-fonts.ts +3 -0
- package/src/api/brand-mark.ts +6 -1
- package/src/api/dev-write-guard.ts +53 -0
- package/src/api/layers/file.ts +7 -4
- package/src/api/onboarding-extract.ts +85 -30
- package/src/api/onboarding.ts +3 -0
- package/src/api/save-tokens.ts +3 -0
- package/src/app/layout.tsx +6 -0
- package/src/app/preview/canvas/page.tsx +12 -0
- package/src/app/preview/components/page.tsx +734 -0
- package/src/app/preview/studio/blank-screen.tsx +143 -0
- package/src/app/preview/studio/page.tsx +7 -0
- package/src/app/shell.tsx +160 -44
- package/src/components/canvas/canvas.tsx +458 -0
- package/src/components/canvas/layout.ts +72 -0
- package/src/components/canvas/parse-canvas.ts +32 -0
- package/src/components/canvas/sample.ts +90 -0
- package/src/components/canvas/spec-frame.tsx +43 -0
- package/src/components/canvas/types.ts +33 -0
- package/src/components/docs-tab.tsx +7 -7
- package/src/components/home-recent.tsx +73 -0
- package/src/components/home-tab.tsx +13 -13
- package/src/components/layers-tab.tsx +2 -2
- package/src/components/markdown-preview.tsx +60 -12
- package/src/components/studio/control-panel.tsx +299 -0
- package/src/components/studio/control-row.tsx +77 -0
- package/src/components/studio/preview-frame.tsx +165 -0
- package/src/components/studio/preview-pane.tsx +247 -0
- package/src/components/studio/studio.tsx +133 -128
- package/src/components/studio/types.ts +218 -0
- package/src/components/studio/use-studio-tweaks.ts +128 -0
- package/src/components/studio/use-studio-view-state.ts +72 -0
- package/src/components/ui/autocomplete.tsx +1 -1
- package/src/components/ui/color-picker.tsx +20 -4
- package/src/components/ui/data-table.tsx +64 -3
- package/src/components/ui/date-field.tsx +1 -1
- package/src/components/ui/editable.tsx +1 -0
- package/src/components/ui/faceted-filter.tsx +187 -0
- package/src/components/ui/gauge-chart.tsx +18 -4
- package/src/components/ui/inline-edit.tsx +175 -0
- package/src/components/ui/month-picker.tsx +1 -1
- package/src/components/ui/number-input.tsx +28 -5
- package/src/components/ui/otp-input.tsx +208 -0
- package/src/components/ui/phone-input.tsx +274 -0
- package/src/components/ui/search-input.tsx +1 -1
- package/src/components/ui/tags-input.tsx +1 -1
- package/src/components/ui/timer.tsx +1 -0
- package/src/components/ui/transfer-list.tsx +13 -26
- package/src/components/ui/week-picker.tsx +1 -1
- package/src/components/ui/year-picker.tsx +1 -1
- package/src/data/component-added.json +958 -0
- package/src/data/docs-index.ts +13 -1
- package/src/hooks/use-global-mono-font.ts +1 -0
- package/src/hooks/use-global-primary-color.ts +1 -0
- package/src/hooks/use-global-sans-font.ts +1 -0
- package/src/hooks/use-global-serif-font.ts +1 -0
- package/src/hooks/use-global-type-scale.ts +17 -2
- package/src/hooks/use-mobile.ts +2 -0
- package/src/hooks/use-sync-type-scale.ts +7 -11
- package/src/lib/spec-parse.ts +4 -0
- package/src/lib/svg-sanitize.ts +19 -9
- package/src/stories/Autocomplete.stories.tsx +2 -0
- package/src/stories/Canvas.stories.tsx +45 -0
- package/src/stories/ColorPicker.stories.tsx +40 -0
- package/src/stories/DataTable.stories.tsx +30 -0
- package/src/stories/DateField.stories.tsx +21 -0
- package/src/stories/Editable.stories.tsx +2 -0
- package/src/stories/FacetedFilter.stories.tsx +197 -0
- package/src/stories/GaugeChart.stories.tsx +9 -3
- package/src/stories/InlineEdit.stories.tsx +106 -0
- package/src/stories/MarkdownPreview.stories.tsx +53 -0
- package/src/stories/MonthPicker.stories.tsx +21 -0
- package/src/stories/NumberInput.stories.tsx +25 -0
- package/src/stories/OtpInput.stories.tsx +110 -0
- package/src/stories/PhoneInput.stories.tsx +127 -0
- package/src/stories/SearchInput.stories.tsx +2 -0
- package/src/stories/TagsInput.stories.tsx +2 -0
- package/src/stories/Timer.stories.tsx +26 -0
- package/src/stories/TransferList.stories.tsx +4 -0
- package/src/stories/WeekPicker.stories.tsx +21 -0
- package/src/stories/YearPicker.stories.tsx +21 -0
- package/src/stories/story-groups.json +22 -16
- package/src/tokens.json +82 -54
package/src/data/docs-index.ts
CHANGED
|
@@ -55,6 +55,9 @@ export const DOCS_INDEX: DocGroup[] = [
|
|
|
55
55
|
{ title: "Layer 3 — Primitive tokens", path: "layer-3-primitive-tokens/README.md" },
|
|
56
56
|
{ title: "Layer 4 — Semantic tokens", path: "layer-4-semantic-tokens/README.md" },
|
|
57
57
|
{ title: "Layer 5 — Component registry", path: "layer-5-component-registry/README.md" },
|
|
58
|
+
{ title: "Component decision records", path: "layer-5-component-registry/decisions/README.md", summary: "One record per component: why it exists, decided edge cases, and every option ruled out. Read before changing a component; MCP get_decisions serves it." },
|
|
59
|
+
{ title: "Product decision record", path: "docs/product-decision-record.md", summary: "A markdown record for a decision a prototype forces: question, two or more options, facts labeled Observed/Requirement/Assumption/Unknown, a human owner, sign-off, and revisit triggers. A lint enforces it; agents draft but never own or sign. Includes a worked example." },
|
|
60
|
+
{ title: "Decision velocity brief evaluation", path: "docs/decision-velocity-brief-evaluation.md", summary: "Evaluation note (partly adopted): a ChatGPT brief for a decision-review product. Adopted the markdown record and lint; set aside the app, permissions, concurrency, AI summaries and measurement pilot until a client needs them." },
|
|
58
61
|
{ title: "Layer 6 — Patterns & rules", path: "layer-6-patterns-and-rules/README.md" },
|
|
59
62
|
{ title: "Layer 7 — Agent interface", path: "layer-7-agent-interface/README.md" },
|
|
60
63
|
{ title: "Layer 8 — Documentation", path: "layer-8-documentation/README.md" },
|
|
@@ -68,6 +71,7 @@ export const DOCS_INDEX: DocGroup[] = [
|
|
|
68
71
|
description: "The exhaustive contract — file placement through PR shape, with the failure-mode catalog.",
|
|
69
72
|
entries: [
|
|
70
73
|
{ title: "Component build spec", path: "docs/component-build-spec.md", summary: "15-section contract every new component satisfies." },
|
|
74
|
+
{ title: "Hover states on shell-themed forks", path: "docs/shell-themed-hover-states.md", summary: "Why neutral muted and accent hovers read as gray patches on a brand-colored shell, and the per-theme override that fixes it." },
|
|
71
75
|
{ title: "Component readiness audit", path: "prompts/component-readiness-audit.md", summary: "13-question plan-time gate." },
|
|
72
76
|
{ title: "Component backlog", path: "docs/component-backlog.md", summary: "Figma-library primitives queued for Night Shift." },
|
|
73
77
|
{ title: "Component index", path: "COMPONENT_INDEX.md" },
|
|
@@ -114,6 +118,11 @@ export const DOCS_INDEX: DocGroup[] = [
|
|
|
114
118
|
{ title: "Skill — motion-review", path: ".claude/skills/motion-review/SKILL.md" },
|
|
115
119
|
{ title: "Skill — redesign", path: ".claude/skills/redesign/SKILL.md", summary: "Re-skin an existing surface WITHOUT changing what it does — preserve copy / IA / routes / brand, rebuild only the visual + interaction layer with a fresh (diversified) fingerprint. Distinct from design-exploration (new surface) and component-builder (one component). Adapted BADS-native from Hallmark's redesign verb." },
|
|
116
120
|
{ title: "Prompt — conceptual model", path: "prompts/conceptual-model.md", summary: "Before sketching a product surface, name its domain objects, states, relationships, and vocabulary — Jamie Mill's 'most neglected layer,' wired into Path B as design-exploration step 3.5. Feeds the real-content pool, state patterns, and primitive selection." },
|
|
121
|
+
{ title: "Prompt — subject inventory", path: "prompts/subject-inventory.md", summary: "For marketing and brand surfaces: list 8-12 facts that belong to this client and no competitor, each with a source, before any direction is drawn. The page idea and image searches come from the list. Adapted from taste-skill." },
|
|
122
|
+
{ title: "Marketing composition library", path: "disciplines/marketing/library/README.md", summary: "20 directions, 48 heroes and 172 section blueprints for marketing pages, dealt by bads-deal-directions so the choice among directions is real. Colors and fonts stay with brand tokens. Derived from taste-skill (MIT)." },
|
|
123
|
+
{ title: "Motion glossary", path: "disciplines/marketing/patterns/motion-glossary.md", summary: "24 web effects by name, each mapped to its BADS component or token, a status (default, expressive, caution, avoid) and a reduced-motion state, so a client or reviewer can ask for an effect by name." },
|
|
124
|
+
{ title: "motion-prompt evaluation", path: "docs/motion-prompt-evaluation.md", summary: "Evaluation note (idea adopted, library not installed): a library of 120 named effects for prompting. Adopted the naming idea as a BADS motion glossary mapped to tokens, components and the anti-defaults." },
|
|
125
|
+
{ title: "taste-skill evaluation", path: "docs/taste-skill-evaluation.md", summary: "Evaluation note (ideas adopted, skill not installed): what Leonxlnx/taste-skill adds beyond BADS's anti-defaults. Adopted a direction dealer, a subject inventory, open-license image sourcing and a rendered tells check, as BADS-native tools." },
|
|
117
126
|
{ title: "Prompt — parallel rollout", path: "prompts/parallel-rollout.md", summary: "For a Path B build that's N similar surfaces: build one reference screen, turn it into an explicit contract, sign off on the contract, then fan the rest out against it (via Workflow) and verify each to the contract. Stops multi-screen drift. Adapted from the design-spec-framework." },
|
|
118
127
|
{ title: "Prompt — design directions", path: "prompts/design-directions.md" },
|
|
119
128
|
{ title: "Prompt — color ramp", path: "prompts/color-ramp.md", summary: "Build a 9-shade ramp from the single brand hex a client hands you: place 500, find the edges, fill inward, and move with hue rotation (capped 20-30°) rather than lightness alone so dark shades don't go grey. Adapted to BADS's AAA floor, which is stricter than the source and pushes the dark end further than it looks." },
|
|
@@ -140,6 +149,7 @@ export const DOCS_INDEX: DocGroup[] = [
|
|
|
140
149
|
{ title: "lieflat-charts evaluation", path: "docs/lieflat-charts-evaluation.md", summary: "Scouting note (not adopted): an editorial data-viz agent skill. Blocker — PolyForm Noncommercial license; its code must never be vendored into a commercial fork. BADS already holds the philosophy (chart-design.md). One license-clean idea borrowed: a data-shape → chart-type selector added to chart-design.md." },
|
|
141
150
|
{ title: "PRAXIST evaluation", path: "docs/praxist-evaluation.md", summary: "Scouting note (not vendored): sapientinc/PRAXIST, an autonomous measurable-research engine. Blocker — Fair Source License, and it optimizes a single number where most BADS research is qualitative. The loop shape (iterate-search-evaluate) is borrowed via the existing auto-research skill for the Night Shift weekly deep-dive (step 3a); the measurable-metric optimization lab is designed here but deferred." },
|
|
142
151
|
{ title: "Deep-dive research questions", path: "docs/research-questions.md", summary: "Sir-curated queue for the Night Shift's weekly deep-dive (step 3a, Monday). The agent takes the top open question, runs the auto-research skill against it, and lands a report in ledgers/reports/. Empty queue is fine — the agent derives a question from recurring open ledger themes." },
|
|
152
|
+
{ title: "Agent-era design systems evaluation", path: "docs/agent-era-design-systems-evaluation.md", summary: "Scouting note on the Hatch talk \"Design Systems in the Age of Agents\" (Unily/Resin). Seven ideas adopted: decision records, lifecycle check, gap ledger, page assemblies, the why tool, stewardship fields, the consumer matrix. Includes a correction to our first read of the readiness audit." },
|
|
143
153
|
{ title: "HumanLayer skills evaluation", path: "docs/humanlayer-skills-evaluation.md", summary: "Scouting note (MIT — no adoption blocker): humanlayer/skills. design-control-loop's sensor/controller/actuator vocabulary maps 1:1 onto the Night Shift crew (borrowed as docs/control-loop.md); improve-claude-md's <important if> technique complements the de-blobbing (proposal filed); narrow-react-prop-types wired into Carl. build-iterated-agentic-loop + show-me skipped as redundant." },
|
|
144
154
|
{ title: "jakubkrehel/skills evaluation", path: "docs/jakubkrehel-skills-evaluation.md", summary: "Scouting note (MIT, nothing adopted): a design-engineering skill collection on BADS's home turf — every dimension (UI, type, color, a11y, layout, writing) is already covered by BADS with enforcement (lints/tokens/contracts), not just review prompts. The one real borrow is the source, not a skill: Jakub Krehel's Interfaces magazine added to the Friday research rotation." },
|
|
145
155
|
{ title: "HIGAgentSkills evaluation", path: "docs/hig-agent-skills-evaluation.md", summary: "Scouting note (content not vendored): justinwetch/HIGAgentSkills, a distilled Apple HIG corpus. Blockers — no license + Apple IP, web-vs-native mismatch, and BADS deliberately diverges from Apple. But its tiered routing-index architecture validates BADS's manifest approach and surfaces one real gap (a unified keyword→file lookup), filed as a proposal." },
|
|
@@ -148,7 +158,7 @@ export const DOCS_INDEX: DocGroup[] = [
|
|
|
148
158
|
{ title: "shadcn/lint evaluation", path: "docs/shadcn-lint-evaluation.md", summary: "Scouting note (MIT, adopted in full): shadcn/ui's new agent-first Tailwind linter. Ground-truthed all 6 rules against BADS's existing lint suite — 2 partial gaps extended into lint-tokens.js, 4 genuinely novel rules built from scratch (no-restyle, unknown-classes via the real Tailwind compiler, static-classes, inline-styles with BADS's own sanctioned exceptions). Found and fixed a real production bug (a silently-broken dynamic Tailwind class) and several real lint-implementation bugs (comment-scanning false positives, brace-extraction) along the way." },
|
|
149
159
|
{ title: "Paper.design evaluation", path: "docs/paper-design-evaluation.md", summary: "Scouting note (proprietary, open alpha — not adopted): a code-native design canvas whose elements are real HTML/CSS/Tailwind, with a bidirectional MCP server (sync tokens, export to React/Tailwind, commit to GitHub). Structurally a better-fitting mechanism than Figma Variables sync for the already-deferred 'Bidirectional Figma ↔ code sync' roadmap item (its 40+ component activation signal has already fired), but blocked from adoption today by alpha instability, proprietary vendor lock-in (tension with BADS's portability principle), and a local-desktop-only MCP server that can never be wired into Night Shift's autonomous pipeline. Revisit after a manual trial and a stable release." },
|
|
150
160
|
{ title: "Dessn evaluation", path: "docs/dessn-evaluation.md", summary: "Scouting note (proprietary, early-stage — not adopted): reads a GitHub/GitLab repo read-only, runs the real codebase in the cloud, and lets a designer prototype against the actual components — no separate canvas to sync. Compared directly against paper.design (different half of the same gap: Dessn targets the 'Prototype to production loop' fidelity-capture problem in roadmap-closedloop-import.md item #11, not Path B direction-sketching). Blocked by early-stage maturity, per-seat cost, no agent/MCP surface, and a real per-client trust ask (repo read access, even with SOC2/no-storage assurances). Motivated a new roadmap entry on whether BADS could build a cheaper native equivalent." },
|
|
151
|
-
{ title: "Open Design System Bench evaluation", path: "docs/open-design-system-bench-evaluation.md", summary: "Trial note (MIT, adopted as a manual tool, not wired into CI): a harness that runs Claude Code against a component library and grades the output. About $13 of runs found an undeclared peer dependency and an import-path gap in the agent docs; both fixed. After the fix, full context compiled in every run and cut hard-gate failures from 4 of 15 to 1 of 15, with no change in judged design quality." },
|
|
161
|
+
{ title: "Open Design System Bench evaluation", path: "docs/open-design-system-bench-evaluation.md", summary: "Trial note (MIT, adopted as a manual tool, not wired into CI): a harness that runs Claude Code against a component library and grades the output. About $13 of runs found an undeclared peer dependency and an import-path gap in the agent docs; both fixed. After the fix, full context compiled in every run and cut hard-gate failures from 4 of 15 to 1 of 15, with no change in judged design quality. Also records the grader setup traps (form-field vocabulary, autoFocus, lucide-react)." },
|
|
152
162
|
{ title: "Token migration", path: "docs/token-migration.md", summary: "The pattern for renaming/restructuring tokens in a fork without a heroic all-at-once PR: a token-migration.json old→new mapping enforced diff-aware (changed files held to new names, legacy tolerated in untouched files) via pnpm check:token-migration, plus a copy-pasteable mapping table. Adapted from web-common." },
|
|
153
163
|
{ title: "Chart color palette", path: "docs/chart-color-palette.md", summary: "Accessible 5-color categorical palette for data viz — Okabe-Ito-derived, reviewed against WCAG 1.4.11 non-text contrast." },
|
|
154
164
|
{ title: "Chart design", path: "docs/chart-design.md", summary: "Chart composition rules — grid, axes, labels, legend, tooltip, number formatting, states, motion. The 'data is the only saturated thing' register; companion to the color palette." },
|
|
@@ -242,6 +252,7 @@ export const DOCS_INDEX: DocGroup[] = [
|
|
|
242
252
|
description: "Deferred plans — what we'd build if the activation signal fires.",
|
|
243
253
|
entries: [
|
|
244
254
|
{ title: "Roadmap", path: "docs/roadmap.md", summary: "Layer 2/6/8/9/10 deferred work with the signal that should activate each one." },
|
|
255
|
+
{ title: "Prototype spec report", path: "docs/prototype-spec-report.md", summary: "Why each prototype is a container with a fixed-section spec.md (element inventory with an approver on every deferral, decisions, open questions, handoff), what shipped, and how the spec shows as a doc frame on the infinite canvas beside the live views, with pan-to-link, scrolling inside the frame, and a keyboard route." },
|
|
245
256
|
{ title: "Plan — skill package", path: "docs/plans/2026-08-21-skill-package.md", summary: "Approved plan: generate a per-fork, npx-installable agent skill — SKILL.md + drift-proof component recipes + token CSS — so the design system's rules travel into the client product repos where components are consumed. Phase A shipped; see the spec." },
|
|
246
257
|
{ title: "Spec — skill package", path: "docs/specs/2026-08-21-skill-package.md", summary: "The durable contract for packages/skill: generated-only output, usage-focused recipes, ≤2k-word SKILL.md, deterministic builds, the check:skill staleness gate, and the eval --context=skill acceptance instrument." },
|
|
247
258
|
{ title: "Plan — self-healing layer", path: "docs/plans/2026-08-21-self-healing-layer.md", summary: "Approved plan: the watch-half of the system — drift ledger, token intent validator, component health score, and a Health surface, assembled from signals BADS already owns; runtime telemetry deliberately deferred behind consent + futures-check." },
|
|
@@ -250,6 +261,7 @@ export const DOCS_INDEX: DocGroup[] = [
|
|
|
250
261
|
{ title: "Spec — drift elimination", path: "docs/specs/2026-08-31-drift-elimination.md", summary: "Phase A contract: precision over recall (unverifiable is never reported as drift), advisory-by-default with one blocking generated-artifact gate, additive-only sync manifest, and declared expected-drift allowlists. Calibration: 51→0 false positives on the registry checker, and real drift caught including llms.txt advertising 79 components when there were 173." },
|
|
251
262
|
{ title: "Plan — Best-of-N", path: "docs/plans/2026-09-10-best-of-n.md", summary: "Run one judgment N times and treat disagreement as the signal. Two uses: a three-verifier unanimity panel before Code Review Carl can force-merge a fix, and an eval agreement score that finds the rules repeated runs resolve differently. Rejects a merge agent and majority vote for the gate, and says why." },
|
|
252
263
|
{ title: "Spec — Best-of-N", path: "docs/specs/2026-09-10-best-of-n.md", summary: "The contract for scripts/verifier-panel.mjs (unanimous, fail-closed, distinct lenses, evidence-backed approvals) and scripts/eval-agreement.mjs (check stability, primitive choice, import path, drift rows only from the with-context arm). Records the first measurement: a skill rule sending agents to the package root, 3 of 15 before the fix and 0 of 15 after." },
|
|
264
|
+
{ title: "Plan — Studio rebuild", path: "docs/plans/2026-10-07-studio-screen.md", summary: "Controls left, live iframe preview right. Five directions with real references, the pick and the runner-up, and five parallel work packages." },
|
|
253
265
|
{ title: "Roadmap — ClosedLoop import candidates", path: "docs/roadmap-closedloop-import.md", summary: "Fourteen production patterns surfaced by auditing the closedloop-ai GitHub org (40 repos, 17 cloned, 2026-09-03). Three shipped immediately; the rest carry activation signals matching the standard roadmap format." },
|
|
254
266
|
{ title: "Spec — Prototype role views", path: "docs/specs/2026-09-28-prototype-role-views.md", summary: "Pre-activation contract for the roadmap's visual-prototyping-surface item: five views (designer canvas, engineer diff, PM flow map, researcher participant mode, QA gate) over one shared state tree, with the load-bearing rule that every edit in every view must resolve to a value tokens.json/component-registry.json already declares legal — no view can produce an off-system state. The QA view makes the constraint's own deliberate-violation test runnable on demand, reusing ux-smoke.mjs and the ux-tests.jsonl findings shape. Not being built yet; written to scope what building it would mean." },
|
|
255
267
|
],
|
|
@@ -154,6 +154,7 @@ const COLOR_KEY = storageKey("primaryColor");
|
|
|
154
154
|
const CUSTOMS_KEY = storageKey("customPrimaryColors");
|
|
155
155
|
// First brand color (if any) wins as the default; otherwise fall back to shadcn neutral.
|
|
156
156
|
const DEFAULT = brand.colors[0]?.id ?? "neutral";
|
|
157
|
+
export const DEFAULT_PRIMARY_COLOR = DEFAULT;
|
|
157
158
|
|
|
158
159
|
const PRIMARY_OVERRIDE_VARIABLES = [
|
|
159
160
|
"--primary",
|
|
@@ -47,6 +47,7 @@ import { storageKey, readMigrated } from "@behavioral-agentic-design-system/core
|
|
|
47
47
|
const STORAGE_KEY = storageKey("sansFont");
|
|
48
48
|
// First brand font (if any) wins as the default; otherwise Hyperlegible.
|
|
49
49
|
const DEFAULT: SansFontKey = SANS_BRAND_FONTS[0]?.id ?? "hyperlegible";
|
|
50
|
+
export const DEFAULT_SANS_FONT = DEFAULT;
|
|
50
51
|
|
|
51
52
|
function isValidKey(value: string | null): value is SansFontKey {
|
|
52
53
|
return !!value && value in SANS_FONT_OPTIONS;
|
|
@@ -35,7 +35,7 @@ const STORAGE_KEY = storageKey("typeScale");
|
|
|
35
35
|
|
|
36
36
|
/** The Tailwind text-* utilities this design system exposes, mapped to their
|
|
37
37
|
* step offset from base. Steps are exponents on the ratio. */
|
|
38
|
-
const STEPS: Record<string, number> = {
|
|
38
|
+
export const STEPS: Record<string, number> = {
|
|
39
39
|
"text-xs": -2,
|
|
40
40
|
"text-sm": -1,
|
|
41
41
|
"text-base": 0,
|
|
@@ -53,8 +53,23 @@ export function computeSizes(scale: TypeScale): Record<string, number> {
|
|
|
53
53
|
return out;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
function applyScale(
|
|
56
|
+
function applyScale(requested: TypeScale) {
|
|
57
57
|
if (typeof document === "undefined") return;
|
|
58
|
+
// Enforce the 14px text-xs floor (WCAG 1.4.4) at the single choke point so
|
|
59
|
+
// no caller can bypass it. Base 18 with ratio 1.4 used to render text-xs at
|
|
60
|
+
// 9.2px (18 / 1.4^2). text-xs is two steps down: base / ratio^2. Raise base
|
|
61
|
+
// to 14 * ratio^2 when under (ratio is lowered first, as clampTypeScale does).
|
|
62
|
+
// Mirrors clampTypeScale in components/studio/types.ts,
|
|
63
|
+
// inlined because hooks/ must not import from components/.
|
|
64
|
+
const FLOOR = 14;
|
|
65
|
+
const ratio = Math.max(
|
|
66
|
+
TYPE_SCALE_RANGES.ratio.min,
|
|
67
|
+
Math.min(requested.ratio, TYPE_SCALE_RANGES.ratio.max, Math.sqrt(requested.base / FLOOR)),
|
|
68
|
+
);
|
|
69
|
+
const scale: TypeScale = {
|
|
70
|
+
base: Math.min(TYPE_SCALE_RANGES.base.max, Math.max(requested.base, FLOOR * ratio ** 2)),
|
|
71
|
+
ratio,
|
|
72
|
+
};
|
|
58
73
|
const sizes = computeSizes(scale);
|
|
59
74
|
const root = document.documentElement.style;
|
|
60
75
|
// The CSS variables that Tailwind's text-* utilities resolve to are named
|
package/src/hooks/use-mobile.ts
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { useLayoutEffect } from "react";
|
|
4
|
-
import { TYPE_SCALE_DEFAULTS } from "./use-global-type-scale";
|
|
4
|
+
import { TYPE_SCALE_DEFAULTS, STEPS } from "./use-global-type-scale";
|
|
5
5
|
import { readMigrated } from "@behavioral-agentic-design-system/core/lib/storage";
|
|
6
6
|
|
|
7
|
-
const STEPS = {
|
|
8
|
-
"text-xs": -2,
|
|
9
|
-
"text-sm": -1,
|
|
10
|
-
"text-base": 0,
|
|
11
|
-
"text-lg": 1,
|
|
12
|
-
"text-xl": 2,
|
|
13
|
-
"text-2xl": 3,
|
|
14
|
-
"text-3xl": 4,
|
|
15
|
-
} as const;
|
|
16
|
-
|
|
17
7
|
function applyTypeScale() {
|
|
18
8
|
if (typeof window === "undefined" || typeof document === "undefined") return;
|
|
19
9
|
|
|
@@ -33,6 +23,12 @@ function applyTypeScale() {
|
|
|
33
23
|
// Use defaults
|
|
34
24
|
}
|
|
35
25
|
|
|
26
|
+
// Enforce the 14px text-xs floor (WCAG 1.4.4) on the persisted value.
|
|
27
|
+
// Mirrors applyScale() in use-global-type-scale.ts and the layout.tsx boot
|
|
28
|
+
// script. Lower ratio first, then raise base.
|
|
29
|
+
ratio = Math.max(1.05, Math.min(ratio, 1.4, Math.sqrt(base / 14)));
|
|
30
|
+
base = Math.min(22, Math.max(base, 14 * ratio * ratio));
|
|
31
|
+
|
|
36
32
|
// Apply computed sizes as CSS variables
|
|
37
33
|
for (const [name, step] of Object.entries(STEPS)) {
|
|
38
34
|
const size = base * Math.pow(ratio, step);
|
package/src/lib/svg-sanitize.ts
CHANGED
|
@@ -15,7 +15,7 @@ import type { Element as XmlElement } from "@xmldom/xmldom";
|
|
|
15
15
|
* are intentional brand color choices.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const ALLOWED_TAGS_RAW = [
|
|
19
19
|
"svg",
|
|
20
20
|
"g",
|
|
21
21
|
"path",
|
|
@@ -48,9 +48,12 @@ const ALLOWED_TAGS = new Set([
|
|
|
48
48
|
"feMerge",
|
|
49
49
|
"feMergeNode",
|
|
50
50
|
"feColorMatrix",
|
|
51
|
-
]
|
|
51
|
+
];
|
|
52
|
+
// Compared lowercased below. The raw lists keep SVG's camelCase spelling for readability; a lookup of
|
|
53
|
+
// "viewbox" in a Set holding "viewBox" misses, which used to strip viewBox, gradients and clipPaths.
|
|
54
|
+
const ALLOWED_TAGS = new Set(ALLOWED_TAGS_RAW.map((t) => t.toLowerCase()));
|
|
52
55
|
|
|
53
|
-
const
|
|
56
|
+
const ALLOWED_ATTRS_RAW = [
|
|
54
57
|
"id",
|
|
55
58
|
"class",
|
|
56
59
|
"viewBox",
|
|
@@ -107,7 +110,8 @@ const ALLOWED_ATTRS = new Set([
|
|
|
107
110
|
"color-interpolation-filters",
|
|
108
111
|
"patternUnits",
|
|
109
112
|
"patternContentUnits",
|
|
110
|
-
]
|
|
113
|
+
];
|
|
114
|
+
const ALLOWED_ATTRS = new Set(ALLOWED_ATTRS_RAW.map((a) => a.toLowerCase()));
|
|
111
115
|
|
|
112
116
|
const URL_ATTRS = new Set(["href", "xlink:href"]);
|
|
113
117
|
|
|
@@ -129,12 +133,15 @@ function stripDangerous(node: XmlElement): boolean {
|
|
|
129
133
|
node.removeAttribute(attr.name);
|
|
130
134
|
continue;
|
|
131
135
|
}
|
|
132
|
-
//
|
|
136
|
+
// href / xlink:href may only point inside the document (#id). An external URL on <use> or a
|
|
137
|
+
// gradient would make the browser fetch it, and javascript:/data: are never safe.
|
|
133
138
|
if (URL_ATTRS.has(an)) {
|
|
134
|
-
const v = (attr.value || "").trim()
|
|
135
|
-
if (v.startsWith("
|
|
136
|
-
|
|
137
|
-
|
|
139
|
+
const v = (attr.value || "").trim();
|
|
140
|
+
if (!v.startsWith("#")) node.removeAttribute(attr.name);
|
|
141
|
+
}
|
|
142
|
+
// style may reference only in-document url(#id); anything else is a remote fetch.
|
|
143
|
+
if (an === "style" && /url\(\s*(?!['"]?#)/i.test(attr.value || "")) {
|
|
144
|
+
node.removeAttribute(attr.name);
|
|
138
145
|
}
|
|
139
146
|
}
|
|
140
147
|
|
|
@@ -153,6 +160,9 @@ function normalizeColor(raw: string): string | null {
|
|
|
153
160
|
const v = raw.trim().toLowerCase();
|
|
154
161
|
if (!v) return null;
|
|
155
162
|
if (v === "none" || v === "transparent" || v === "inherit" || v === "currentcolor") return null;
|
|
163
|
+
// A paint server (gradient, pattern) is not a flat colour. Counting it as one made a gradient-only mark
|
|
164
|
+
// look monotone and rewrote fill="url(#g)" to currentColor.
|
|
165
|
+
if (v.startsWith("url(")) return null;
|
|
156
166
|
// Expand 3-char hex (#abc) to 6-char (#aabbcc) so matches across formats.
|
|
157
167
|
if (/^#[0-9a-f]{3}$/.test(v)) {
|
|
158
168
|
return `#${v[1]}${v[1]}${v[2]}${v[2]}${v[3]}${v[3]}`;
|
|
@@ -175,6 +175,8 @@ export const LongOptions: Story = {
|
|
|
175
175
|
};
|
|
176
176
|
|
|
177
177
|
// Realistic use: assign a design review — pick a teammate or type any name.
|
|
178
|
+
// Enter pressed to confirm an IME candidate (Japanese, Chinese, Korean) is ignored by this component.
|
|
179
|
+
// Not scriptable in a story; check by hand with an IME on.
|
|
178
180
|
export const RealisticUse: Story = {
|
|
179
181
|
render: function RealisticUseStory() {
|
|
180
182
|
const [value, setValue] = React.useState("");
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import { Canvas } from "@behavioral-agentic-design-system/core/components/canvas/canvas";
|
|
3
|
+
import {
|
|
4
|
+
SAMPLE_CANVAS,
|
|
5
|
+
SAMPLE_SPEC,
|
|
6
|
+
sampleResolveView,
|
|
7
|
+
} from "@behavioral-agentic-design-system/core/components/canvas/sample";
|
|
8
|
+
|
|
9
|
+
const meta: Meta<typeof Canvas> = {
|
|
10
|
+
title: "Components/Layout/Canvas",
|
|
11
|
+
component: Canvas,
|
|
12
|
+
parameters: { layout: "fullscreen" },
|
|
13
|
+
tags: ["autodocs"],
|
|
14
|
+
decorators: [
|
|
15
|
+
(Story) => (
|
|
16
|
+
<div className="h-[720px] p-4">
|
|
17
|
+
<Story />
|
|
18
|
+
</div>
|
|
19
|
+
),
|
|
20
|
+
],
|
|
21
|
+
args: {
|
|
22
|
+
doc: SAMPLE_CANVAS,
|
|
23
|
+
docs: { "spec.md": SAMPLE_SPEC },
|
|
24
|
+
resolveView: sampleResolveView,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default meta;
|
|
29
|
+
type Story = StoryObj<typeof meta>;
|
|
30
|
+
|
|
31
|
+
/** The spec is a doc frame on the canvas. It pans and zooms with the live views and scrolls inside its own frame. */
|
|
32
|
+
export const Default: Story = {};
|
|
33
|
+
|
|
34
|
+
/** Opens on one frame instead of the whole canvas. */
|
|
35
|
+
export const FocusedOnAView: Story = { args: { initialFrame: "dashboard" } };
|
|
36
|
+
|
|
37
|
+
/** A doc frame whose source is missing says so instead of rendering an empty box. */
|
|
38
|
+
export const MissingDocument: Story = { args: { docs: {} } };
|
|
39
|
+
|
|
40
|
+
/** With the pop-out link the reader can leave the canvas for the full-width spec. */
|
|
41
|
+
export const WithPopOut: Story = { args: { specHref: "/prototypes/showcase-overview?view=spec" } };
|
|
42
|
+
|
|
43
|
+
export const RealisticUse: Story = {
|
|
44
|
+
args: { initialFrame: "cards", specHref: "/prototypes/showcase-overview?view=spec" },
|
|
45
|
+
};
|
|
@@ -177,6 +177,46 @@ export const Controlled: Story = {
|
|
|
177
177
|
},
|
|
178
178
|
};
|
|
179
179
|
|
|
180
|
+
/**
|
|
181
|
+
* A controlled parent that stores the added color in uppercase, the way the
|
|
182
|
+
* Studio's palette hook does. The wheel drafts "#3b82f6" in lowercase, so a
|
|
183
|
+
* case-sensitive dedup listed the same color twice (one local, one from props).
|
|
184
|
+
*/
|
|
185
|
+
export const ControlledEchoesAddedColor: Story = {
|
|
186
|
+
render: function EchoPicker() {
|
|
187
|
+
const [color, setColor] = React.useState("#ef4444");
|
|
188
|
+
const [swatches, setSwatches] = React.useState(["#ef4444", "#22c55e"]);
|
|
189
|
+
return (
|
|
190
|
+
<ColorPicker
|
|
191
|
+
value={color}
|
|
192
|
+
swatches={swatches}
|
|
193
|
+
wheel
|
|
194
|
+
onValueChange={(hex) => {
|
|
195
|
+
setColor(hex.toUpperCase());
|
|
196
|
+
setSwatches((prev) =>
|
|
197
|
+
prev.some((c) => c.toLowerCase() === hex.toLowerCase()) ? prev : [...prev, hex.toUpperCase()]
|
|
198
|
+
);
|
|
199
|
+
}}
|
|
200
|
+
aria-label="Brand color"
|
|
201
|
+
/>
|
|
202
|
+
);
|
|
203
|
+
},
|
|
204
|
+
play: async ({ canvasElement }) => {
|
|
205
|
+
const canvas = within(canvasElement);
|
|
206
|
+
await userEvent.click(canvas.getByRole("button", { name: /add a custom color/i }));
|
|
207
|
+
// The wheel's draft starts at the current color, so type a new one: the lowercase
|
|
208
|
+
// hex the wheel keeps is what the uppercasing parent has to be matched against.
|
|
209
|
+
const hex = await within(document.body).findByLabelText(/hex color/i);
|
|
210
|
+
await userEvent.clear(hex);
|
|
211
|
+
await userEvent.type(hex, "#3b82f6");
|
|
212
|
+
await userEvent.click(await within(document.body).findByRole("button", { name: /^add color$/i }));
|
|
213
|
+
// The click commits through React state in the parent, so wait for the
|
|
214
|
+
// swatch instead of reading the DOM the instant the click returns.
|
|
215
|
+
const added = await canvas.findAllByRole("radio", { name: /^#3b82f6$/i });
|
|
216
|
+
await expect(added).toHaveLength(1);
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
|
|
180
220
|
function tagTextColor(hex: string): string {
|
|
181
221
|
const h = hex.replace("#", "");
|
|
182
222
|
const parts = h.length === 3
|
|
@@ -163,6 +163,34 @@ export const WithRowSelection: Story = {
|
|
|
163
163
|
),
|
|
164
164
|
};
|
|
165
165
|
|
|
166
|
+
// ---------------------------------------------------------------------------
|
|
167
|
+
// SelectionWithRowClick: ticking a checkbox selects; it does not open the row.
|
|
168
|
+
// onRowSelectionChange reports the selected data; getRowId keys rows by email.
|
|
169
|
+
// ---------------------------------------------------------------------------
|
|
170
|
+
|
|
171
|
+
export const SelectionWithRowClick: Story = {
|
|
172
|
+
parameters: { controls: { disable: true } },
|
|
173
|
+
render: () => {
|
|
174
|
+
const [selected, setSelected] = React.useState<TeamMember[]>([]);
|
|
175
|
+
const [opened, setOpened] = React.useState<string>("nobody");
|
|
176
|
+
return (
|
|
177
|
+
<div className="flex flex-col gap-3">
|
|
178
|
+
<DataTable
|
|
179
|
+
columns={TEAM_COLUMNS}
|
|
180
|
+
data={TEAM_MEMBERS}
|
|
181
|
+
rowSelection={true}
|
|
182
|
+
getRowId={(row) => row.email}
|
|
183
|
+
onRowSelectionChange={(rows) => setSelected(rows as TeamMember[])}
|
|
184
|
+
onRowClick={(row) => setOpened((row as TeamMember).name)}
|
|
185
|
+
/>
|
|
186
|
+
<p className="text-sm text-muted-foreground">
|
|
187
|
+
{selected.length} selected. Last opened: {opened}.
|
|
188
|
+
</p>
|
|
189
|
+
</div>
|
|
190
|
+
);
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
|
|
166
194
|
// ---------------------------------------------------------------------------
|
|
167
195
|
// Dense
|
|
168
196
|
// ---------------------------------------------------------------------------
|
|
@@ -276,6 +304,7 @@ export const WideOverflowing: Story = {
|
|
|
276
304
|
render: () => (
|
|
277
305
|
<div className="w-[380px]">
|
|
278
306
|
<DataTable
|
|
307
|
+
caption="Component adoption metrics"
|
|
279
308
|
columns={[
|
|
280
309
|
{ accessorKey: "component", header: "Component", size: 200 },
|
|
281
310
|
{ accessorKey: "status", header: "Status", size: 120 },
|
|
@@ -298,6 +327,7 @@ export const RealisticUse: Story = {
|
|
|
298
327
|
Component adoption tracker — Jordan Reeves' team across 14 product surfaces.
|
|
299
328
|
</p>
|
|
300
329
|
<DataTable
|
|
330
|
+
caption="Component adoption tracker"
|
|
301
331
|
columns={REALISTIC_COLUMNS}
|
|
302
332
|
data={REALISTIC_DATA}
|
|
303
333
|
sorting={true}
|
|
@@ -112,3 +112,24 @@ export const RealisticUse: Story = {
|
|
|
112
112
|
)
|
|
113
113
|
},
|
|
114
114
|
}
|
|
115
|
+
|
|
116
|
+
// Controlled from an empty state: `useState<Date>()` starts as undefined, which used to read as
|
|
117
|
+
// "uncontrolled", so a later Clear showed the first pick again.
|
|
118
|
+
export const ControlledStartsEmpty: Story = {
|
|
119
|
+
parameters: { controls: { disable: true } },
|
|
120
|
+
render: () => {
|
|
121
|
+
const [value, setValue] = React.useState<Date>()
|
|
122
|
+
return (
|
|
123
|
+
<div className="flex flex-col items-start gap-3">
|
|
124
|
+
<DateField value={value} onValueChange={(v) => setValue(v)} />
|
|
125
|
+
<button
|
|
126
|
+
type="button"
|
|
127
|
+
className="min-h-11 rounded-md border px-4 text-sm font-medium"
|
|
128
|
+
onClick={() => setValue(undefined)}
|
|
129
|
+
>
|
|
130
|
+
Clear
|
|
131
|
+
</button>
|
|
132
|
+
</div>
|
|
133
|
+
)
|
|
134
|
+
},
|
|
135
|
+
}
|
|
@@ -142,6 +142,8 @@ export const Controlled: Story = {
|
|
|
142
142
|
},
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
+
// Enter pressed to confirm an IME candidate (Japanese, Chinese, Korean) is ignored by this component.
|
|
146
|
+
// Not scriptable in a story; check by hand with an IME on.
|
|
145
147
|
export const RealisticUse: Story = {
|
|
146
148
|
render: () => {
|
|
147
149
|
const [name, setName] = React.useState("Brand refresh sprint")
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import type { Meta, StoryObj } from "@storybook/react"
|
|
3
|
+
import { userEvent, within, expect, waitFor } from "storybook/test"
|
|
4
|
+
import {
|
|
5
|
+
AlertCircleIcon,
|
|
6
|
+
ArrowDownIcon,
|
|
7
|
+
ArrowRightIcon,
|
|
8
|
+
ArrowUpIcon,
|
|
9
|
+
BuildingIcon,
|
|
10
|
+
ShieldIcon,
|
|
11
|
+
UserIcon,
|
|
12
|
+
UsersIcon,
|
|
13
|
+
} from "lucide-react"
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
FacetedFilter,
|
|
17
|
+
type FacetedFilterOption,
|
|
18
|
+
} from "@behavioral-agentic-design-system/core/components/ui/faceted-filter"
|
|
19
|
+
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// Option sets (real content — no "Option 1")
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
const STATUS_OPTIONS: FacetedFilterOption[] = [
|
|
24
|
+
{ label: "Active", value: "active", count: 124 },
|
|
25
|
+
{ label: "Inactive", value: "inactive", count: 38 },
|
|
26
|
+
{ label: "Pending", value: "pending", count: 17 },
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
const PRIORITY_OPTIONS: FacetedFilterOption[] = [
|
|
30
|
+
{ label: "Critical", value: "critical", icon: AlertCircleIcon },
|
|
31
|
+
{ label: "High", value: "high", icon: ArrowUpIcon },
|
|
32
|
+
{ label: "Medium", value: "medium", icon: ArrowRightIcon },
|
|
33
|
+
{ label: "Low", value: "low", icon: ArrowDownIcon },
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
const USER_STATUS_OPTIONS: FacetedFilterOption[] = [
|
|
37
|
+
{ label: "Verified", value: "verified", count: 892 },
|
|
38
|
+
{ label: "Unverified", value: "unverified", count: 74 },
|
|
39
|
+
{ label: "Suspended", value: "suspended", count: 12 },
|
|
40
|
+
{ label: "Pending review", value: "pending_review", count: 31 },
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
const ROLE_OPTIONS: FacetedFilterOption[] = [
|
|
44
|
+
{ label: "Admin", value: "admin", icon: ShieldIcon },
|
|
45
|
+
{ label: "Member", value: "member", icon: UserIcon },
|
|
46
|
+
{ label: "Viewer", value: "viewer", icon: UsersIcon },
|
|
47
|
+
{ label: "Billing", value: "billing", icon: BuildingIcon },
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
const TEAM_OPTIONS: FacetedFilterOption[] = [
|
|
51
|
+
{ label: "Engineering", value: "engineering", count: 48 },
|
|
52
|
+
{ label: "Design", value: "design", count: 12 },
|
|
53
|
+
{ label: "Marketing", value: "marketing", count: 19 },
|
|
54
|
+
{ label: "Sales", value: "sales", count: 34 },
|
|
55
|
+
{ label: "Support", value: "support", count: 27 },
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
// Controlled wrapper
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
function ControlledFacetedFilter({
|
|
62
|
+
defaultSelected = [],
|
|
63
|
+
...props
|
|
64
|
+
}: React.ComponentProps<typeof FacetedFilter> & {
|
|
65
|
+
defaultSelected?: string[]
|
|
66
|
+
}) {
|
|
67
|
+
const [selected, setSelected] = React.useState<Set<string>>(
|
|
68
|
+
new Set(defaultSelected)
|
|
69
|
+
)
|
|
70
|
+
return (
|
|
71
|
+
<FacetedFilter
|
|
72
|
+
{...props}
|
|
73
|
+
selectedValues={selected}
|
|
74
|
+
onSelectionChange={setSelected}
|
|
75
|
+
/>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
// Meta
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
82
|
+
const meta: Meta<typeof FacetedFilter> = {
|
|
83
|
+
title: "Components/Content and data/FacetedFilter",
|
|
84
|
+
component: FacetedFilter,
|
|
85
|
+
tags: ["autodocs"],
|
|
86
|
+
parameters: {
|
|
87
|
+
layout: "centered",
|
|
88
|
+
docs: {
|
|
89
|
+
description: {
|
|
90
|
+
component:
|
|
91
|
+
"Popover-based multi-select filter for DataTable surfaces. Composes Popover + Command + Checkbox + Badge + Button — no new dependencies.",
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export default meta
|
|
98
|
+
type Story = StoryObj<typeof meta>
|
|
99
|
+
|
|
100
|
+
// ---------------------------------------------------------------------------
|
|
101
|
+
// Stories
|
|
102
|
+
// ---------------------------------------------------------------------------
|
|
103
|
+
|
|
104
|
+
export const Default: Story = {
|
|
105
|
+
parameters: { controls: { disable: true } },
|
|
106
|
+
render: () => (
|
|
107
|
+
<ControlledFacetedFilter title="Status" options={STATUS_OPTIONS} />
|
|
108
|
+
),
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export const WithPreselection: Story = {
|
|
112
|
+
parameters: { controls: { disable: true } },
|
|
113
|
+
render: () => (
|
|
114
|
+
<div className="flex flex-wrap items-center gap-3">
|
|
115
|
+
<ControlledFacetedFilter
|
|
116
|
+
title="Status (1 selected)"
|
|
117
|
+
options={STATUS_OPTIONS}
|
|
118
|
+
defaultSelected={["active"]}
|
|
119
|
+
/>
|
|
120
|
+
<ControlledFacetedFilter
|
|
121
|
+
title="Status (2 selected)"
|
|
122
|
+
options={STATUS_OPTIONS}
|
|
123
|
+
defaultSelected={["active", "pending"]}
|
|
124
|
+
/>
|
|
125
|
+
<ControlledFacetedFilter
|
|
126
|
+
title="Status (3+ selected)"
|
|
127
|
+
options={STATUS_OPTIONS}
|
|
128
|
+
defaultSelected={["active", "inactive", "pending"]}
|
|
129
|
+
/>
|
|
130
|
+
</div>
|
|
131
|
+
),
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// No other story ever opens the popover — every one renders only the closed
|
|
135
|
+
// trigger, so the per-row selection indicator (the thing corrections.md #026
|
|
136
|
+
// was about) never appeared in a Chromatic snapshot. This story exists
|
|
137
|
+
// specifically to put that row in front of visual regression, not just the
|
|
138
|
+
// lint: clicks the trigger, waits for the real popover content (Popover
|
|
139
|
+
// portals to document.body, same reason Dialog's play function below queries
|
|
140
|
+
// from there), and asserts the pre-checked option's Checkbox primitive
|
|
141
|
+
// reports data-state="checked" — the exact state that used to render as a
|
|
142
|
+
// filled circle instead of a checkbox.
|
|
143
|
+
export const OpenShowingSelection: Story = {
|
|
144
|
+
parameters: { controls: { disable: true } },
|
|
145
|
+
render: () => (
|
|
146
|
+
<ControlledFacetedFilter
|
|
147
|
+
title="Status"
|
|
148
|
+
options={STATUS_OPTIONS}
|
|
149
|
+
defaultSelected={["pending"]}
|
|
150
|
+
/>
|
|
151
|
+
),
|
|
152
|
+
play: async ({ canvasElement }) => {
|
|
153
|
+
const canvas = within(canvasElement)
|
|
154
|
+
await userEvent.click(canvas.getByRole("button", { name: /status/i }))
|
|
155
|
+
const body = within(document.body)
|
|
156
|
+
// Start-anchored, not a bare substring regex (/active/i also matches
|
|
157
|
+
// "Inactive") and not an exact string (the row's accessible name is the
|
|
158
|
+
// label plus the count span's text, e.g. "Pending 17 items").
|
|
159
|
+
const pendingOption = await body.findByRole("option", { name: /^pending\b/i })
|
|
160
|
+
await waitFor(() => expect(pendingOption).toBeVisible())
|
|
161
|
+
const indicator = pendingOption.querySelector('[data-slot="checkbox"]')
|
|
162
|
+
expect(indicator).toHaveAttribute("data-state", "checked")
|
|
163
|
+
const activeOption = body.getByRole("option", { name: /^active\b/i })
|
|
164
|
+
expect(
|
|
165
|
+
activeOption.querySelector('[data-slot="checkbox"]')
|
|
166
|
+
).toHaveAttribute("data-state", "unchecked")
|
|
167
|
+
},
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export const WithIcons: Story = {
|
|
171
|
+
parameters: { controls: { disable: true } },
|
|
172
|
+
render: () => (
|
|
173
|
+
<ControlledFacetedFilter title="Priority" options={PRIORITY_OPTIONS} />
|
|
174
|
+
),
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export const RealisticUse: Story = {
|
|
178
|
+
parameters: { controls: { disable: true } },
|
|
179
|
+
render: () => (
|
|
180
|
+
<div className="flex flex-wrap items-center gap-2 rounded-lg border bg-card p-4">
|
|
181
|
+
<span className="text-sm font-medium text-muted-foreground">
|
|
182
|
+
Filters:
|
|
183
|
+
</span>
|
|
184
|
+
<ControlledFacetedFilter
|
|
185
|
+
title="Status"
|
|
186
|
+
options={USER_STATUS_OPTIONS}
|
|
187
|
+
defaultSelected={["verified"]}
|
|
188
|
+
/>
|
|
189
|
+
<ControlledFacetedFilter title="Role" options={ROLE_OPTIONS} />
|
|
190
|
+
<ControlledFacetedFilter
|
|
191
|
+
title="Team"
|
|
192
|
+
options={TEAM_OPTIONS}
|
|
193
|
+
defaultSelected={["engineering", "design"]}
|
|
194
|
+
/>
|
|
195
|
+
</div>
|
|
196
|
+
),
|
|
197
|
+
}
|