@behavioral-agentic-design-system/core 0.39.1 → 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.
Files changed (115) hide show
  1. package/README.md +2 -0
  2. package/package.json +26 -5
  3. package/scripts/a11y-lint.cjs +88 -8
  4. package/scripts/bads-components.mjs +118 -0
  5. package/scripts/build-tokens.cjs +133 -12
  6. package/scripts/check-stories.mjs +1 -1
  7. package/scripts/health-report.mjs +16 -2
  8. package/scripts/lint-component-source.mjs +100 -0
  9. package/scripts/lint-microanimation.mjs +267 -0
  10. package/scripts/lint-slop.mjs +25 -1
  11. package/scripts/size-audit.cjs +79 -0
  12. package/scripts/source-of-truth.cjs +58 -0
  13. package/scripts/ux-smoke.mjs +438 -0
  14. package/scripts/wcag-audit.cjs +121 -6
  15. package/src/api/layers/file.ts +1 -0
  16. package/src/app/opengraph-image.tsx +5 -0
  17. package/src/app/preview/components/page.tsx +2237 -2
  18. package/src/app/shell.tsx +17 -16
  19. package/src/components/Foundations/Motion.stories.tsx +1 -0
  20. package/src/components/customize/brand-mark-section.tsx +4 -2
  21. package/src/components/customize/design-controls.tsx +17 -2
  22. package/src/components/customize/discipline-section.tsx +3 -6
  23. package/src/components/customize/font-pickers.tsx +1 -1
  24. package/src/components/customize/letter-spacing.tsx +1 -1
  25. package/src/components/customize/save-bar.tsx +2 -2
  26. package/src/components/customize/theme-io.tsx +7 -7
  27. package/src/components/customize/type-scale.tsx +1 -1
  28. package/src/components/customize-tab.tsx +7 -4
  29. package/src/components/home-tab.tsx +3 -0
  30. package/src/components/studio/studio.tsx +153 -0
  31. package/src/components/ui/accordion.tsx +7 -0
  32. package/src/components/ui/alert.tsx +1 -0
  33. package/src/components/ui/anchor.tsx +37 -3
  34. package/src/components/ui/announcement-bar.tsx +256 -0
  35. package/src/components/ui/attachment.tsx +211 -0
  36. package/src/components/ui/badge.tsx +1 -0
  37. package/src/components/ui/callout.tsx +218 -0
  38. package/src/components/ui/chart.tsx +5 -14
  39. package/src/components/ui/code.tsx +1 -1
  40. package/src/components/ui/color-picker.tsx +2 -2
  41. package/src/components/ui/format-relative-time.tsx +139 -0
  42. package/src/components/ui/gauge-chart.tsx +238 -0
  43. package/src/components/ui/grid.tsx +255 -0
  44. package/src/components/ui/heatmap.tsx +256 -0
  45. package/src/components/ui/icon.tsx +108 -0
  46. package/src/components/ui/index.ts +17 -0
  47. package/src/components/ui/infinite-scroll.tsx +103 -0
  48. package/src/components/ui/json-input.tsx +351 -0
  49. package/src/components/ui/navigation-progress.tsx +281 -0
  50. package/src/components/ui/number-input.tsx +1 -4
  51. package/src/components/ui/page-header.tsx +63 -0
  52. package/src/components/ui/password-input.tsx +2 -1
  53. package/src/components/ui/password-strength-input.tsx +288 -0
  54. package/src/components/ui/pill.tsx +140 -0
  55. package/src/components/ui/popover.tsx +27 -4
  56. package/src/components/ui/portal.tsx +111 -0
  57. package/src/components/ui/presence.tsx +172 -0
  58. package/src/components/ui/progress-stack.tsx +258 -0
  59. package/src/components/ui/scroll-progress.tsx +100 -0
  60. package/src/components/ui/select.tsx +89 -4
  61. package/src/components/ui/separator.tsx +1 -0
  62. package/src/components/ui/slider.tsx +83 -3
  63. package/src/components/ui/snackbar.tsx +393 -0
  64. package/src/components/ui/sortable-list.tsx +342 -0
  65. package/src/components/ui/sparkline.tsx +2 -14
  66. package/src/components/ui/squircle.tsx +1 -1
  67. package/src/components/ui/table.tsx +1 -1
  68. package/src/components/ui/textarea.tsx +28 -1
  69. package/src/components/ui/tour.tsx +1 -3
  70. package/src/data/docs-index.ts +25 -0
  71. package/src/hooks/use-reduced-motion.ts +6 -0
  72. package/src/lib/clamp.ts +2 -0
  73. package/src/stories/Accordion.stories.tsx +59 -0
  74. package/src/stories/Alert.stories.tsx +3 -1
  75. package/src/stories/Anchor.stories.tsx +54 -0
  76. package/src/stories/AnnouncementBar.stories.tsx +261 -0
  77. package/src/stories/Attachment.stories.tsx +189 -0
  78. package/src/stories/Badge.stories.tsx +3 -0
  79. package/src/stories/Calendar.stories.tsx +1 -1
  80. package/src/stories/Callout.stories.tsx +219 -0
  81. package/src/stories/Chart.stories.tsx +8 -0
  82. package/src/stories/Code.stories.tsx +1 -0
  83. package/src/stories/ColorPicker.stories.tsx +24 -0
  84. package/src/stories/FormatRelativeTime.stories.tsx +116 -0
  85. package/src/stories/GaugeChart.stories.tsx +163 -0
  86. package/src/stories/Grid.stories.tsx +197 -0
  87. package/src/stories/Heatmap.stories.tsx +172 -0
  88. package/src/stories/Icon.stories.tsx +175 -0
  89. package/src/stories/InfiniteScroll.stories.tsx +225 -0
  90. package/src/stories/JsonInput.stories.tsx +212 -0
  91. package/src/stories/MultiSelect.stories.tsx +1 -1
  92. package/src/stories/NavigationProgress.stories.tsx +159 -0
  93. package/src/stories/NumberInput.stories.tsx +1 -0
  94. package/src/stories/PageHeader.stories.tsx +102 -0
  95. package/src/stories/PasswordInput.stories.tsx +4 -0
  96. package/src/stories/PasswordStrengthInput.stories.tsx +211 -0
  97. package/src/stories/Pill.stories.tsx +201 -0
  98. package/src/stories/Popover.stories.tsx +29 -1
  99. package/src/stories/Portal.stories.tsx +191 -0
  100. package/src/stories/Presence.stories.tsx +228 -0
  101. package/src/stories/ProgressStack.stories.tsx +287 -0
  102. package/src/stories/ScrollProgress.stories.tsx +117 -0
  103. package/src/stories/Select.stories.tsx +25 -0
  104. package/src/stories/Separator.stories.tsx +3 -0
  105. package/src/stories/Slider.stories.tsx +54 -5
  106. package/src/stories/Snackbar.stories.tsx +315 -0
  107. package/src/stories/SortableList.stories.tsx +263 -0
  108. package/src/stories/Sparkline.stories.tsx +3 -0
  109. package/src/stories/Squircle.stories.tsx +1 -0
  110. package/src/stories/Table.stories.tsx +1 -0
  111. package/src/stories/Textarea.stories.tsx +18 -0
  112. package/src/stories/Tour.stories.tsx +1 -0
  113. package/src/stories/story-groups.json +26 -6
  114. package/src/styles.css +133 -12
  115. package/LICENSE +0 -21
@@ -0,0 +1,219 @@
1
+ import type { Meta, StoryObj } from "@storybook/react";
2
+ import { SparklesIcon } from "lucide-react";
3
+ import { Callout } from "@behavioral-agentic-design-system/core/components/ui/callout";
4
+ import { Code } from "@behavioral-agentic-design-system/core/components/ui/code";
5
+
6
+ /**
7
+ * Callout is the documentation/editorial aside that highlights contextual
8
+ * information inside prose — not system feedback.
9
+ *
10
+ * Use it for the note-about-a-gotcha, the tip-about-a-shortcut, the
11
+ * warning-before-a-destructive-migration. Five variants (note / tip /
12
+ * warning / danger / info) share the same intent family as Alert and
13
+ * Notification but with an `<aside>` semantic and no dismiss or action row.
14
+ *
15
+ * Body content is a rich slot — headings, lists, inline code, and multiple
16
+ * paragraphs all render correctly inside the body.
17
+ */
18
+ const meta: Meta<typeof Callout> = {
19
+ title: "Components/Feedback/Callout",
20
+ component: Callout,
21
+ parameters: { layout: "centered" },
22
+ tags: ["autodocs"],
23
+ argTypes: {
24
+ variant: {
25
+ control: "select",
26
+ options: ["note", "tip", "warning", "danger", "info"],
27
+ },
28
+ },
29
+ };
30
+
31
+ export default meta;
32
+ type Story = StoryObj<typeof meta>;
33
+
34
+ // ─── Stories ──────────────────────────────────────────────────────────────────
35
+
36
+ export const Default: Story = {
37
+ args: {
38
+ variant: "note",
39
+ title: "Note",
40
+ },
41
+ render: (args) => (
42
+ <div className="w-[480px]">
43
+ <Callout {...args}>
44
+ The component registry is the single source of truth. Never hardcode
45
+ values that live in <Code>tokens.json</Code> — changes propagate via{" "}
46
+ <Code>pnpm build:tokens</Code>.
47
+ </Callout>
48
+ </div>
49
+ ),
50
+ };
51
+
52
+ export const Variant_Note: Story = {
53
+ parameters: { controls: { disable: true } }, render: () => (
54
+ <div className="w-[480px]">
55
+ <Callout variant="note" title="Note">
56
+ Run <Code>pnpm wcag:audit</Code> before any PR that touches color
57
+ tokens to catch contrast regressions against the AAA floor.
58
+ </Callout>
59
+ </div>
60
+ ),
61
+ };
62
+
63
+ export const Variant_Tip: Story = {
64
+ parameters: { controls: { disable: true } }, render: () => (
65
+ <div className="w-[480px]">
66
+ <Callout variant="tip" title="Tip">
67
+ Set <Code>forceMount</Code> on inactive <Code>TabsContent</Code> panels
68
+ and wrap them in <Code>TabsPanels</Code> to avoid iframe cold-load on
69
+ every tab switch.
70
+ </Callout>
71
+ </div>
72
+ ),
73
+ };
74
+
75
+ export const Variant_Warning: Story = {
76
+ parameters: { controls: { disable: true } }, render: () => (
77
+ <div className="w-[480px]">
78
+ <Callout variant="warning" title="Warning">
79
+ The <Code>duration-fast</Code> and <Code>duration-base</Code> Tailwind
80
+ utilities compile to nothing in v4 — use inline{" "}
81
+ <Code>{`style={{ transitionDuration: "var(--duration-fast)" }}`}</Code>{" "}
82
+ instead.
83
+ </Callout>
84
+ </div>
85
+ ),
86
+ };
87
+
88
+ export const Variant_Danger: Story = {
89
+ parameters: { controls: { disable: true } }, render: () => (
90
+ <div className="w-[480px]">
91
+ <Callout variant="danger" title="Breaking change in v3">
92
+ The <Code>size</Code> prop on Button was renamed to{" "}
93
+ <Code>buttonSize</Code>. Update every call site before upgrading.
94
+ </Callout>
95
+ </div>
96
+ ),
97
+ };
98
+
99
+ export const Variant_Info: Story = {
100
+ parameters: { controls: { disable: true } }, render: () => (
101
+ <div className="w-[480px]">
102
+ <Callout variant="info" title="WCAG 3.0 status">
103
+ The March 2026 Working Draft renamed "outcomes" to "requirements". No
104
+ conformance action is required until the Candidate Recommendation
105
+ (expected Q4 2027). BADS's current AAA floor maps cleanly to the
106
+ Gold tier.
107
+ </Callout>
108
+ </div>
109
+ ),
110
+ };
111
+
112
+ export const AllVariants: Story = {
113
+ parameters: { controls: { disable: true } }, render: () => (
114
+ <div className="flex w-[480px] flex-col gap-4">
115
+ <Callout variant="note" title="Note">
116
+ General information or contextual aside.
117
+ </Callout>
118
+ <Callout variant="tip" title="Tip">
119
+ A helpful shortcut or recommended practice.
120
+ </Callout>
121
+ <Callout variant="warning" title="Warning">
122
+ Caution: a risk or potential issue to be aware of.
123
+ </Callout>
124
+ <Callout variant="danger" title="Danger">
125
+ Stop: this path leads to data loss or a breaking change.
126
+ </Callout>
127
+ <Callout variant="info" title="Info">
128
+ Neutral reference that is neither an error nor a tip.
129
+ </Callout>
130
+ </div>
131
+ ),
132
+ };
133
+
134
+ export const NoTitle: Story = {
135
+ parameters: { controls: { disable: true } }, render: () => (
136
+ <div className="flex w-[480px] flex-col gap-4">
137
+ <Callout variant="note">
138
+ Icon alone signals the variant when the title is omitted.
139
+ </Callout>
140
+ <Callout variant="warning">
141
+ Passing a custom icon? Set <Code>strokeWidth={"{1.5}"}</Code> to stay
142
+ on-system.
143
+ </Callout>
144
+ </div>
145
+ ),
146
+ };
147
+
148
+ export const NoIcon: Story = {
149
+ parameters: { controls: { disable: true } }, render: () => (
150
+ <div className="w-[480px]">
151
+ <Callout variant="tip" icon={null} title="Styling tip">
152
+ Pass <Code>icon={"{null}"}</Code> to suppress the default icon and let
153
+ the title and background tint carry the variant signal.
154
+ </Callout>
155
+ </div>
156
+ ),
157
+ };
158
+
159
+ export const CustomIcon: Story = {
160
+ parameters: { controls: { disable: true } }, render: () => (
161
+ <div className="w-[480px]">
162
+ <Callout
163
+ variant="tip"
164
+ icon={<SparklesIcon strokeWidth={1.5} aria-hidden />}
165
+ title="Night Shift"
166
+ >
167
+ Night Shift runs daily at 06:00 CDT, audits the full system, and opens
168
+ draft PRs for low-risk mechanical fixes. See{" "}
169
+ <Code>CIRCADIAN.md</Code> for the full spec.
170
+ </Callout>
171
+ </div>
172
+ ),
173
+ };
174
+
175
+ export const RichContent: Story = {
176
+ parameters: { controls: { disable: true } }, render: () => (
177
+ <div className="w-[480px]">
178
+ <Callout variant="danger" title="Microanimation patterns to avoid">
179
+ <p>These patterns compile to nothing in Tailwind v4 and produce silent failures:</p>
180
+ <ul className="mt-2 list-disc pl-4 space-y-1 text-muted-foreground">
181
+ <li><Code>duration-fast</Code>, <Code>duration-base</Code>, <Code>duration-slow</Code></li>
182
+ <li><Code>duration-[var(--duration-fast)]</Code> (arbitrary-value form)</li>
183
+ <li>Inline <Code>transitionDuration: "200ms"</Code> (literal value bypasses tokens)</li>
184
+ </ul>
185
+ <p className="mt-2">
186
+ Use inline <Code>{`style={{ transitionDuration: "var(--duration-fast)" }}`}</Code>{" "}
187
+ instead.
188
+ </p>
189
+ </Callout>
190
+ </div>
191
+ ),
192
+ };
193
+
194
+ export const RealisticUse: Story = {
195
+ parameters: { controls: { disable: true } }, render: () => (
196
+ <div className="w-[560px] flex flex-col gap-5">
197
+ <h2 className="text-lg font-semibold">Rename a client fork</h2>
198
+ <p className="text-sm text-muted-foreground">
199
+ A fork is unrenamed if <Code>.client-identity.json</Code> does not
200
+ exist and <Code>brand.config.ts</Code> still reads{" "}
201
+ <Code>name: &quot;BADS&quot;</Code>.
202
+ </p>
203
+ <Callout variant="tip" title="Fast path">
204
+ Run <Code>pnpm rename &quot;Clap Design&quot; clap</Code> — the script
205
+ updates every reference in a single pass, then commit with{" "}
206
+ <Code>git add -A && git commit -m &quot;chore: rename to Clap Design&quot;</Code>.
207
+ </Callout>
208
+ <Callout variant="warning" title="After renaming">
209
+ Re-run <Code>pnpm install && pnpm build:tokens</Code> so the generated
210
+ CSS carries the new package namespace. Skipping this causes a silent
211
+ FOUC on first load.
212
+ </Callout>
213
+ <Callout variant="danger">
214
+ Never run <Code>pnpm rename</Code> on an already-renamed repo — it will
215
+ do nothing harmful but wastes time and produces a confusing diff.
216
+ </Callout>
217
+ </div>
218
+ ),
219
+ };
@@ -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,
@@ -145,6 +149,10 @@ export const Variant_WithReferenceDot: Story = {
145
149
  ),
146
150
  };
147
151
 
152
+ // `animate={false}` freezes the chart at its final frame on demand. It is the
153
+ // same output reduced-motion users get automatically: ChartContainer reads the
154
+ // shared `useReducedMotion` hook (hooks/use-reduced-motion) and drops the
155
+ // entrance for them regardless of this prop.
148
156
  export const Variant_NoAnimation: Story = {
149
157
  render: () => (
150
158
  <ChartContainer config={twoSeriesConfig} className="h-56 w-[520px]" animate={false}>
@@ -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]">
@@ -1,5 +1,6 @@
1
1
  import React from "react";
2
2
  import type { Meta, StoryObj } from "@storybook/react";
3
+ import { userEvent, within, expect } from "storybook/test";
3
4
  import { ColorPicker } from "@behavioral-agentic-design-system/core/components/ui/color-picker";
4
5
  import { Card, CardContent, CardHeader, CardTitle } from "@behavioral-agentic-design-system/core/components/ui/card";
5
6
  import { Label } from "@behavioral-agentic-design-system/core/components/ui/label";
@@ -77,6 +78,28 @@ export const AddViaWheel: Story = {
77
78
  </div>
78
79
  );
79
80
  },
81
+ // "Add color" is the wheel popover's committing action and it is full-width,
82
+ // which is the shape BADS-2b flags: a w-full Button is the primary action of
83
+ // its container, and at the default size that is a 36px target under SC
84
+ // 2.5.5's 44px floor. The class fix is invisible until something renders it,
85
+ // so measure the rendered height rather than trusting the className.
86
+ // Two traps here, both worth keeping in the comment because both cost a
87
+ // round to find:
88
+ //
89
+ // 1. The wheel opens in a Radix portal at <body>, OUTSIDE canvasElement, so
90
+ // the query has to run against the document.
91
+ // 2. Assert the COMPUTED min-height, not getBoundingClientRect(). The popover
92
+ // enters with zoom-in-95, so the rect reads the animated box: 41.8px on
93
+ // one run and 43.4px on the next, against a design value of 44. That is
94
+ // corrections #023's "a reading taken mid-animation is not a design value"
95
+ // in miniature, and a gate that reports a different number each run
96
+ // teaches people to re-run it until it is green.
97
+ play: async ({ canvasElement }) => {
98
+ const canvas = within(canvasElement);
99
+ await userEvent.click(canvas.getByRole("button", { name: /add a custom color/i }));
100
+ const add = await within(document.body).findByRole("button", { name: /^add color$/i });
101
+ await expect(parseFloat(getComputedStyle(add).minHeight)).toBeGreaterThanOrEqual(44);
102
+ },
80
103
  };
81
104
 
82
105
  export const AddOnlyWheel: Story = {
@@ -205,3 +228,4 @@ export const RealisticUse: Story = {
205
228
  );
206
229
  },
207
230
  };
231
+
@@ -0,0 +1,116 @@
1
+ import type { Meta, StoryObj } from "@storybook/react"
2
+ import { FormatRelativeTime } from "@behavioral-agentic-design-system/core/components/ui/format-relative-time"
3
+
4
+ const meta: Meta<typeof FormatRelativeTime> = {
5
+ title: "Components/Content and data/FormatRelativeTime",
6
+ component: FormatRelativeTime,
7
+ parameters: {
8
+ docs: {
9
+ description: {
10
+ component:
11
+ "Locale-aware relative-time display primitive. Renders a `<time>` element with a machine-readable dateTime attribute. Optionally live-updates every 30 s.",
12
+ },
13
+ },
14
+ },
15
+ tags: ["autodocs"],
16
+ }
17
+
18
+ export default meta
19
+ type Story = StoryObj<typeof FormatRelativeTime>
20
+
21
+ // Two minutes ago
22
+ export const Default: Story = {
23
+ args: {
24
+ date: new Date(Date.now() - 2 * 60_000),
25
+ },
26
+ }
27
+
28
+ // Future date
29
+ export const Future: Story = {
30
+ args: {
31
+ date: new Date(Date.now() + 4 * 60 * 60_000),
32
+ },
33
+ }
34
+
35
+ // Yesterday
36
+ export const Yesterday: Story = {
37
+ args: {
38
+ date: new Date(Date.now() - 25 * 60 * 60_000),
39
+ numeric: "auto",
40
+ },
41
+ }
42
+
43
+ // Two weeks ago — days unit
44
+ export const TwoWeeksAgo: Story = {
45
+ args: {
46
+ date: new Date(Date.now() - 14 * 24 * 60 * 60_000),
47
+ },
48
+ }
49
+
50
+ // Long time ago — years unit
51
+ export const ThreeYearsAgo: Story = {
52
+ args: {
53
+ date: new Date(Date.now() - 3 * 365 * 24 * 60 * 60_000),
54
+ },
55
+ }
56
+
57
+ // Static (no live update) — for use in SSR/static contexts
58
+ export const Static: Story = {
59
+ args: {
60
+ date: new Date(Date.now() - 45_000),
61
+ live: false,
62
+ },
63
+ }
64
+
65
+ // Narrow style — compact label ("2 min. ago")
66
+ export const Narrow: Story = {
67
+ args: {
68
+ date: new Date(Date.now() - 7 * 60_000),
69
+ formatStyle: "narrow",
70
+ },
71
+ }
72
+
73
+ // Numeric forced — always uses numbers even for "yesterday"
74
+ export const AlwaysNumeric: Story = {
75
+ args: {
76
+ date: new Date(Date.now() - 25 * 60 * 60_000),
77
+ numeric: "always",
78
+ },
79
+ }
80
+
81
+ // Realistic use: activity feed row
82
+ export const RealisticUse: Story = {
83
+ parameters: { controls: { disable: true } },
84
+ render: () => (
85
+ <ul className="flex flex-col gap-2 text-sm">
86
+ {[
87
+ { user: "Jordan Reeves", action: "approved the PR", ago: 3 * 60_000 },
88
+ {
89
+ user: "Seo-yun Park",
90
+ action: "left a comment",
91
+ ago: 42 * 60_000,
92
+ },
93
+ {
94
+ user: "Marcus Lindqvist",
95
+ action: "opened a pull request",
96
+ ago: 4 * 60 * 60_000,
97
+ },
98
+ {
99
+ user: "Anika Patel",
100
+ action: "pushed 3 commits",
101
+ ago: 2 * 24 * 60 * 60_000,
102
+ },
103
+ ].map(({ user, action, ago }) => (
104
+ <li key={user} className="flex items-center justify-between gap-4">
105
+ <span>
106
+ <span className="font-medium">{user}</span> {action}
107
+ </span>
108
+ <FormatRelativeTime
109
+ date={new Date(Date.now() - ago)}
110
+ className="text-muted-foreground tabular-nums shrink-0"
111
+ />
112
+ </li>
113
+ ))}
114
+ </ul>
115
+ ),
116
+ }
@@ -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
+ }