@behavioral-agentic-design-system/core 0.40.0 → 0.42.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 +19 -3
- package/scripts/a11y-lint.cjs +41 -2
- package/scripts/health-report.mjs +16 -2
- package/scripts/lint-slop.mjs +25 -1
- package/scripts/wcag-audit.cjs +72 -5
- package/src/app/opengraph-image.tsx +5 -0
- package/src/app/preview/components/page.tsx +1269 -2
- package/src/app/shell.tsx +8 -5
- package/src/components/Foundations/Motion.stories.tsx +1 -0
- package/src/components/customize/design-controls.tsx +16 -1
- package/src/components/studio/studio.tsx +153 -0
- package/src/components/ui/anchor.tsx +37 -3
- package/src/components/ui/attachment.tsx +211 -0
- package/src/components/ui/chart.tsx +3 -0
- package/src/components/ui/code.tsx +1 -1
- package/src/components/ui/color-picker.tsx +1 -1
- package/src/components/ui/gauge-chart.tsx +238 -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/json-input.tsx +351 -0
- package/src/components/ui/navigation-progress.tsx +281 -0
- package/src/components/ui/number-input.tsx +1 -4
- package/src/components/ui/password-input.tsx +2 -1
- package/src/components/ui/password-strength-input.tsx +288 -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/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/tour.tsx +1 -3
- package/src/data/docs-index.ts +24 -0
- package/src/lib/clamp.ts +2 -0
- package/src/stories/Anchor.stories.tsx +54 -0
- package/src/stories/Attachment.stories.tsx +189 -0
- package/src/stories/Chart.stories.tsx +4 -0
- package/src/stories/Code.stories.tsx +1 -0
- package/src/stories/ColorPicker.stories.tsx +1 -0
- package/src/stories/GaugeChart.stories.tsx +163 -0
- package/src/stories/Heatmap.stories.tsx +172 -0
- package/src/stories/InfiniteScroll.stories.tsx +225 -0
- package/src/stories/JsonInput.stories.tsx +212 -0
- package/src/stories/NavigationProgress.stories.tsx +159 -0
- package/src/stories/NumberInput.stories.tsx +1 -0
- package/src/stories/PasswordInput.stories.tsx +4 -0
- package/src/stories/PasswordStrengthInput.stories.tsx +211 -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/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/Tour.stories.tsx +1 -0
- package/src/stories/story-groups.json +17 -6
- package/LICENSE +0 -21
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// Motion: the remove control is a CloseButton, so hover/focus/press inherit
|
|
2
|
+
// Button's token-driven transition-colors; the chip itself has no entrance
|
|
3
|
+
// or exit animation (removal is an undo — it should be instant).
|
|
4
|
+
import type { Meta, StoryObj } from "@storybook/react"
|
|
5
|
+
import * as React from "react"
|
|
6
|
+
import { Paperclip, SendHorizontal } from "lucide-react"
|
|
7
|
+
|
|
8
|
+
import { Attachment } from "@behavioral-agentic-design-system/core/components/ui/attachment"
|
|
9
|
+
import { Button } from "@behavioral-agentic-design-system/core/components/ui/button"
|
|
10
|
+
import { Card } from "@behavioral-agentic-design-system/core/components/ui/card"
|
|
11
|
+
import { Textarea } from "@behavioral-agentic-design-system/core/components/ui/textarea"
|
|
12
|
+
|
|
13
|
+
// File names and byte counts from content/personas/bads.json → files[].
|
|
14
|
+
const FILES = {
|
|
15
|
+
roiReport: { name: "roi-report-2026-06.pdf", bytes: 1_536_000, type: "application/pdf" },
|
|
16
|
+
favicon: { name: "favicon.svg", bytes: 500, type: "image/svg+xml" },
|
|
17
|
+
styles: { name: "styles.css", bytes: 42_700, type: "text/css" },
|
|
18
|
+
brandFonts: { name: "brand-fonts.woff2", bytes: 84_512, type: "font/woff2" },
|
|
19
|
+
figProposal: { name: "tokens-v2-proposal.fig", bytes: 24_618_034, type: "" },
|
|
20
|
+
snapshots: {
|
|
21
|
+
name: "chromatic-snapshots-2026-06.zip",
|
|
22
|
+
bytes: 1_073_741_824,
|
|
23
|
+
type: "application/zip",
|
|
24
|
+
},
|
|
25
|
+
} as const
|
|
26
|
+
|
|
27
|
+
const meta: Meta<typeof Attachment> = {
|
|
28
|
+
title: "Components/Badges and avatars/Attachment",
|
|
29
|
+
component: Attachment,
|
|
30
|
+
tags: ["autodocs"],
|
|
31
|
+
parameters: {
|
|
32
|
+
layout: "centered",
|
|
33
|
+
docs: {
|
|
34
|
+
description: {
|
|
35
|
+
component:
|
|
36
|
+
"Pre-send file chip for a chat composer: file-type icon (picked from the MIME type, falling back to the extension), truncated name with the full value on title, formatted size via FormatByte, and a 44px CloseButton remove control labeled 'Remove <name>'. The root is role='group' with aria-label 'Attached file: <name>'. Omit onRemove for a read-only chip. Not a drop zone (FileUpload) and not a post-send card (FileCard).",
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
args: {
|
|
41
|
+
onRemove: () => {},
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default meta
|
|
46
|
+
type Story = StoryObj<typeof Attachment>
|
|
47
|
+
|
|
48
|
+
export const Default: Story = {
|
|
49
|
+
args: {
|
|
50
|
+
fileName: FILES.roiReport.name,
|
|
51
|
+
fileSize: FILES.roiReport.bytes,
|
|
52
|
+
fileType: FILES.roiReport.type,
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const ImageAttachment: Story = {
|
|
57
|
+
args: {
|
|
58
|
+
fileName: FILES.favicon.name,
|
|
59
|
+
fileSize: FILES.favicon.bytes,
|
|
60
|
+
fileType: FILES.favicon.type,
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const CodeAttachment: Story = {
|
|
65
|
+
args: {
|
|
66
|
+
fileName: FILES.styles.name,
|
|
67
|
+
fileSize: FILES.styles.bytes,
|
|
68
|
+
fileType: FILES.styles.type,
|
|
69
|
+
},
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** A long archive name truncates; the full name stays on title and in the group label. */
|
|
73
|
+
export const LargeFile: Story = {
|
|
74
|
+
args: {
|
|
75
|
+
fileName: FILES.snapshots.name,
|
|
76
|
+
fileSize: FILES.snapshots.bytes,
|
|
77
|
+
fileType: FILES.snapshots.type,
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Unknown MIME type (the browser reports "" for .fig) — the extension fallback picks the generic icon. */
|
|
82
|
+
export const UnknownType: Story = {
|
|
83
|
+
args: {
|
|
84
|
+
fileName: FILES.figProposal.name,
|
|
85
|
+
fileSize: FILES.figProposal.bytes,
|
|
86
|
+
fileType: FILES.figProposal.type,
|
|
87
|
+
},
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** No onRemove → the remove button is not rendered; the chip is read-only. */
|
|
91
|
+
export const ReadOnly: Story = {
|
|
92
|
+
args: {
|
|
93
|
+
fileName: FILES.brandFonts.name,
|
|
94
|
+
fileSize: FILES.brandFonts.bytes,
|
|
95
|
+
fileType: FILES.brandFonts.type,
|
|
96
|
+
onRemove: undefined,
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Dimmed, remove control disabled — the state while the message is sending. */
|
|
101
|
+
export const Disabled: Story = {
|
|
102
|
+
args: {
|
|
103
|
+
fileName: FILES.roiReport.name,
|
|
104
|
+
fileSize: FILES.roiReport.bytes,
|
|
105
|
+
fileType: FILES.roiReport.type,
|
|
106
|
+
disabled: true,
|
|
107
|
+
},
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function ComposerDemo() {
|
|
111
|
+
const [attached, setAttached] = React.useState<
|
|
112
|
+
Array<{ name: string; bytes: number; type: string }>
|
|
113
|
+
>([FILES.roiReport, FILES.styles, FILES.snapshots])
|
|
114
|
+
const [sending, setSending] = React.useState(false)
|
|
115
|
+
// Removing a chip unmounts the focused button; send focus back to the
|
|
116
|
+
// composer so a keyboard user is not dropped on <body>. The component
|
|
117
|
+
// leaves this to the consumer on purpose — only the composer knows where
|
|
118
|
+
// "back" is.
|
|
119
|
+
const composerRef = React.useRef<HTMLTextAreaElement>(null)
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<Card className="w-[28rem] max-w-full gap-0 p-3">
|
|
123
|
+
<Textarea
|
|
124
|
+
ref={composerRef}
|
|
125
|
+
aria-label="Message to Jordan Reeves"
|
|
126
|
+
placeholder="Message Jordan Reeves"
|
|
127
|
+
defaultValue="Here's the June ROI export, the generated stylesheet, and last quarter's Chromatic baseline."
|
|
128
|
+
className="min-h-20 resize-none border-0 bg-transparent px-1 shadow-none focus-visible:ring-0"
|
|
129
|
+
/>
|
|
130
|
+
{attached.length > 0 && (
|
|
131
|
+
<div className="mt-2 flex flex-wrap gap-2 px-1" aria-label="Attachments">
|
|
132
|
+
{attached.map((f) => (
|
|
133
|
+
<Attachment
|
|
134
|
+
key={f.name}
|
|
135
|
+
fileName={f.name}
|
|
136
|
+
fileSize={f.bytes}
|
|
137
|
+
fileType={f.type}
|
|
138
|
+
disabled={sending}
|
|
139
|
+
onRemove={() => {
|
|
140
|
+
setAttached((prev) => prev.filter((p) => p.name !== f.name))
|
|
141
|
+
composerRef.current?.focus()
|
|
142
|
+
}}
|
|
143
|
+
/>
|
|
144
|
+
))}
|
|
145
|
+
</div>
|
|
146
|
+
)}
|
|
147
|
+
<div className="mt-3 flex items-center justify-between gap-2">
|
|
148
|
+
<Button
|
|
149
|
+
type="button"
|
|
150
|
+
variant="ghost"
|
|
151
|
+
size="icon-xl"
|
|
152
|
+
aria-label="Attach a file"
|
|
153
|
+
disabled={sending}
|
|
154
|
+
onClick={() =>
|
|
155
|
+
setAttached((prev) =>
|
|
156
|
+
prev.some((p) => p.name === FILES.favicon.name)
|
|
157
|
+
? prev
|
|
158
|
+
: [...prev, FILES.favicon]
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
>
|
|
162
|
+
<Paperclip strokeWidth={1.5} aria-hidden="true" />
|
|
163
|
+
</Button>
|
|
164
|
+
<Button
|
|
165
|
+
type="button"
|
|
166
|
+
size="xl"
|
|
167
|
+
disabled={sending}
|
|
168
|
+
loading={sending}
|
|
169
|
+
onClick={() => {
|
|
170
|
+
setSending(true)
|
|
171
|
+
window.setTimeout(() => {
|
|
172
|
+
setSending(false)
|
|
173
|
+
setAttached([])
|
|
174
|
+
}, 1200)
|
|
175
|
+
}}
|
|
176
|
+
>
|
|
177
|
+
<SendHorizontal strokeWidth={1.5} aria-hidden="true" />
|
|
178
|
+
Send
|
|
179
|
+
</Button>
|
|
180
|
+
</div>
|
|
181
|
+
</Card>
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Three chips inside a composer. Remove one, re-attach via the paperclip, send to watch the disabled state. */
|
|
186
|
+
export const RealisticUse: Story = {
|
|
187
|
+
render: () => <ComposerDemo />,
|
|
188
|
+
parameters: { controls: { disable: true } },
|
|
189
|
+
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// ChartContainer's dot-fade-in keyframe + per-series --color-* custom
|
|
2
|
+
// properties are generated per instance via a raw <style> tag scoped to a
|
|
3
|
+
// runtime [data-chart=<id>] selector — see the escape-hatch note on that
|
|
4
|
+
// <style> element in chart.tsx for why (scripts/lint-inline-styles.mjs).
|
|
1
5
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
6
|
import {
|
|
3
7
|
ChartContainer,
|
|
@@ -52,6 +52,7 @@ export const Variant_Block: Story = {
|
|
|
52
52
|
// Long, non-wrapping lines overflow the container (whitespace-pre), so the block
|
|
53
53
|
// becomes a horizontal scroll region. tabIndex={0} makes it keyboard-reachable
|
|
54
54
|
// and it shows the system focus-visible ring when focused (a11y: SC 2.1.1 / 2.4.7).
|
|
55
|
+
// Scrollbar styled via native CSS: [scrollbar-width:thin] [scrollbar-color:...]
|
|
55
56
|
export const Variant_Block_Scroll: Story = {
|
|
56
57
|
render: () => (
|
|
57
58
|
<div className="w-[360px]">
|
|
@@ -0,0 +1,163 @@
|
|
|
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 follows the shared `useReducedMotion` hook
|
|
34
|
+
// (hooks/use-reduced-motion), the same one ChartContainer and Sparkline read,
|
|
35
|
+
// so a reduced-motion user gets the final arc immediately in every story.
|
|
36
|
+
export const Default: Story = {
|
|
37
|
+
render: (args) => (
|
|
38
|
+
<div className="w-48">
|
|
39
|
+
<GaugeChart {...args} />
|
|
40
|
+
</div>
|
|
41
|
+
),
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// All five Okabe-Ito series colors on the same reading, so the track/fill
|
|
45
|
+
// relationship can be judged per hue. Five gauges can't be driven from one
|
|
46
|
+
// set of args, so the Controls panel is disabled rather than left inert
|
|
47
|
+
// (check:story-controls).
|
|
48
|
+
export const Colors: Story = {
|
|
49
|
+
parameters: { controls: { disable: true } },
|
|
50
|
+
render: () => (
|
|
51
|
+
<div className="flex flex-wrap items-end justify-center gap-6">
|
|
52
|
+
{[1, 2, 3, 4, 5].map((n) => (
|
|
53
|
+
<div key={n} className="flex w-32 flex-col items-center gap-2">
|
|
54
|
+
<GaugeChart
|
|
55
|
+
value={72}
|
|
56
|
+
size="sm"
|
|
57
|
+
color={`var(--chart-${n})`}
|
|
58
|
+
aria-label={`Sample reading in chart color ${n}`}
|
|
59
|
+
/>
|
|
60
|
+
<code className="text-xs text-muted-foreground">--chart-{n}</code>
|
|
61
|
+
</div>
|
|
62
|
+
))}
|
|
63
|
+
</div>
|
|
64
|
+
),
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const WithLabel: Story = {
|
|
68
|
+
args: { value: 85, label: "CPU usage" },
|
|
69
|
+
render: (args) => (
|
|
70
|
+
<div className="w-48">
|
|
71
|
+
<GaugeChart {...args} />
|
|
72
|
+
</div>
|
|
73
|
+
),
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const Sizes: Story = {
|
|
77
|
+
parameters: { controls: { disable: true } },
|
|
78
|
+
render: () => (
|
|
79
|
+
<div className="flex flex-wrap items-end justify-center gap-6">
|
|
80
|
+
{(["sm", "md", "lg", "xl"] as const).map((size) => (
|
|
81
|
+
<div key={size} className="flex flex-col items-center gap-2">
|
|
82
|
+
<GaugeChart
|
|
83
|
+
value={72}
|
|
84
|
+
size={size}
|
|
85
|
+
label="Coverage"
|
|
86
|
+
className="w-auto"
|
|
87
|
+
style={{ width: { sm: 120, md: 160, lg: 200, xl: 240 }[size] }}
|
|
88
|
+
/>
|
|
89
|
+
<code className="text-xs text-muted-foreground">{size}</code>
|
|
90
|
+
</div>
|
|
91
|
+
))}
|
|
92
|
+
</div>
|
|
93
|
+
),
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Percent readings render "98%" rather than "98"; the same formatter feeds
|
|
97
|
+
// aria-valuetext, so the visible and announced strings can't diverge.
|
|
98
|
+
export const CustomFormat: Story = {
|
|
99
|
+
args: {
|
|
100
|
+
value: 98.4,
|
|
101
|
+
label: "Story coverage",
|
|
102
|
+
formatValue: (v: number) =>
|
|
103
|
+
new Intl.NumberFormat(undefined, {
|
|
104
|
+
style: "percent",
|
|
105
|
+
maximumFractionDigits: 1,
|
|
106
|
+
}).format(v / 100),
|
|
107
|
+
},
|
|
108
|
+
render: (args) => (
|
|
109
|
+
<div className="w-48">
|
|
110
|
+
<GaugeChart {...args} />
|
|
111
|
+
</div>
|
|
112
|
+
),
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Story coverage 98.4% and 88 registry components come from
|
|
116
|
+
// content/personas/bads.json → primary.metrics. The three supporting gauges
|
|
117
|
+
// reuse the palette in order (chart-1..3) with the hero at chart-1.
|
|
118
|
+
export const RealisticUse: Story = {
|
|
119
|
+
parameters: { controls: { disable: true } },
|
|
120
|
+
render: () => (
|
|
121
|
+
<Card className="w-[480px]">
|
|
122
|
+
<CardHeader>
|
|
123
|
+
<CardTitle>System health</CardTitle>
|
|
124
|
+
<CardDescription>
|
|
125
|
+
BADS core — nightly gate run, 2026-09-15
|
|
126
|
+
</CardDescription>
|
|
127
|
+
</CardHeader>
|
|
128
|
+
<CardContent className="flex flex-col gap-6">
|
|
129
|
+
<div className="flex justify-center">
|
|
130
|
+
<GaugeChart value={67} label="Overall" size="lg" className="w-52" />
|
|
131
|
+
</div>
|
|
132
|
+
<div className="grid grid-cols-3 gap-4">
|
|
133
|
+
<div className="flex flex-col items-center gap-1">
|
|
134
|
+
<GaugeChart
|
|
135
|
+
value={98.4}
|
|
136
|
+
label="Story coverage"
|
|
137
|
+
size="sm"
|
|
138
|
+
formatValue={(v) => `${v.toFixed(1)}%`}
|
|
139
|
+
/>
|
|
140
|
+
</div>
|
|
141
|
+
<div className="flex flex-col items-center gap-1">
|
|
142
|
+
<GaugeChart
|
|
143
|
+
value={88}
|
|
144
|
+
max={120}
|
|
145
|
+
label="Registry entries"
|
|
146
|
+
size="sm"
|
|
147
|
+
color="var(--chart-2)"
|
|
148
|
+
/>
|
|
149
|
+
</div>
|
|
150
|
+
<div className="flex flex-col items-center gap-1">
|
|
151
|
+
<GaugeChart
|
|
152
|
+
value={4}
|
|
153
|
+
max={12}
|
|
154
|
+
label="Open advisories"
|
|
155
|
+
size="sm"
|
|
156
|
+
color="var(--chart-3)"
|
|
157
|
+
/>
|
|
158
|
+
</div>
|
|
159
|
+
</div>
|
|
160
|
+
</CardContent>
|
|
161
|
+
</Card>
|
|
162
|
+
),
|
|
163
|
+
}
|
|
@@ -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
|
+
};
|