@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.
Files changed (148) hide show
  1. package/README.md +2 -0
  2. package/package.json +41 -9
  3. package/scripts/a11y-lint.cjs +66 -3
  4. package/scripts/check-spec.mjs +73 -0
  5. package/scripts/deal-directions.mjs +186 -0
  6. package/scripts/health-report.mjs +23 -3
  7. package/scripts/lib/counted-lint.mjs +100 -0
  8. package/scripts/lib/marketing-library.mjs +129 -0
  9. package/scripts/lib/on-system.mjs +249 -0
  10. package/scripts/lib/random.mjs +22 -0
  11. package/scripts/lib/spec-parse.d.mts +25 -0
  12. package/scripts/lib/spec-parse.mjs +188 -0
  13. package/scripts/lib/tells.mjs +128 -0
  14. package/scripts/lint-css-vars.mjs +175 -0
  15. package/scripts/lint-html-nesting.mjs +116 -0
  16. package/scripts/lint-live-ctas.mjs +138 -0
  17. package/scripts/lint-slop.mjs +25 -1
  18. package/scripts/on-system-score.mjs +95 -0
  19. package/scripts/slop-rules.mjs +1 -1
  20. package/scripts/source-images.mjs +180 -0
  21. package/scripts/ux-tells.mjs +78 -0
  22. package/scripts/wcag-audit.cjs +72 -5
  23. package/src/api/brand-colors.ts +3 -0
  24. package/src/api/brand-fonts.ts +3 -0
  25. package/src/api/brand-mark.ts +6 -1
  26. package/src/api/dev-write-guard.ts +53 -0
  27. package/src/api/layers/file.ts +7 -4
  28. package/src/api/onboarding-extract.ts +85 -30
  29. package/src/api/onboarding.ts +3 -0
  30. package/src/api/save-tokens.ts +3 -0
  31. package/src/app/layout.tsx +6 -0
  32. package/src/app/opengraph-image.tsx +5 -0
  33. package/src/app/preview/canvas/page.tsx +12 -0
  34. package/src/app/preview/components/page.tsx +2003 -2
  35. package/src/app/preview/studio/blank-screen.tsx +143 -0
  36. package/src/app/preview/studio/page.tsx +7 -0
  37. package/src/app/shell.tsx +168 -49
  38. package/src/components/Foundations/Motion.stories.tsx +1 -0
  39. package/src/components/canvas/canvas.tsx +458 -0
  40. package/src/components/canvas/layout.ts +72 -0
  41. package/src/components/canvas/parse-canvas.ts +32 -0
  42. package/src/components/canvas/sample.ts +90 -0
  43. package/src/components/canvas/spec-frame.tsx +43 -0
  44. package/src/components/canvas/types.ts +33 -0
  45. package/src/components/customize/design-controls.tsx +16 -1
  46. package/src/components/docs-tab.tsx +7 -7
  47. package/src/components/home-recent.tsx +73 -0
  48. package/src/components/home-tab.tsx +13 -13
  49. package/src/components/layers-tab.tsx +2 -2
  50. package/src/components/markdown-preview.tsx +60 -12
  51. package/src/components/studio/control-panel.tsx +299 -0
  52. package/src/components/studio/control-row.tsx +77 -0
  53. package/src/components/studio/preview-frame.tsx +165 -0
  54. package/src/components/studio/preview-pane.tsx +247 -0
  55. package/src/components/studio/studio.tsx +158 -0
  56. package/src/components/studio/types.ts +218 -0
  57. package/src/components/studio/use-studio-tweaks.ts +128 -0
  58. package/src/components/studio/use-studio-view-state.ts +72 -0
  59. package/src/components/ui/anchor.tsx +37 -3
  60. package/src/components/ui/attachment.tsx +211 -0
  61. package/src/components/ui/autocomplete.tsx +1 -1
  62. package/src/components/ui/chart.tsx +3 -0
  63. package/src/components/ui/code.tsx +1 -1
  64. package/src/components/ui/color-picker.tsx +21 -5
  65. package/src/components/ui/data-table.tsx +64 -3
  66. package/src/components/ui/date-field.tsx +1 -1
  67. package/src/components/ui/editable.tsx +1 -0
  68. package/src/components/ui/faceted-filter.tsx +187 -0
  69. package/src/components/ui/gauge-chart.tsx +252 -0
  70. package/src/components/ui/heatmap.tsx +256 -0
  71. package/src/components/ui/index.ts +9 -0
  72. package/src/components/ui/infinite-scroll.tsx +103 -0
  73. package/src/components/ui/inline-edit.tsx +175 -0
  74. package/src/components/ui/json-input.tsx +351 -0
  75. package/src/components/ui/month-picker.tsx +1 -1
  76. package/src/components/ui/navigation-progress.tsx +281 -0
  77. package/src/components/ui/number-input.tsx +27 -7
  78. package/src/components/ui/otp-input.tsx +208 -0
  79. package/src/components/ui/password-input.tsx +2 -1
  80. package/src/components/ui/password-strength-input.tsx +288 -0
  81. package/src/components/ui/phone-input.tsx +274 -0
  82. package/src/components/ui/pill.tsx +140 -0
  83. package/src/components/ui/popover.tsx +27 -4
  84. package/src/components/ui/scroll-progress.tsx +100 -0
  85. package/src/components/ui/search-input.tsx +1 -1
  86. package/src/components/ui/snackbar.tsx +393 -0
  87. package/src/components/ui/sortable-list.tsx +342 -0
  88. package/src/components/ui/squircle.tsx +1 -1
  89. package/src/components/ui/table.tsx +1 -1
  90. package/src/components/ui/tags-input.tsx +1 -1
  91. package/src/components/ui/timer.tsx +1 -0
  92. package/src/components/ui/tour.tsx +1 -3
  93. package/src/components/ui/transfer-list.tsx +13 -26
  94. package/src/components/ui/week-picker.tsx +1 -1
  95. package/src/components/ui/year-picker.tsx +1 -1
  96. package/src/data/component-added.json +958 -0
  97. package/src/data/docs-index.ts +36 -0
  98. package/src/hooks/use-global-mono-font.ts +1 -0
  99. package/src/hooks/use-global-primary-color.ts +1 -0
  100. package/src/hooks/use-global-sans-font.ts +1 -0
  101. package/src/hooks/use-global-serif-font.ts +1 -0
  102. package/src/hooks/use-global-type-scale.ts +17 -2
  103. package/src/hooks/use-mobile.ts +2 -0
  104. package/src/hooks/use-sync-type-scale.ts +7 -11
  105. package/src/lib/clamp.ts +2 -0
  106. package/src/lib/spec-parse.ts +4 -0
  107. package/src/lib/svg-sanitize.ts +19 -9
  108. package/src/stories/Anchor.stories.tsx +54 -0
  109. package/src/stories/Attachment.stories.tsx +189 -0
  110. package/src/stories/Autocomplete.stories.tsx +2 -0
  111. package/src/stories/Canvas.stories.tsx +45 -0
  112. package/src/stories/Chart.stories.tsx +4 -0
  113. package/src/stories/Code.stories.tsx +1 -0
  114. package/src/stories/ColorPicker.stories.tsx +41 -0
  115. package/src/stories/DataTable.stories.tsx +30 -0
  116. package/src/stories/DateField.stories.tsx +21 -0
  117. package/src/stories/Editable.stories.tsx +2 -0
  118. package/src/stories/FacetedFilter.stories.tsx +197 -0
  119. package/src/stories/GaugeChart.stories.tsx +169 -0
  120. package/src/stories/Heatmap.stories.tsx +172 -0
  121. package/src/stories/InfiniteScroll.stories.tsx +225 -0
  122. package/src/stories/InlineEdit.stories.tsx +106 -0
  123. package/src/stories/JsonInput.stories.tsx +212 -0
  124. package/src/stories/MarkdownPreview.stories.tsx +53 -0
  125. package/src/stories/MonthPicker.stories.tsx +21 -0
  126. package/src/stories/NavigationProgress.stories.tsx +159 -0
  127. package/src/stories/NumberInput.stories.tsx +26 -0
  128. package/src/stories/OtpInput.stories.tsx +110 -0
  129. package/src/stories/PasswordInput.stories.tsx +4 -0
  130. package/src/stories/PasswordStrengthInput.stories.tsx +211 -0
  131. package/src/stories/PhoneInput.stories.tsx +127 -0
  132. package/src/stories/Pill.stories.tsx +201 -0
  133. package/src/stories/Popover.stories.tsx +29 -1
  134. package/src/stories/Portal.stories.tsx +3 -1
  135. package/src/stories/ScrollProgress.stories.tsx +117 -0
  136. package/src/stories/SearchInput.stories.tsx +2 -0
  137. package/src/stories/Snackbar.stories.tsx +315 -0
  138. package/src/stories/SortableList.stories.tsx +263 -0
  139. package/src/stories/Squircle.stories.tsx +1 -0
  140. package/src/stories/Table.stories.tsx +1 -0
  141. package/src/stories/TagsInput.stories.tsx +2 -0
  142. package/src/stories/Timer.stories.tsx +26 -0
  143. package/src/stories/Tour.stories.tsx +1 -0
  144. package/src/stories/TransferList.stories.tsx +4 -0
  145. package/src/stories/WeekPicker.stories.tsx +21 -0
  146. package/src/stories/YearPicker.stories.tsx +21 -0
  147. package/src/stories/story-groups.json +33 -16
  148. package/src/tokens.json +82 -54
@@ -0,0 +1,159 @@
1
+ import * as React from "react";
2
+ import type { Meta, StoryObj } from "@storybook/react";
3
+ import {
4
+ NavigationProgress,
5
+ useNavigationProgress,
6
+ } from "@behavioral-agentic-design-system/core/components/ui/navigation-progress";
7
+ import { Button } from "@behavioral-agentic-design-system/core/components/ui/button";
8
+ import {
9
+ Card,
10
+ CardContent,
11
+ CardDescription,
12
+ CardHeader,
13
+ CardTitle,
14
+ } from "@behavioral-agentic-design-system/core/components/ui/card";
15
+
16
+ // Content from content/personas/bads.json → primary (Jordan Reeves, Fieldnote
17
+ // Labs). The bar is fixed to the top edge of the story canvas; the controls
18
+ // below drive the module store.
19
+
20
+ const meta: Meta<typeof NavigationProgress> = {
21
+ title: "Components/Feedback/NavigationProgress",
22
+ component: NavigationProgress,
23
+ parameters: { layout: "fullscreen" },
24
+ tags: ["autodocs"],
25
+ argTypes: {
26
+ size: { control: "select", options: ["sm", "md", "lg"] },
27
+ color: { control: "text" },
28
+ initialProgress: { control: { type: "number", min: 0, max: 100 } },
29
+ stepInterval: { control: { type: "number", min: 50, step: 50 } },
30
+ label: { control: "text" },
31
+ },
32
+ args: {
33
+ size: "md",
34
+ initialProgress: 8,
35
+ stepInterval: 500,
36
+ label: "Page loading",
37
+ },
38
+ };
39
+
40
+ export default meta;
41
+ type Story = StoryObj<typeof meta>;
42
+
43
+ // The bar + a control strip. Every button is a flow-changing CTA → min-h-11.
44
+ function Demo(args: Story["args"]) {
45
+ const { progress, active, start, set, increment, stop, complete, reset } =
46
+ useNavigationProgress();
47
+ return (
48
+ <div className="min-h-[220px] p-6">
49
+ <NavigationProgress {...args} />
50
+ <p className="mb-4 text-sm text-muted-foreground">
51
+ {active ? `Loading — ${Math.round(progress)}%` : "Idle — the bar is hidden"}
52
+ </p>
53
+ <div className="flex flex-wrap gap-2">
54
+ <Button size="xl" onClick={() => start()}>Start</Button>
55
+ <Button size="xl" variant="outline" onClick={() => set(60)}>Set 60%</Button>
56
+ <Button size="xl" variant="outline" onClick={() => increment(10)}>+10</Button>
57
+ <Button size="xl" variant="outline" onClick={() => stop()}>Stop</Button>
58
+ <Button size="xl" variant="secondary" onClick={() => complete()}>Complete</Button>
59
+ <Button size="xl" variant="ghost" onClick={() => reset()}>Reset</Button>
60
+ </div>
61
+ </div>
62
+ );
63
+ }
64
+
65
+ export const Default: Story = {
66
+ render: (args) => <Demo {...args} />,
67
+ };
68
+
69
+ export const Size_SM: Story = {
70
+ args: { size: "sm" },
71
+ render: (args) => <Demo {...args} />,
72
+ };
73
+
74
+ export const Size_MD: Story = {
75
+ args: { size: "md" },
76
+ render: (args) => <Demo {...args} />,
77
+ };
78
+
79
+ export const Size_LG: Story = {
80
+ args: { size: "lg" },
81
+ render: (args) => <Demo {...args} />,
82
+ };
83
+
84
+ // Any CSS color. Monochrome here — a fork whose primary is near-black on a
85
+ // dark shell may want the bar to read as foreground instead.
86
+ export const Color: Story = {
87
+ args: { color: "var(--foreground)", size: "lg" },
88
+ render: (args) => <Demo {...args} />,
89
+ };
90
+
91
+ // Simulated route change: "Open Billing" starts the bar, the new screen lands
92
+ // 1.6 s later and completes it. This is the shape a Next.js route hook or a
93
+ // fetch wrapper produces — start() on navigation, complete() on data.
94
+ function RouteChangeDemo() {
95
+ const { start, complete, active } = useNavigationProgress();
96
+ const [screen, setScreen] = React.useState<"workspace" | "billing">("workspace");
97
+ const timer = React.useRef<ReturnType<typeof setTimeout> | null>(null);
98
+
99
+ React.useEffect(() => () => {
100
+ if (timer.current) clearTimeout(timer.current);
101
+ }, []);
102
+
103
+ function navigate(to: "workspace" | "billing") {
104
+ if (timer.current) clearTimeout(timer.current);
105
+ start();
106
+ timer.current = setTimeout(() => {
107
+ setScreen(to);
108
+ complete();
109
+ }, 1600);
110
+ }
111
+
112
+ return (
113
+ <div className="min-h-[320px] p-6">
114
+ <NavigationProgress />
115
+ <nav aria-label="Workspace" className="mb-6 flex gap-2">
116
+ <Button
117
+ size="xl"
118
+ variant={screen === "workspace" ? "secondary" : "ghost"}
119
+ aria-current={screen === "workspace" ? "page" : undefined}
120
+ onClick={() => navigate("workspace")}
121
+ disabled={active}
122
+ >
123
+ Workspace
124
+ </Button>
125
+ <Button
126
+ size="xl"
127
+ variant={screen === "billing" ? "secondary" : "ghost"}
128
+ aria-current={screen === "billing" ? "page" : undefined}
129
+ onClick={() => navigate("billing")}
130
+ disabled={active}
131
+ >
132
+ Billing
133
+ </Button>
134
+ </nav>
135
+ <Card className="max-w-md" aria-busy={active || undefined}>
136
+ <CardHeader>
137
+ <CardTitle className="text-base">
138
+ {screen === "workspace" ? "Fieldnote Labs workspace" : "Billing"}
139
+ </CardTitle>
140
+ <CardDescription>
141
+ {screen === "workspace"
142
+ ? "36 components · 8 members · updated 2026-05-26 by Jordan Reeves"
143
+ : "Team plan · next invoice 2026-11-01 · billing contact jordan@reeves.design"}
144
+ </CardDescription>
145
+ </CardHeader>
146
+ <CardContent className="text-sm text-muted-foreground">
147
+ {active
148
+ ? "Loading the next screen — the bar at the top edge is the only indicator; nothing in the page blocks."
149
+ : "Switch tabs to watch the bar start, trickle, and complete when the screen lands."}
150
+ </CardContent>
151
+ </Card>
152
+ </div>
153
+ );
154
+ }
155
+
156
+ export const RealisticUse: Story = {
157
+ parameters: { controls: { disable: true } },
158
+ render: () => <RouteChangeDemo />,
159
+ };
@@ -49,6 +49,31 @@ export const Step: Story = {
49
49
  name: "Step of 5",
50
50
  };
51
51
 
52
+ // Stepping a fraction must not leak float noise (0.2 + 0.1 shows 0.3, not 0.30000000000000004).
53
+ export const DecimalStep: Story = {
54
+ render: () => <Controlled step={0.1} defaultValue={0.2} aria-label="Discount rate" />,
55
+ name: "Decimal step (0.1)",
56
+ parameters: { controls: { disable: true } },
57
+ };
58
+
59
+ // A caller's onBlur runs alongside commit-on-blur instead of replacing it.
60
+ export const WithOnBlur: Story = {
61
+ parameters: { controls: { disable: true } },
62
+ render: () => {
63
+ const [seen, setSeen] = React.useState("none yet");
64
+ return (
65
+ <div className="flex flex-col gap-3">
66
+ <NumberInput
67
+ defaultValue={3}
68
+ aria-label="Seats"
69
+ onBlur={(e) => setSeen(e.currentTarget.value)}
70
+ />
71
+ <p className="text-sm text-muted-foreground">Last blur saw: {seen}</p>
72
+ </div>
73
+ );
74
+ },
75
+ };
76
+
52
77
  // ─── Disabled ─────────────────────────────────────────────────────────────────
53
78
  export const Disabled: Story = {
54
79
  render: () => <NumberInput value={42} disabled aria-label="Quantity" />,
@@ -98,3 +123,4 @@ function TicketPicker() {
98
123
  export const RealisticUse: Story = {
99
124
  render: () => <TicketPicker />,
100
125
  };
126
+
@@ -0,0 +1,110 @@
1
+ import type { Meta, StoryObj } from "@storybook/react";
2
+ import * as React from "react";
3
+ import { OTPInput } from "@behavioral-agentic-design-system/core/components/ui/otp-input";
4
+
5
+ const meta: Meta<typeof OTPInput> = {
6
+ title: "Components/Forms/OTPInput",
7
+ component: OTPInput,
8
+ parameters: { layout: "centered" },
9
+ tags: ["autodocs"],
10
+ };
11
+
12
+ export default meta;
13
+ type Story = StoryObj<typeof meta>;
14
+
15
+ export const Default: Story = {
16
+ render: (args) => <OTPInput {...args} />,
17
+ args: { length: 6, numeric: true },
18
+ };
19
+
20
+ export const Size_Sm: Story = {
21
+ render: (args) => <OTPInput {...args} />,
22
+ args: { length: 6, size: "sm" },
23
+ };
24
+
25
+ export const Size_Default: Story = {
26
+ render: (args) => <OTPInput {...args} />,
27
+ args: { length: 6, size: "default" },
28
+ };
29
+
30
+ export const Size_Lg: Story = {
31
+ render: (args) => <OTPInput {...args} />,
32
+ args: { length: 6, size: "lg" },
33
+ };
34
+
35
+ export const WithSeparator: Story = {
36
+ render: (args) => <OTPInput {...args} />,
37
+ args: { length: 6, separatorAfter: 2 },
38
+ };
39
+
40
+ export const FourDigit: Story = {
41
+ render: (args) => <OTPInput {...args} />,
42
+ args: { length: 4, numeric: true },
43
+ };
44
+
45
+ export const Alphanumeric: Story = {
46
+ render: (args) => <OTPInput {...args} />,
47
+ args: { length: 6, numeric: false },
48
+ };
49
+
50
+ export const Disabled: Story = {
51
+ render: (args) => <OTPInput {...args} />,
52
+ args: { length: 6, disabled: true, value: "123456" } as any,
53
+ };
54
+
55
+ export const Invalid: Story = {
56
+ render: (args) => <OTPInput {...args} />,
57
+ args: { length: 6, invalid: true, value: "12345" } as any,
58
+ };
59
+
60
+ export const RealisticUse: Story = {
61
+ parameters: { controls: { disable: true } },
62
+ render: () => {
63
+ const [value, setValue] = React.useState("");
64
+ const [status, setStatus] = React.useState<"idle" | "verifying" | "success" | "error">("idle");
65
+
66
+ function handleComplete(v: string) {
67
+ setStatus("verifying");
68
+ setTimeout(() => {
69
+ setStatus(v === "000000" ? "error" : "success");
70
+ }, 800);
71
+ }
72
+
73
+ return (
74
+ <div className="flex flex-col items-center gap-4 text-center">
75
+ <div className="space-y-1">
76
+ <p className="text-sm font-medium text-foreground">Enter verification code</p>
77
+ <p className="text-sm text-muted-foreground">
78
+ Sent to elara.voss@designcraft.co
79
+ </p>
80
+ </div>
81
+ <OTPInput
82
+ value={value}
83
+ onChange={(v) => {
84
+ setValue(v);
85
+ if (status !== "idle") setStatus("idle");
86
+ }}
87
+ onComplete={handleComplete}
88
+ separatorAfter={2}
89
+ invalid={status === "error"}
90
+ disabled={status === "verifying" || status === "success"}
91
+ aria-label="Email verification code"
92
+ />
93
+ {status === "verifying" && (
94
+ <p className="text-sm text-muted-foreground">Verifying…</p>
95
+ )}
96
+ {status === "success" && (
97
+ <p className="text-sm text-green-600 dark:text-green-400">Verified successfully</p>
98
+ )}
99
+ {status === "error" && (
100
+ <p className="text-sm text-destructive">Incorrect code. Try again.</p>
101
+ )}
102
+ {status === "idle" && value.length === 0 && (
103
+ <p className="text-xs text-muted-foreground">
104
+ Use <code className="rounded bg-muted px-1 py-0.5 font-mono text-xs">000000</code> to test error state
105
+ </p>
106
+ )}
107
+ </div>
108
+ );
109
+ },
110
+ };
@@ -12,6 +12,10 @@ const meta: Meta<typeof PasswordInput> = {
12
12
  export default meta;
13
13
  type Story = StoryObj<typeof PasswordInput>;
14
14
 
15
+ // Tab to the show/hide toggle button and confirm it paints the standard
16
+ // focus-visible ring (ring-ring/50) rather than falling back to the UA
17
+ // default outline — see corrections.md and ledgers/ux-tests.jsonl
18
+ // (PasswordInput, 2026-07-14, resolved 2026-10-05).
15
19
  export const Default: Story = {};
16
20
 
17
21
  export const Size_Sm: Story = {
@@ -0,0 +1,211 @@
1
+ import type { Meta, StoryObj } from "@storybook/react"
2
+ import * as React from "react"
3
+ import { PasswordStrengthInput } from "@behavioral-agentic-design-system/core/components/ui/password-strength-input"
4
+ import { Label } from "@behavioral-agentic-design-system/core/components/ui/label"
5
+ import { Button } from "@behavioral-agentic-design-system/core/components/ui/button"
6
+
7
+ const meta: Meta<typeof PasswordStrengthInput> = {
8
+ title: "Components/Forms/PasswordStrengthInput",
9
+ component: PasswordStrengthInput,
10
+ parameters: { layout: "centered" },
11
+ args: {
12
+ placeholder: "New password",
13
+ autoComplete: "new-password",
14
+ style: { width: 320 },
15
+ },
16
+ }
17
+
18
+ export default meta
19
+ type Story = StoryObj<typeof PasswordStrengthInput>
20
+
21
+ // ─── Basic states ─────────────────────────────────────────────────────────────
22
+
23
+ export const Default: Story = {}
24
+
25
+ export const ShowHints: Story = {
26
+ args: { showHints: true },
27
+ }
28
+
29
+ export const HideLabel: Story = {
30
+ args: { showLabel: false },
31
+ name: "Variant_HideLabel",
32
+ }
33
+
34
+ export const Segments_3: Story = {
35
+ name: "Variant_Segments3",
36
+ args: { segments: 3 },
37
+ }
38
+
39
+ export const Segments_5: Story = {
40
+ name: "Variant_Segments5",
41
+ args: { segments: 5 },
42
+ }
43
+
44
+ // ─── Sizes ────────────────────────────────────────────────────────────────────
45
+
46
+ export const Size_Sm: Story = {
47
+ args: { size: "sm" },
48
+ }
49
+
50
+ export const Size_Lg: Story = {
51
+ args: { size: "lg" },
52
+ }
53
+
54
+ export const Size_Xl: Story = {
55
+ args: { size: "xl" },
56
+ }
57
+
58
+ // ─── Disabled ─────────────────────────────────────────────────────────────────
59
+
60
+ export const Disabled: Story = {
61
+ args: { disabled: true },
62
+ }
63
+
64
+ // ─── Strength levels (controlled) ────────────────────────────────────────────
65
+
66
+ /** Demonstrates the four filled visual states without user interaction. */
67
+ export const Variant_StrengthWeak: Story = {
68
+ name: "Variant_StrengthWeak",
69
+ args: { value: "pass", onChange: () => {} },
70
+ }
71
+
72
+ export const Variant_StrengthFair: Story = {
73
+ name: "Variant_StrengthFair",
74
+ args: { value: "password1", onChange: () => {} },
75
+ }
76
+
77
+ export const Variant_StrengthGood: Story = {
78
+ name: "Variant_StrengthGood",
79
+ args: { value: "Password123", onChange: () => {} },
80
+ }
81
+
82
+ export const Variant_StrengthStrong: Story = {
83
+ name: "Variant_StrengthStrong",
84
+ args: { value: "P@ssword123!!", onChange: () => {} },
85
+ }
86
+
87
+ // ─── Realistic use: signup form ───────────────────────────────────────────────
88
+
89
+ /**
90
+ * A signup form using real names from the BADS content pool.
91
+ * Demonstrates controlled usage with form submission.
92
+ */
93
+ export const RealisticUse: Story = {
94
+ parameters: { controls: { disable: true } },
95
+ render: () => {
96
+ function SignupForm() {
97
+ const [password, setPassword] = React.useState("")
98
+ const [submitted, setSubmitted] = React.useState(false)
99
+
100
+ return submitted ? (
101
+ <div className="flex w-80 flex-col gap-3 rounded-lg border border-border bg-card p-5">
102
+ <p className="text-sm text-muted-foreground">
103
+ Welcome, Jordan — your account is ready.
104
+ </p>
105
+ <Button
106
+ size="sm"
107
+ variant="outline"
108
+ onClick={() => {
109
+ setPassword("")
110
+ setSubmitted(false)
111
+ }}
112
+ >
113
+ Start over
114
+ </Button>
115
+ </div>
116
+ ) : (
117
+ <form
118
+ className="flex w-80 flex-col gap-4 rounded-lg border border-border bg-card p-5"
119
+ onSubmit={(e) => {
120
+ e.preventDefault()
121
+ if (password.length >= 6) setSubmitted(true)
122
+ }}
123
+ >
124
+ <div className="space-y-1">
125
+ <h2 className="text-base font-semibold">Create your account</h2>
126
+ <p className="text-sm text-muted-foreground">
127
+ Northwind Health — design system access
128
+ </p>
129
+ </div>
130
+
131
+ <div className="flex flex-col gap-1.5">
132
+ <Label htmlFor="signup-email">Email</Label>
133
+ <input
134
+ id="signup-email"
135
+ type="email"
136
+ defaultValue="jordan.reeves@northwindhealth.com"
137
+ readOnly
138
+ className="h-9 rounded-md border border-input bg-transparent px-3 text-sm opacity-60 cursor-not-allowed"
139
+ />
140
+ </div>
141
+
142
+ <div className="flex flex-col gap-1.5">
143
+ <Label htmlFor="signup-password">Password</Label>
144
+ <PasswordStrengthInput
145
+ id="signup-password"
146
+ value={password}
147
+ onChange={(e) => setPassword(e.target.value)}
148
+ placeholder="Create a strong password"
149
+ autoComplete="new-password"
150
+ showHints
151
+ />
152
+ </div>
153
+
154
+ <Button
155
+ type="submit"
156
+ size="xl"
157
+ className="w-full"
158
+ disabled={password.length < 6}
159
+ >
160
+ Create account
161
+ </Button>
162
+ </form>
163
+ )
164
+ }
165
+ return <SignupForm />
166
+ },
167
+ }
168
+
169
+ // ─── Custom strength function ─────────────────────────────────────────────────
170
+
171
+ /**
172
+ * Demonstrates a custom strengthFn that enforces strict rules
173
+ * (e.g., minimum 10 chars + special char required for "Strong").
174
+ */
175
+ export const Variant_CustomStrengthFn: Story = {
176
+ name: "Variant_CustomStrengthFn",
177
+ parameters: { controls: { disable: true } },
178
+ render: () => {
179
+ function StrictForm() {
180
+ const [pw, setPw] = React.useState("")
181
+
182
+ function strictStrengthFn(value: string): 0 | 1 | 2 | 3 | 4 {
183
+ if (!value.length) return 0
184
+ let score = 0
185
+ if (value.length >= 10) score++
186
+ if (value.length >= 16) score++
187
+ if (/[A-Z]/.test(value) && /[a-z]/.test(value)) score++
188
+ if (/[0-9]/.test(value) && /[^A-Za-z0-9]/.test(value)) score++
189
+ return Math.min(4, Math.max(1, score)) as 0 | 1 | 2 | 3 | 4
190
+ }
191
+
192
+ return (
193
+ <div className="flex w-80 flex-col gap-3">
194
+ <p className="text-sm text-muted-foreground">
195
+ Strict scorer — requires ≥10 chars + symbol + mixed case for
196
+ "Strong."
197
+ </p>
198
+ <PasswordStrengthInput
199
+ value={pw}
200
+ onChange={(e) => setPw(e.target.value)}
201
+ placeholder="API key passphrase"
202
+ strengthFn={strictStrengthFn}
203
+ segments={5}
204
+ showHints
205
+ />
206
+ </div>
207
+ )
208
+ }
209
+ return <StrictForm />
210
+ },
211
+ }
@@ -0,0 +1,127 @@
1
+ import * as React from "react";
2
+ import { Meta, StoryObj } from "@storybook/react";
3
+ import { PhoneInput } from "@behavioral-agentic-design-system/core/components/ui/phone-input";
4
+ import {
5
+ Field,
6
+ FieldLabel,
7
+ FieldHelper,
8
+ FieldError,
9
+ } from "@behavioral-agentic-design-system/core/components/ui/field";
10
+
11
+ const meta: Meta<typeof PhoneInput> = {
12
+ title: "Components/Forms/PhoneInput",
13
+ component: PhoneInput,
14
+ parameters: {
15
+ layout: "centered",
16
+ },
17
+ tags: ["autodocs"],
18
+ };
19
+
20
+ export default meta;
21
+ type Story = StoryObj<typeof meta>;
22
+
23
+ export const Default: Story = {
24
+ args: {
25
+ "aria-label": "Phone number",
26
+ defaultCountry: "US",
27
+ },
28
+ };
29
+
30
+ export const WithValue: Story = {
31
+ name: "With value (controlled)",
32
+ parameters: { controls: { disable: true } },
33
+ render: () => {
34
+ const [phone, setPhone] = React.useState("+14155550182");
35
+ return (
36
+ <div className="w-72">
37
+ <PhoneInput
38
+ aria-label="Phone number"
39
+ value={phone}
40
+ onChange={setPhone}
41
+ />
42
+ <p className="mt-2 text-sm text-muted-foreground">
43
+ E.164: <code className="font-mono">{phone || "(empty)"}</code>
44
+ </p>
45
+ </div>
46
+ );
47
+ },
48
+ };
49
+
50
+ export const Disabled: Story = {
51
+ args: {
52
+ "aria-label": "Phone number",
53
+ disabled: true,
54
+ defaultCountry: "GB",
55
+ },
56
+ };
57
+
58
+ export const Error: Story = {
59
+ name: "Error state",
60
+ parameters: { controls: { disable: true } },
61
+ render: () => (
62
+ <div className="w-72">
63
+ <Field name="phone" invalid>
64
+ <FieldLabel>Phone number</FieldLabel>
65
+ <PhoneInput id="phone" aria-label="Phone number" error defaultCountry="US" />
66
+ <FieldError>Please enter a valid phone number.</FieldError>
67
+ </Field>
68
+ </div>
69
+ ),
70
+ };
71
+
72
+ // Canada and the United States share +1. A controlled field must keep the country the user picked, and
73
+ // emit digits only: typing "(415) 555-0182" reports "+14155550182".
74
+ export const ControlledKeepsCountry: Story = {
75
+ name: "Controlled, keeps Canada, emits E.164",
76
+ parameters: { controls: { disable: true } },
77
+ render: () => {
78
+ const [value, setValue] = React.useState("");
79
+ return (
80
+ <div className="flex w-80 flex-col gap-3">
81
+ <PhoneInput aria-label="Mobile number" value={value} onChange={setValue} name="phone" />
82
+ <p className="text-sm text-muted-foreground">Value: {value || "empty"}</p>
83
+ </div>
84
+ );
85
+ },
86
+ };
87
+
88
+ export const DifferentCountries: Story = {
89
+ name: "Different default countries",
90
+ parameters: { controls: { disable: true } },
91
+ render: () => (
92
+ <div className="flex w-80 flex-col gap-3">
93
+ <PhoneInput aria-label="UK number" defaultCountry="GB" />
94
+ <PhoneInput aria-label="Australian number" defaultCountry="AU" />
95
+ <PhoneInput aria-label="German number" defaultCountry="DE" />
96
+ <PhoneInput aria-label="Brazilian number" defaultCountry="BR" />
97
+ </div>
98
+ ),
99
+ };
100
+
101
+ export const RealisticUse: Story = {
102
+ name: "Realistic use: account settings — Jordan Reeves",
103
+ parameters: { controls: { disable: true } },
104
+ render: () => {
105
+ const [phone, setPhone] = React.useState("+14155550182");
106
+ return (
107
+ <div className="w-80">
108
+ <Field name="phone-realistic">
109
+ <FieldLabel>Phone number</FieldLabel>
110
+ <PhoneInput
111
+ id="phone-realistic"
112
+ aria-label="Phone number"
113
+ value={phone}
114
+ onChange={setPhone}
115
+ defaultCountry="US"
116
+ />
117
+ <FieldHelper>
118
+ Used for two-factor authentication and account recovery.
119
+ </FieldHelper>
120
+ </Field>
121
+ <p className="mt-3 text-xs text-muted-foreground">
122
+ Stored value: <code className="font-mono">{phone || "(empty)"}</code>
123
+ </p>
124
+ </div>
125
+ );
126
+ },
127
+ };