@behavioral-agentic-design-system/core 0.40.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/README.md +2 -0
- package/package.json +41 -9
- package/scripts/a11y-lint.cjs +66 -3
- package/scripts/check-spec.mjs +73 -0
- package/scripts/deal-directions.mjs +186 -0
- package/scripts/health-report.mjs +23 -3
- 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/lint-slop.mjs +25 -1
- 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/scripts/wcag-audit.cjs +72 -5
- 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/opengraph-image.tsx +5 -0
- package/src/app/preview/canvas/page.tsx +12 -0
- package/src/app/preview/components/page.tsx +2003 -2
- package/src/app/preview/studio/blank-screen.tsx +143 -0
- package/src/app/preview/studio/page.tsx +7 -0
- package/src/app/shell.tsx +168 -49
- package/src/components/Foundations/Motion.stories.tsx +1 -0
- 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/customize/design-controls.tsx +16 -1
- 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 +158 -0
- 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/anchor.tsx +37 -3
- package/src/components/ui/attachment.tsx +211 -0
- package/src/components/ui/autocomplete.tsx +1 -1
- package/src/components/ui/chart.tsx +3 -0
- package/src/components/ui/code.tsx +1 -1
- package/src/components/ui/color-picker.tsx +21 -5
- 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 +252 -0
- package/src/components/ui/heatmap.tsx +256 -0
- package/src/components/ui/index.ts +9 -0
- package/src/components/ui/infinite-scroll.tsx +103 -0
- package/src/components/ui/inline-edit.tsx +175 -0
- package/src/components/ui/json-input.tsx +351 -0
- package/src/components/ui/month-picker.tsx +1 -1
- package/src/components/ui/navigation-progress.tsx +281 -0
- package/src/components/ui/number-input.tsx +27 -7
- package/src/components/ui/otp-input.tsx +208 -0
- package/src/components/ui/password-input.tsx +2 -1
- package/src/components/ui/password-strength-input.tsx +288 -0
- package/src/components/ui/phone-input.tsx +274 -0
- package/src/components/ui/pill.tsx +140 -0
- package/src/components/ui/popover.tsx +27 -4
- package/src/components/ui/scroll-progress.tsx +100 -0
- package/src/components/ui/search-input.tsx +1 -1
- package/src/components/ui/snackbar.tsx +393 -0
- package/src/components/ui/sortable-list.tsx +342 -0
- package/src/components/ui/squircle.tsx +1 -1
- package/src/components/ui/table.tsx +1 -1
- package/src/components/ui/tags-input.tsx +1 -1
- package/src/components/ui/timer.tsx +1 -0
- package/src/components/ui/tour.tsx +1 -3
- 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 +36 -0
- 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/clamp.ts +2 -0
- package/src/lib/spec-parse.ts +4 -0
- package/src/lib/svg-sanitize.ts +19 -9
- package/src/stories/Anchor.stories.tsx +54 -0
- package/src/stories/Attachment.stories.tsx +189 -0
- package/src/stories/Autocomplete.stories.tsx +2 -0
- package/src/stories/Canvas.stories.tsx +45 -0
- package/src/stories/Chart.stories.tsx +4 -0
- package/src/stories/Code.stories.tsx +1 -0
- package/src/stories/ColorPicker.stories.tsx +41 -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 +169 -0
- package/src/stories/Heatmap.stories.tsx +172 -0
- package/src/stories/InfiniteScroll.stories.tsx +225 -0
- package/src/stories/InlineEdit.stories.tsx +106 -0
- package/src/stories/JsonInput.stories.tsx +212 -0
- package/src/stories/MarkdownPreview.stories.tsx +53 -0
- package/src/stories/MonthPicker.stories.tsx +21 -0
- package/src/stories/NavigationProgress.stories.tsx +159 -0
- package/src/stories/NumberInput.stories.tsx +26 -0
- package/src/stories/OtpInput.stories.tsx +110 -0
- package/src/stories/PasswordInput.stories.tsx +4 -0
- package/src/stories/PasswordStrengthInput.stories.tsx +211 -0
- package/src/stories/PhoneInput.stories.tsx +127 -0
- package/src/stories/Pill.stories.tsx +201 -0
- package/src/stories/Popover.stories.tsx +29 -1
- package/src/stories/Portal.stories.tsx +3 -1
- package/src/stories/ScrollProgress.stories.tsx +117 -0
- package/src/stories/SearchInput.stories.tsx +2 -0
- package/src/stories/Snackbar.stories.tsx +315 -0
- package/src/stories/SortableList.stories.tsx +263 -0
- package/src/stories/Squircle.stories.tsx +1 -0
- package/src/stories/Table.stories.tsx +1 -0
- package/src/stories/TagsInput.stories.tsx +2 -0
- package/src/stories/Timer.stories.tsx +26 -0
- package/src/stories/Tour.stories.tsx +1 -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 +33 -16
- package/src/tokens.json +82 -54
|
@@ -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
|
|
@@ -228,3 +268,4 @@ export const RealisticUse: Story = {
|
|
|
228
268
|
);
|
|
229
269
|
},
|
|
230
270
|
};
|
|
271
|
+
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import type { Meta, StoryObj } from "@storybook/react"
|
|
3
|
+
import { GaugeChart } from "@behavioral-agentic-design-system/core/components/ui/gauge-chart"
|
|
4
|
+
import {
|
|
5
|
+
Card,
|
|
6
|
+
CardContent,
|
|
7
|
+
CardDescription,
|
|
8
|
+
CardHeader,
|
|
9
|
+
CardTitle,
|
|
10
|
+
} from "@behavioral-agentic-design-system/core/components/ui/card"
|
|
11
|
+
|
|
12
|
+
const meta: Meta<typeof GaugeChart> = {
|
|
13
|
+
title: "Components/Content and data/GaugeChart",
|
|
14
|
+
component: GaugeChart,
|
|
15
|
+
parameters: { layout: "centered" },
|
|
16
|
+
tags: ["autodocs"],
|
|
17
|
+
argTypes: {
|
|
18
|
+
value: { control: { type: "range", min: 0, max: 100, step: 1 } },
|
|
19
|
+
min: { control: "number" },
|
|
20
|
+
max: { control: "number" },
|
|
21
|
+
label: { control: "text" },
|
|
22
|
+
size: { control: "select", options: ["sm", "md", "lg", "xl"] },
|
|
23
|
+
color: { control: "text" },
|
|
24
|
+
},
|
|
25
|
+
args: {
|
|
26
|
+
value: 72,
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default meta
|
|
31
|
+
type Story = StoryObj<typeof meta>
|
|
32
|
+
|
|
33
|
+
// The entrance draw-in reads reduced-motion synchronously at mount (via
|
|
34
|
+
// hooks/use-reduced-motion's `prefersReducedMotion()`), not through the
|
|
35
|
+
// reactive `useReducedMotion()` hook ChartContainer and Sparkline use. The
|
|
36
|
+
// reactive hook starts `false` on every render and corrects a tick later;
|
|
37
|
+
// if that correction landed after react-smooth had already started tweening
|
|
38
|
+
// the value arc, Recharts froze on the near-zero-angle interpolated frame
|
|
39
|
+
// instead of jumping to the final one, so a reduced-motion user could see
|
|
40
|
+
// the value arc render as permanently invisible. Reading synchronously
|
|
41
|
+
// means a reduced-motion user gets the final arc immediately in every story.
|
|
42
|
+
export const Default: Story = {
|
|
43
|
+
render: (args) => (
|
|
44
|
+
<div className="w-48">
|
|
45
|
+
<GaugeChart {...args} />
|
|
46
|
+
</div>
|
|
47
|
+
),
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// All five Okabe-Ito series colors on the same reading, so the track/fill
|
|
51
|
+
// relationship can be judged per hue. Five gauges can't be driven from one
|
|
52
|
+
// set of args, so the Controls panel is disabled rather than left inert
|
|
53
|
+
// (check:story-controls).
|
|
54
|
+
export const Colors: Story = {
|
|
55
|
+
parameters: { controls: { disable: true } },
|
|
56
|
+
render: () => (
|
|
57
|
+
<div className="flex flex-wrap items-end justify-center gap-6">
|
|
58
|
+
{[1, 2, 3, 4, 5].map((n) => (
|
|
59
|
+
<div key={n} className="flex w-32 flex-col items-center gap-2">
|
|
60
|
+
<GaugeChart
|
|
61
|
+
value={72}
|
|
62
|
+
size="sm"
|
|
63
|
+
color={`var(--chart-${n})`}
|
|
64
|
+
aria-label={`Sample reading in chart color ${n}`}
|
|
65
|
+
/>
|
|
66
|
+
<code className="text-xs text-muted-foreground">--chart-{n}</code>
|
|
67
|
+
</div>
|
|
68
|
+
))}
|
|
69
|
+
</div>
|
|
70
|
+
),
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const WithLabel: Story = {
|
|
74
|
+
args: { value: 85, label: "CPU usage" },
|
|
75
|
+
render: (args) => (
|
|
76
|
+
<div className="w-48">
|
|
77
|
+
<GaugeChart {...args} />
|
|
78
|
+
</div>
|
|
79
|
+
),
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const Sizes: Story = {
|
|
83
|
+
parameters: { controls: { disable: true } },
|
|
84
|
+
render: () => (
|
|
85
|
+
<div className="flex flex-wrap items-end justify-center gap-6">
|
|
86
|
+
{(["sm", "md", "lg", "xl"] as const).map((size) => (
|
|
87
|
+
<div key={size} className="flex flex-col items-center gap-2">
|
|
88
|
+
<GaugeChart
|
|
89
|
+
value={72}
|
|
90
|
+
size={size}
|
|
91
|
+
label="Coverage"
|
|
92
|
+
className="w-auto"
|
|
93
|
+
style={{ width: { sm: 120, md: 160, lg: 200, xl: 240 }[size] }}
|
|
94
|
+
/>
|
|
95
|
+
<code className="text-xs text-muted-foreground">{size}</code>
|
|
96
|
+
</div>
|
|
97
|
+
))}
|
|
98
|
+
</div>
|
|
99
|
+
),
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Percent readings render "98%" rather than "98"; the same formatter feeds
|
|
103
|
+
// aria-valuetext, so the visible and announced strings can't diverge.
|
|
104
|
+
export const CustomFormat: Story = {
|
|
105
|
+
args: {
|
|
106
|
+
value: 98.4,
|
|
107
|
+
label: "Story coverage",
|
|
108
|
+
formatValue: (v: number) =>
|
|
109
|
+
new Intl.NumberFormat(undefined, {
|
|
110
|
+
style: "percent",
|
|
111
|
+
maximumFractionDigits: 1,
|
|
112
|
+
}).format(v / 100),
|
|
113
|
+
},
|
|
114
|
+
render: (args) => (
|
|
115
|
+
<div className="w-48">
|
|
116
|
+
<GaugeChart {...args} />
|
|
117
|
+
</div>
|
|
118
|
+
),
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Story coverage 98.4% and 88 registry components come from
|
|
122
|
+
// content/personas/bads.json → primary.metrics. The three supporting gauges
|
|
123
|
+
// reuse the palette in order (chart-1..3) with the hero at chart-1.
|
|
124
|
+
export const RealisticUse: Story = {
|
|
125
|
+
parameters: { controls: { disable: true } },
|
|
126
|
+
render: () => (
|
|
127
|
+
<Card className="w-[480px]">
|
|
128
|
+
<CardHeader>
|
|
129
|
+
<CardTitle>System health</CardTitle>
|
|
130
|
+
<CardDescription>
|
|
131
|
+
BADS core — nightly gate run, 2026-09-15
|
|
132
|
+
</CardDescription>
|
|
133
|
+
</CardHeader>
|
|
134
|
+
<CardContent className="flex flex-col gap-6">
|
|
135
|
+
<div className="flex justify-center">
|
|
136
|
+
<GaugeChart value={67} label="Overall" size="lg" className="w-52" />
|
|
137
|
+
</div>
|
|
138
|
+
<div className="grid grid-cols-3 gap-4">
|
|
139
|
+
<div className="flex flex-col items-center gap-1">
|
|
140
|
+
<GaugeChart
|
|
141
|
+
value={98.4}
|
|
142
|
+
label="Story coverage"
|
|
143
|
+
size="sm"
|
|
144
|
+
formatValue={(v) => `${v.toFixed(1)}%`}
|
|
145
|
+
/>
|
|
146
|
+
</div>
|
|
147
|
+
<div className="flex flex-col items-center gap-1">
|
|
148
|
+
<GaugeChart
|
|
149
|
+
value={88}
|
|
150
|
+
max={120}
|
|
151
|
+
label="Registry entries"
|
|
152
|
+
size="sm"
|
|
153
|
+
color="var(--chart-2)"
|
|
154
|
+
/>
|
|
155
|
+
</div>
|
|
156
|
+
<div className="flex flex-col items-center gap-1">
|
|
157
|
+
<GaugeChart
|
|
158
|
+
value={4}
|
|
159
|
+
max={12}
|
|
160
|
+
label="Open advisories"
|
|
161
|
+
size="sm"
|
|
162
|
+
color="var(--chart-3)"
|
|
163
|
+
/>
|
|
164
|
+
</div>
|
|
165
|
+
</div>
|
|
166
|
+
</CardContent>
|
|
167
|
+
</Card>
|
|
168
|
+
),
|
|
169
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// "use client" added to heatmap.tsx (useCallback + useMemo hooks)
|
|
2
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
3
|
+
import { Heatmap } from "@behavioral-agentic-design-system/core/components/ui/heatmap";
|
|
4
|
+
import {
|
|
5
|
+
Card,
|
|
6
|
+
CardContent,
|
|
7
|
+
CardDescription,
|
|
8
|
+
CardHeader,
|
|
9
|
+
CardTitle,
|
|
10
|
+
} from "@behavioral-agentic-design-system/core/components/ui/card";
|
|
11
|
+
|
|
12
|
+
// Content from content/personas/bads.json → primary (Jordan Reeves, Fieldnote
|
|
13
|
+
// Labs, design-system jargon). Data is generated by a seeded LCG so every
|
|
14
|
+
// render — and every Chromatic snapshot — is byte-identical. No Math.random.
|
|
15
|
+
function seeded(seed: number) {
|
|
16
|
+
let s = seed >>> 0;
|
|
17
|
+
return () => {
|
|
18
|
+
s = (s * 1664525 + 1013904223) >>> 0;
|
|
19
|
+
return s / 0x100000000;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function matrix(rowCount: number, colCount: number, seed: number, max = 24) {
|
|
24
|
+
const next = seeded(seed);
|
|
25
|
+
return Array.from({ length: rowCount }, (_, r) =>
|
|
26
|
+
Array.from({ length: colCount }, (_, c) => {
|
|
27
|
+
// Weekends and early columns run quieter so the ramp has structure.
|
|
28
|
+
const weight = r >= 5 ? 0.35 : 1;
|
|
29
|
+
const ramp = 0.4 + (c / Math.max(1, colCount - 1)) * 0.6;
|
|
30
|
+
return Math.round(next() * max * weight * ramp);
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const WEEKDAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
|
|
36
|
+
const weeks = (n: number) => Array.from({ length: n }, (_, i) => `W${i + 1}`);
|
|
37
|
+
|
|
38
|
+
const meta: Meta<typeof Heatmap> = {
|
|
39
|
+
title: "Components/Content and data/Heatmap",
|
|
40
|
+
component: Heatmap,
|
|
41
|
+
parameters: { layout: "centered" },
|
|
42
|
+
tags: ["autodocs"],
|
|
43
|
+
argTypes: {
|
|
44
|
+
size: { control: "select", options: ["sm", "md", "lg"] },
|
|
45
|
+
color: { control: "text" },
|
|
46
|
+
showLegend: { control: "boolean" },
|
|
47
|
+
label: { control: "text" },
|
|
48
|
+
},
|
|
49
|
+
args: {
|
|
50
|
+
rows: WEEKDAYS,
|
|
51
|
+
columns: weeks(12),
|
|
52
|
+
data: matrix(7, 12, 7),
|
|
53
|
+
label: "Token commits by weekday, last 12 weeks",
|
|
54
|
+
formatValue: (v: number) => `${v} commits`,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export default meta;
|
|
59
|
+
type Story = StoryObj<typeof meta>;
|
|
60
|
+
|
|
61
|
+
export const Default: Story = {};
|
|
62
|
+
|
|
63
|
+
export const Size_SM: Story = {
|
|
64
|
+
args: { size: "sm" },
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const Size_MD: Story = {
|
|
68
|
+
args: { size: "md" },
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const Size_LG: Story = {
|
|
72
|
+
args: { size: "lg" },
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// One series color, always from the chart palette. Vermillion (--chart-2) is
|
|
76
|
+
// the second categorical color; here it distinguishes "review comments" from
|
|
77
|
+
// the commits matrix on the same dashboard.
|
|
78
|
+
export const SeriesColor: Story = {
|
|
79
|
+
args: {
|
|
80
|
+
color: "var(--chart-2)",
|
|
81
|
+
label: "Review comments by weekday, last 12 weeks",
|
|
82
|
+
formatValue: (v: number) => `${v} comments`,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// Null cells are "no data" (a quiet muted/50 swatch, announced as "No data"),
|
|
87
|
+
// distinct from level 0 which is a real lowest-bucket value.
|
|
88
|
+
export const WithMissingData: Story = {
|
|
89
|
+
args: {
|
|
90
|
+
columns: weeks(8),
|
|
91
|
+
data: matrix(7, 8, 11).map((row, r) =>
|
|
92
|
+
row.map((v, c) => (c > 5 && r > 3 ? null : v)),
|
|
93
|
+
),
|
|
94
|
+
label: "Token commits by weekday — weeks 7 and 8 not yet synced",
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// A fixed domain lets several heatmaps share one scale, so 12 commits reads
|
|
99
|
+
// the same shade in every card of a row.
|
|
100
|
+
export const FixedDomain: Story = {
|
|
101
|
+
args: {
|
|
102
|
+
domain: [0, 40],
|
|
103
|
+
columns: weeks(8),
|
|
104
|
+
data: matrix(7, 8, 3, 18),
|
|
105
|
+
label: "Token commits, scaled 0–40 so cards across the row match",
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export const NoLegend: Story = {
|
|
110
|
+
args: { showLegend: false, columns: weeks(8), data: matrix(7, 8, 5) },
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// Scroll-region coverage (corrections #019): 52 columns inside a 420px box.
|
|
114
|
+
// The root is tabIndex=0 + role=region so a keyboard user can scroll it;
|
|
115
|
+
// the axe suite only sees that if a story actually overflows.
|
|
116
|
+
export const WideOverflowing: Story = {
|
|
117
|
+
parameters: { controls: { disable: true } },
|
|
118
|
+
render: (args) => (
|
|
119
|
+
<div className="w-[420px] rounded-lg border p-4">
|
|
120
|
+
<Heatmap
|
|
121
|
+
{...args}
|
|
122
|
+
columns={weeks(52)}
|
|
123
|
+
data={matrix(7, 52, 19)}
|
|
124
|
+
label="Token commits by weekday, 52 weeks — scrolls horizontally"
|
|
125
|
+
/>
|
|
126
|
+
</div>
|
|
127
|
+
),
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// Hour × weekday usage: the "when does the team hit the system" matrix. Row
|
|
131
|
+
// labels are hours, so the matrix is tall and narrow; sm cells keep it inside
|
|
132
|
+
// a card.
|
|
133
|
+
export const HourByWeekday: Story = {
|
|
134
|
+
parameters: { controls: { disable: true } },
|
|
135
|
+
render: (args) => (
|
|
136
|
+
<Heatmap
|
|
137
|
+
{...args}
|
|
138
|
+
size="sm"
|
|
139
|
+
rows={Array.from({ length: 12 }, (_, h) => `${h + 8}:00`)}
|
|
140
|
+
columns={WEEKDAYS.slice(0, 5)}
|
|
141
|
+
data={matrix(12, 5, 23, 60)}
|
|
142
|
+
label="Storybook sessions by hour and weekday, Fieldnote Labs"
|
|
143
|
+
formatValue={(v: number) => `${v} sessions`}
|
|
144
|
+
/>
|
|
145
|
+
),
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// Contribution calendar on a profile card — the register this primitive is
|
|
149
|
+
// most often reached for. Real names and orgs from the persona pool.
|
|
150
|
+
export const RealisticUse: Story = {
|
|
151
|
+
parameters: { controls: { disable: true } },
|
|
152
|
+
render: () => (
|
|
153
|
+
<Card className="w-[520px]">
|
|
154
|
+
<CardHeader>
|
|
155
|
+
<CardTitle className="text-base">Jordan Reeves · token commits</CardTitle>
|
|
156
|
+
<CardDescription>
|
|
157
|
+
Fieldnote Labs design-tokens repo, last 16 weeks. 412 commits, busiest
|
|
158
|
+
on Wednesdays.
|
|
159
|
+
</CardDescription>
|
|
160
|
+
</CardHeader>
|
|
161
|
+
<CardContent>
|
|
162
|
+
<Heatmap
|
|
163
|
+
rows={WEEKDAYS}
|
|
164
|
+
columns={weeks(16)}
|
|
165
|
+
data={matrix(7, 16, 42)}
|
|
166
|
+
label="Jordan Reeves token commits by weekday, last 16 weeks"
|
|
167
|
+
formatValue={(v: number) => `${v} commits`}
|
|
168
|
+
/>
|
|
169
|
+
</CardContent>
|
|
170
|
+
</Card>
|
|
171
|
+
),
|
|
172
|
+
};
|