@behavioral-agentic-design-system/core 0.21.0 → 0.23.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.
@@ -0,0 +1,194 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { cva, type VariantProps } from "class-variance-authority";
5
+
6
+ import { cn } from "../../lib/utils";
7
+ import { Button } from "./button";
8
+
9
+ // ─── Variants ─────────────────────────────────────────────────────────────────
10
+ //
11
+ // The group is the ring owner. The hosted <input> is borderless + outline-none
12
+ // so there is exactly ONE focus indicator (the container's focus-within ring),
13
+ // which keeps it high-contrast-mode safe. Same container-owns-ring contract as
14
+ // PasswordInput, generalized to arbitrary leading/trailing addons.
15
+
16
+ const inputGroupVariants = cva(
17
+ [
18
+ "flex items-center overflow-hidden",
19
+ "rounded-md border border-input bg-transparent shadow-xs",
20
+ "transition-[color,box-shadow]",
21
+ "focus-within:border-ring focus-within:ring-[3px] focus-within:ring-ring/50",
22
+ "has-[:disabled]:pointer-events-none has-[:disabled]:cursor-not-allowed has-[:disabled]:opacity-50",
23
+ "aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40",
24
+ ],
25
+ {
26
+ variants: {
27
+ size: {
28
+ sm: "h-8 text-sm",
29
+ default: "h-9 text-base md:text-sm",
30
+ lg: "h-10 text-base",
31
+ xl: "h-11 text-base",
32
+ "2xl": "h-12 text-lg",
33
+ },
34
+ },
35
+ defaultVariants: { size: "default" },
36
+ }
37
+ );
38
+
39
+ type InputGroupSize = NonNullable<VariantProps<typeof inputGroupVariants>["size"]>;
40
+
41
+ const InputGroupSizeContext = React.createContext<InputGroupSize>("default");
42
+
43
+ // Per-size padding for the hosted input and the flanking addons, so the group
44
+ // reads with the same internal rhythm as a standalone Input at each size.
45
+ const inputPaddingBySize: Record<InputGroupSize, string> = {
46
+ sm: "px-2.5 py-1",
47
+ default: "px-3 py-1",
48
+ lg: "px-4 py-2",
49
+ xl: "px-4 py-2",
50
+ "2xl": "px-5 py-2.5",
51
+ };
52
+
53
+ const addonPaddingBySize: Record<InputGroupSize, string> = {
54
+ sm: "px-2.5",
55
+ default: "px-3",
56
+ lg: "px-3.5",
57
+ xl: "px-3.5",
58
+ "2xl": "px-4",
59
+ };
60
+
61
+ // ─── Root ─────────────────────────────────────────────────────────────────────
62
+
63
+ export interface InputGroupProps
64
+ extends React.ComponentProps<"div">,
65
+ VariantProps<typeof inputGroupVariants> {}
66
+
67
+ function InputGroup({
68
+ className,
69
+ size,
70
+ "aria-invalid": ariaInvalid,
71
+ ...props
72
+ }: InputGroupProps) {
73
+ const resolvedSize: InputGroupSize = size ?? "default";
74
+ return (
75
+ <InputGroupSizeContext.Provider value={resolvedSize}>
76
+ <div
77
+ role="group"
78
+ data-slot="input-group"
79
+ aria-invalid={ariaInvalid}
80
+ className={cn(inputGroupVariants({ size, className }))}
81
+ {...props}
82
+ />
83
+ </InputGroupSizeContext.Provider>
84
+ );
85
+ }
86
+
87
+ // ─── Input ────────────────────────────────────────────────────────────────────
88
+
89
+ function InputGroupInput({
90
+ className,
91
+ type,
92
+ ...props
93
+ }: React.ComponentProps<"input">) {
94
+ const size = React.useContext(InputGroupSizeContext);
95
+ return (
96
+ <input
97
+ type={type}
98
+ data-slot="input-group-input"
99
+ className={cn(
100
+ "min-w-0 flex-1 bg-transparent outline-none",
101
+ "placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground",
102
+ "disabled:cursor-not-allowed dark:bg-input/30",
103
+ inputPaddingBySize[size],
104
+ className
105
+ )}
106
+ {...props}
107
+ />
108
+ );
109
+ }
110
+
111
+ // ─── Addon ────────────────────────────────────────────────────────────────────
112
+ //
113
+ // A non-interactive slot for icons or text pinned to the start/end of the group.
114
+ // It sits as a SIBLING of the input (never wrapping it), so no interactive child
115
+ // it may hold ever nests inside another interactive element (axe nested-interactive).
116
+
117
+ export interface InputGroupAddonProps extends React.ComponentProps<"div"> {
118
+ /** Which edge of the group the addon sits on. */
119
+ align?: "inline-start" | "inline-end";
120
+ }
121
+
122
+ function InputGroupAddon({
123
+ className,
124
+ align = "inline-start",
125
+ ...props
126
+ }: InputGroupAddonProps) {
127
+ const size = React.useContext(InputGroupSizeContext);
128
+ return (
129
+ <div
130
+ data-slot="input-group-addon"
131
+ data-align={align}
132
+ className={cn(
133
+ "flex shrink-0 items-center gap-1.5 text-muted-foreground",
134
+ "[&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:stroke-[1.5]",
135
+ addonPaddingBySize[size],
136
+ align === "inline-start" ? "pr-0" : "pl-0",
137
+ className
138
+ )}
139
+ {...props}
140
+ />
141
+ );
142
+ }
143
+
144
+ // ─── Text ─────────────────────────────────────────────────────────────────────
145
+ //
146
+ // A prefix/suffix label (currency symbol, unit, protocol). Presentation only —
147
+ // aria-hidden so screen readers rely on the field's own label, not the ornament.
148
+
149
+ function InputGroupText({ className, ...props }: React.ComponentProps<"span">) {
150
+ return (
151
+ <span
152
+ data-slot="input-group-text"
153
+ aria-hidden
154
+ className={cn("select-none whitespace-nowrap text-muted-foreground", className)}
155
+ {...props}
156
+ />
157
+ );
158
+ }
159
+
160
+ // ─── Button ───────────────────────────────────────────────────────────────────
161
+ //
162
+ // An inline action (Copy, Send, Search). Wraps the Button primitive so it
163
+ // inherits the system's token-driven hover/focus motion. Renders as a sibling
164
+ // of the input — never a parent of it.
165
+
166
+ export type InputGroupButtonProps = React.ComponentProps<typeof Button>;
167
+
168
+ function InputGroupButton({
169
+ className,
170
+ variant = "ghost",
171
+ size = "sm",
172
+ type = "button",
173
+ ...props
174
+ }: InputGroupButtonProps) {
175
+ return (
176
+ <Button
177
+ data-slot="input-group-button"
178
+ type={type}
179
+ variant={variant}
180
+ size={size}
181
+ className={cn("h-full shrink-0 rounded-none", className)}
182
+ {...props}
183
+ />
184
+ );
185
+ }
186
+
187
+ export {
188
+ InputGroup,
189
+ InputGroupInput,
190
+ InputGroupAddon,
191
+ InputGroupText,
192
+ InputGroupButton,
193
+ inputGroupVariants,
194
+ };
@@ -102,6 +102,7 @@ export const DOCS_INDEX: DocGroup[] = [
102
102
  entries: [
103
103
  { title: "Design rules", path: "DESIGN.md", summary: "Visual system + accessibility baseline." },
104
104
  { title: "Chart color palette", path: "docs/chart-color-palette.md", summary: "Accessible 5-color categorical palette for data viz — Okabe-Ito-derived, reviewed against WCAG 1.4.11 non-text contrast." },
105
+ { title: "Privacy-first design (8 principles)", path: "layer-2-ethics-responsibility/privacy-first-design.md", summary: "Matthew Stephens' 8-principle privacy framework: minimize collection, transparency, expiration, no dark patterns, user control, ethical monetization, sustainable practices, accountability — mapped to BADS enforcement." },
105
106
  { title: "Gamification — responsible vs. manipulative", path: "layer-2-ethics-responsibility/gamification.md", summary: "Sir's 10 Core Drives (Octalysis 8 + Exploration & Discovery + Challenge & Competition) + the test gates that decide when Black Hat ships and when it refuses." },
106
107
  { title: "Corrections log", path: "corrections.md", summary: "Per-fork anti-pattern log. Read before every Path B build." },
107
108
  { title: "Anti-defaults refresh", path: "prompts/anti-defaults-refresh.md", summary: "Quarterly pressure-test of the current anti-defaults." },
@@ -125,6 +126,18 @@ export const DOCS_INDEX: DocGroup[] = [
125
126
  { title: "5 · Component needs", path: "prompts/5-component-needs.md" },
126
127
  { title: "6 · Patterns", path: "prompts/6-patterns.md" },
127
128
  { title: "Chromatic setup", path: "docs/chromatic-setup.md" },
129
+ {
130
+ title: "Handoff runbook",
131
+ path: "docs/handoff-runbook.md",
132
+ summary:
133
+ "Transferring a finished fork to the client's own team — quality pass, repo transfer, secret rotation, knowledge transfer, wind-down.",
134
+ },
135
+ {
136
+ title: "Fork sync migration",
137
+ path: "docs/fork-sync-migration.md",
138
+ summary:
139
+ "workspace:* to npm-consume — the migration every client fork runs so daily component releases actually arrive.",
140
+ },
128
141
  { title: "Chromatic prompt", path: "prompts/chromatic.md" },
129
142
  ],
130
143
  },
@@ -1,4 +1,5 @@
1
1
  import type { Meta, StoryObj } from "@storybook/react";
2
+ import { userEvent, within, expect } from "storybook/test";
2
3
  import {
3
4
  Accordion,
4
5
  AccordionItem,
@@ -110,6 +111,26 @@ export const Disabled: Story = {
110
111
  ),
111
112
  };
112
113
 
114
+ export const Interaction_Opens: Story = {
115
+ tags: ["test"],
116
+ render: () => (
117
+ <Accordion type="single" collapsible className="w-[400px]">
118
+ <AccordionItem value="item-1">
119
+ <AccordionTrigger>What is BADS?</AccordionTrigger>
120
+ <AccordionContent>A portable, agentic design system.</AccordionContent>
121
+ </AccordionItem>
122
+ </Accordion>
123
+ ),
124
+ play: async ({ canvasElement }) => {
125
+ const canvas = within(canvasElement);
126
+ const trigger = canvas.getByRole("button", { name: /what is bads/i });
127
+ expect(trigger).toHaveAttribute("data-state", "closed");
128
+ await userEvent.click(trigger);
129
+ expect(trigger).toHaveAttribute("data-state", "open");
130
+ expect(canvas.getByText("A portable, agentic design system.")).toBeVisible();
131
+ },
132
+ };
133
+
113
134
  export const RealisticUse: Story = {
114
135
  render: () => (
115
136
  <div className="w-[480px] rounded-lg border bg-card p-6">
@@ -1,4 +1,5 @@
1
1
  import { Meta, StoryObj } from "@storybook/react"
2
+ import { userEvent, within, expect, fn } from "storybook/test"
2
3
  import { Button } from "@behavioral-agentic-design-system/core/components/ui/button"
3
4
  import { Heart } from "lucide-react"
4
5
 
@@ -125,6 +126,20 @@ export const RealisticUse: Story = {
125
126
  // base class. Default and the icon sizes used to fall through to rounded-full
126
127
  // (pill / circle) while the rest were rounded-md; this row exists so that
127
128
  // inconsistency can't silently come back.
129
+ export const Interaction_Click: Story = {
130
+ tags: ["test"],
131
+ args: {
132
+ children: "Save Changes",
133
+ onClick: fn(),
134
+ },
135
+ play: async ({ canvasElement, args }) => {
136
+ const canvas = within(canvasElement);
137
+ const button = canvas.getByRole("button", { name: /save changes/i });
138
+ await userEvent.click(button);
139
+ expect(args.onClick).toHaveBeenCalledOnce();
140
+ },
141
+ };
142
+
128
143
  export const AllSizes: Story = {
129
144
  render: () => (
130
145
  <div className="flex flex-wrap items-center gap-3">
@@ -20,7 +20,7 @@ type Story = StoryObj<typeof CopyButton>
20
20
 
21
21
  export const Default: Story = {
22
22
  render: () => (
23
- <CopyButton value="hello@example.com">Copy email</CopyButton>
23
+ <CopyButton value="jordan@reeves.design">Copy email</CopyButton>
24
24
  ),
25
25
  }
26
26
 
@@ -42,7 +42,7 @@ export const Variant_Ghost: Story = {
42
42
 
43
43
  export const Variant_Secondary: Story = {
44
44
  render: () => (
45
- <CopyButton value="https://example.com/share/abc123" variant="secondary">
45
+ <CopyButton value="https://design.bads.com/share/tokens-v2-proposal" variant="secondary">
46
46
  Copy link
47
47
  </CopyButton>
48
48
  ),
@@ -5,6 +5,7 @@
5
5
  // canonical demonstration. Mechanism is identical here; no separate\
6
6
  // story added because the demo would duplicate Sheet's.
7
7
  import { Meta, StoryObj } from "@storybook/react";
8
+ import { userEvent, within, expect, waitFor } from "storybook/test";
8
9
  import {
9
10
  Dialog,
10
11
  DialogTrigger,
@@ -161,6 +162,38 @@ export const Size_Full: Story = {
161
162
  ),
162
163
  };
163
164
 
165
+ export const Interaction_Opens: Story = {
166
+ tags: ["test"],
167
+ render: () => (
168
+ <Dialog>
169
+ <DialogTrigger asChild>
170
+ <Button>Open Dialog</Button>
171
+ </DialogTrigger>
172
+ <DialogContent size="sm">
173
+ <DialogHeader>
174
+ <DialogTitle>Confirm Action</DialogTitle>
175
+ <DialogDescription>This action cannot be undone.</DialogDescription>
176
+ </DialogHeader>
177
+ <DialogFooter>
178
+ <DialogClose asChild>
179
+ <Button variant="outline">Cancel</Button>
180
+ </DialogClose>
181
+ </DialogFooter>
182
+ </DialogContent>
183
+ </Dialog>
184
+ ),
185
+ play: async ({ canvasElement }) => {
186
+ const canvas = within(canvasElement);
187
+ await userEvent.click(canvas.getByRole("button", { name: /open dialog/i }));
188
+ // Dialog portals to document.body — query from there. The content's
189
+ // fade-in-0 entrance starts at opacity 0, so toBeVisible() must wait
190
+ // for the animation to finish rather than assert on mount.
191
+ const dialog = await within(document.body).findByRole("dialog");
192
+ await waitFor(() => expect(dialog).toBeVisible());
193
+ expect(within(dialog).getByText("Confirm Action")).toBeVisible();
194
+ },
195
+ };
196
+
164
197
  export const RealisticUse: Story = {
165
198
  render: () => (
166
199
  <Dialog>
@@ -0,0 +1,170 @@
1
+ import type { Meta, StoryObj } from "@storybook/react"
2
+ import * as React from "react"
3
+
4
+ import {
5
+ Editable,
6
+ EditableCancel,
7
+ EditableControl,
8
+ EditablePreview,
9
+ EditableSubmit,
10
+ } from "../components/ui/editable"
11
+
12
+ const meta: Meta<typeof Editable> = {
13
+ title: "Components/Editable",
14
+ component: Editable,
15
+ parameters: { layout: "centered" },
16
+ tags: ["autodocs"],
17
+ }
18
+
19
+ export default meta
20
+ type Story = StoryObj<typeof Editable>
21
+
22
+ export const Default: Story = {
23
+ render: () => (
24
+ <div className="w-64">
25
+ <Editable defaultValue="Project Alpha">
26
+ <EditablePreview />
27
+ </Editable>
28
+ </div>
29
+ ),
30
+ }
31
+
32
+ // The overlay input covers only the preview area, so the Save/Cancel controls
33
+ // render below it (visible) once editing begins — not hidden behind the input.
34
+ // Save/Cancel are the BADS Button primitive (default + ghost), spaced with gap-2.
35
+ export const WithControls: Story = {
36
+ render: () => (
37
+ <div className="w-64">
38
+ <Editable defaultValue="Untitled sprint" submitMode="enter">
39
+ <EditablePreview />
40
+ <EditableControl>
41
+ <EditableSubmit />
42
+ <EditableCancel />
43
+ </EditableControl>
44
+ </Editable>
45
+ </div>
46
+ ),
47
+ }
48
+
49
+ export const SubmitMode_Blur: Story = {
50
+ render: () => (
51
+ <div className="w-64">
52
+ <Editable defaultValue="Click to edit, then blur to save" submitMode="blur">
53
+ <EditablePreview />
54
+ </Editable>
55
+ </div>
56
+ ),
57
+ }
58
+
59
+ export const SubmitMode_Enter: Story = {
60
+ render: () => (
61
+ <div className="w-64">
62
+ <Editable defaultValue="Press Enter to save, Escape to cancel" submitMode="enter">
63
+ <EditablePreview />
64
+ <EditableControl>
65
+ <EditableSubmit>Save</EditableSubmit>
66
+ <EditableCancel>Cancel</EditableCancel>
67
+ </EditableControl>
68
+ </Editable>
69
+ </div>
70
+ ),
71
+ }
72
+
73
+ // Disabled renders as a single dimmed (opacity-50) preview label — the overlay
74
+ // input stays hidden, so the value is not ghosted over itself.
75
+ export const Disabled: Story = {
76
+ render: () => (
77
+ <div className="w-64">
78
+ <Editable defaultValue="Read-only field" disabled>
79
+ <EditablePreview />
80
+ </Editable>
81
+ </div>
82
+ ),
83
+ }
84
+
85
+ export const WithPlaceholder: Story = {
86
+ render: () => (
87
+ <div className="w-64">
88
+ <Editable defaultValue="" placeholder="Add a title...">
89
+ <EditablePreview />
90
+ </Editable>
91
+ </div>
92
+ ),
93
+ }
94
+
95
+ // Keyboard contract: Enter/Space on the preview opens edit mode (focus moves to
96
+ // the input), Escape cancels and Enter (submitMode enter/both) saves — in both
97
+ // cases focus RETURNS to the preview instead of stranding on the aria-hidden
98
+ // input or an unmounted Save/Cancel button. Blur-submit (clicking elsewhere)
99
+ // deliberately does NOT steal focus back. `label` names the edit input for
100
+ // screen readers; without it the input falls back to the placeholder text.
101
+ export const KeyboardFocusReturn: Story = {
102
+ render: () => (
103
+ <div className="w-64">
104
+ <Editable defaultValue="Tab here, press Enter, then Escape" label="Demo field" submitMode="both">
105
+ <EditablePreview />
106
+ <EditableControl>
107
+ <EditableSubmit />
108
+ <EditableCancel />
109
+ </EditableControl>
110
+ </Editable>
111
+ </div>
112
+ ),
113
+ }
114
+
115
+ export const Controlled: Story = {
116
+ render: () => {
117
+ const [value, setValue] = React.useState("Maya Chen")
118
+ return (
119
+ <div className="w-64 space-y-2">
120
+ <p className="text-xs text-muted-foreground">
121
+ Controlled: {JSON.stringify(value)}
122
+ </p>
123
+ <Editable value={value} onValueChange={setValue}>
124
+ <EditablePreview />
125
+ </Editable>
126
+ </div>
127
+ )
128
+ },
129
+ }
130
+
131
+ export const RealisticUse: Story = {
132
+ render: () => {
133
+ const [name, setName] = React.useState("Brand refresh sprint")
134
+ const [lead, setLead] = React.useState("Maya Chen")
135
+
136
+ return (
137
+ <div className="w-72 rounded-lg border border-border bg-card p-4 shadow-sm">
138
+ <p className="mb-3 text-xs font-medium uppercase tracking-wide text-muted-foreground">
139
+ Project Details
140
+ </p>
141
+ <div className="space-y-1">
142
+ <label className="text-xs text-muted-foreground">Project name</label>
143
+ <Editable
144
+ value={name}
145
+ onValueChange={setName}
146
+ label="Project name"
147
+ submitMode="blur"
148
+ >
149
+ <EditablePreview className="text-base font-medium" />
150
+ </Editable>
151
+ </div>
152
+ <div className="mt-3 space-y-1">
153
+ <label className="text-xs text-muted-foreground">Design lead</label>
154
+ <Editable
155
+ value={lead}
156
+ onValueChange={setLead}
157
+ label="Design lead"
158
+ submitMode="both"
159
+ >
160
+ <EditablePreview />
161
+ <EditableControl>
162
+ <EditableSubmit />
163
+ <EditableCancel />
164
+ </EditableControl>
165
+ </Editable>
166
+ </div>
167
+ </div>
168
+ )
169
+ },
170
+ }
@@ -26,7 +26,7 @@ export const Default: Story = {
26
26
  <Field name="email" required>
27
27
  <FieldLabel>Email address</FieldLabel>
28
28
  <FieldControl>
29
- <Input type="email" placeholder="you@example.com" autoComplete="email" />
29
+ <Input type="email" placeholder="jordan@reeves.design" autoComplete="email" />
30
30
  </FieldControl>
31
31
  <FieldHelper>We&apos;ll never share it.</FieldHelper>
32
32
  </Field>