@behavioral-agentic-design-system/core 0.15.0 → 0.17.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.
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  import * as React from "react";
4
- import { XIcon } from "lucide-react";
4
+ import { XIcon, CheckIcon } from "lucide-react";
5
5
  import { cn } from "../../lib/utils";
6
6
 
7
7
  // ─── Types ────────────────────────────────────────────────────────────────────
@@ -22,6 +22,11 @@ export interface TagsInputProps
22
22
  allowDuplicates?: boolean;
23
23
  /** Characters that trigger tag creation in addition to Enter. Default: [","]. */
24
24
  delimiters?: string[];
25
+ /**
26
+ * Pool of suggestion strings shown in a dropdown as the user types.
27
+ * Already-added tags are excluded from the list automatically.
28
+ */
29
+ suggestions?: string[];
25
30
  }
26
31
 
27
32
  // ─── Component ────────────────────────────────────────────────────────────────
@@ -34,15 +39,30 @@ export function TagsInput({
34
39
  maxTags,
35
40
  allowDuplicates = false,
36
41
  delimiters = [","],
42
+ suggestions,
37
43
  className,
38
44
  ...props
39
45
  }: TagsInputProps) {
40
46
  const [inputValue, setInputValue] = React.useState("");
41
47
  const [focusedTagIndex, setFocusedTagIndex] = React.useState<number | null>(null);
48
+ const [activeIndex, setActiveIndex] = React.useState(-1);
49
+ const [showSuggestions, setShowSuggestions] = React.useState(false);
42
50
  const inputRef = React.useRef<HTMLInputElement>(null);
51
+ const listboxRef = React.useRef<HTMLUListElement>(null);
52
+ const listboxId = React.useId();
43
53
 
44
54
  const atMax = maxTags !== undefined && value.length >= maxTags;
45
55
 
56
+ const filteredSuggestions = React.useMemo(() => {
57
+ if (!suggestions?.length || !inputValue.trim()) return [];
58
+ const lower = inputValue.toLowerCase();
59
+ return suggestions.filter(
60
+ (s) => s.toLowerCase().includes(lower) && (allowDuplicates || !value.includes(s))
61
+ );
62
+ }, [suggestions, inputValue, value, allowDuplicates]);
63
+
64
+ const isOpen = showSuggestions && filteredSuggestions.length > 0;
65
+
46
66
  const addTag = React.useCallback(
47
67
  (raw: string) => {
48
68
  const trimmed = raw.trim();
@@ -51,6 +71,8 @@ export function TagsInput({
51
71
  if (!allowDuplicates && value.includes(trimmed)) return;
52
72
  onValueChange([...value, trimmed]);
53
73
  setInputValue("");
74
+ setShowSuggestions(false);
75
+ setActiveIndex(-1);
54
76
  },
55
77
  [atMax, allowDuplicates, value, onValueChange]
56
78
  );
@@ -64,28 +86,79 @@ export function TagsInput({
64
86
  [value, onValueChange]
65
87
  );
66
88
 
89
+ const selectSuggestion = React.useCallback(
90
+ (suggestion: string) => {
91
+ addTag(suggestion);
92
+ inputRef.current?.focus();
93
+ },
94
+ [addTag]
95
+ );
96
+
97
+ // Scroll the active option into view
98
+ React.useEffect(() => {
99
+ if (!isOpen || activeIndex < 0) return;
100
+ const li = listboxRef.current?.children[activeIndex] as HTMLElement | undefined;
101
+ li?.scrollIntoView({ block: "nearest" });
102
+ }, [activeIndex, isOpen]);
103
+
67
104
  const handleKeyDown = React.useCallback(
68
105
  (e: React.KeyboardEvent<HTMLInputElement>) => {
106
+ if (e.key === "ArrowDown") {
107
+ if (!isOpen && filteredSuggestions.length > 0) {
108
+ setShowSuggestions(true);
109
+ setActiveIndex(0);
110
+ } else if (isOpen) {
111
+ e.preventDefault();
112
+ setActiveIndex((i) => Math.min(i + 1, filteredSuggestions.length - 1));
113
+ }
114
+ return;
115
+ }
116
+ if (e.key === "ArrowUp" && isOpen) {
117
+ e.preventDefault();
118
+ setActiveIndex((i) => (i <= 0 ? 0 : i - 1));
119
+ return;
120
+ }
69
121
  if (e.key === "Enter") {
70
122
  e.preventDefault();
71
- addTag(inputValue);
72
- } else if (e.key === "Backspace" && inputValue === "") {
123
+ if (isOpen && activeIndex >= 0) {
124
+ selectSuggestion(filteredSuggestions[activeIndex]);
125
+ } else {
126
+ addTag(inputValue);
127
+ }
128
+ return;
129
+ }
130
+ if (e.key === "Escape") {
131
+ if (isOpen) {
132
+ setShowSuggestions(false);
133
+ setActiveIndex(-1);
134
+ } else {
135
+ setFocusedTagIndex(null);
136
+ }
137
+ return;
138
+ }
139
+ if (e.key === "Backspace" && inputValue === "") {
73
140
  e.preventDefault();
74
141
  if (focusedTagIndex !== null) {
75
142
  removeTag(focusedTagIndex);
76
143
  } else if (value.length > 0) {
77
144
  setFocusedTagIndex(value.length - 1);
78
145
  }
79
- } else if (e.key === "Delete" && inputValue === "" && focusedTagIndex !== null) {
146
+ return;
147
+ }
148
+ if (e.key === "Delete" && inputValue === "" && focusedTagIndex !== null) {
80
149
  e.preventDefault();
81
150
  removeTag(focusedTagIndex);
82
- } else if (e.key === "ArrowLeft" && inputValue === "") {
151
+ return;
152
+ }
153
+ if (e.key === "ArrowLeft" && inputValue === "") {
83
154
  if (focusedTagIndex === null && value.length > 0) {
84
155
  setFocusedTagIndex(value.length - 1);
85
156
  } else if (focusedTagIndex !== null && focusedTagIndex > 0) {
86
157
  setFocusedTagIndex(focusedTagIndex - 1);
87
158
  }
88
- } else if (e.key === "ArrowRight" && inputValue === "") {
159
+ return;
160
+ }
161
+ if (e.key === "ArrowRight" && inputValue === "") {
89
162
  if (focusedTagIndex !== null) {
90
163
  if (focusedTagIndex < value.length - 1) {
91
164
  setFocusedTagIndex(focusedTagIndex + 1);
@@ -93,13 +166,21 @@ export function TagsInput({
93
166
  setFocusedTagIndex(null);
94
167
  }
95
168
  }
96
- } else if (e.key === "Escape") {
97
- setFocusedTagIndex(null);
98
- } else {
99
- setFocusedTagIndex(null);
169
+ return;
100
170
  }
171
+ setFocusedTagIndex(null);
101
172
  },
102
- [inputValue, focusedTagIndex, value, addTag, removeTag]
173
+ [
174
+ inputValue,
175
+ focusedTagIndex,
176
+ value,
177
+ addTag,
178
+ removeTag,
179
+ selectSuggestion,
180
+ isOpen,
181
+ activeIndex,
182
+ filteredSuggestions,
183
+ ]
103
184
  );
104
185
 
105
186
  const handleInputChange = React.useCallback(
@@ -110,6 +191,8 @@ export function TagsInput({
110
191
  addTag(val.slice(0, -1));
111
192
  } else {
112
193
  setInputValue(val);
194
+ setShowSuggestions(true);
195
+ setActiveIndex(-1);
113
196
  }
114
197
  setFocusedTagIndex(null);
115
198
  },
@@ -124,76 +207,134 @@ export function TagsInput({
124
207
  : undefined;
125
208
 
126
209
  return (
127
- <div
128
- data-slot="tags-input"
129
- data-disabled={disabled || undefined}
130
- aria-disabled={disabled || undefined}
131
- onClick={() => !disabled && inputRef.current?.focus()}
132
- className={cn(
133
- "flex min-h-11 flex-wrap items-center gap-1.5 rounded-md border border-input bg-background px-3 py-2",
134
- "cursor-text",
135
- "focus-within:outline-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",
136
- disabled && "cursor-not-allowed border-border/50 bg-muted/30 pointer-events-none",
137
- className
138
- )}
139
- {...props}
140
- >
141
- {value.map((tag, index) => (
142
- <span
143
- key={`${tag}-${index}`}
144
- data-slot="tags-input-item"
145
- data-focused={focusedTagIndex === index || undefined}
210
+ <div className="relative">
211
+ <div
212
+ data-slot="tags-input"
213
+ data-disabled={disabled || undefined}
214
+ aria-disabled={disabled || undefined}
215
+ onClick={() => !disabled && inputRef.current?.focus()}
216
+ className={cn(
217
+ "flex min-h-11 flex-wrap items-center gap-1.5 rounded-md border border-input bg-background px-3 py-2",
218
+ "cursor-text",
219
+ "focus-within:outline-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",
220
+ disabled && "cursor-not-allowed border-border/50 bg-muted/30 pointer-events-none",
221
+ className
222
+ )}
223
+ {...props}
224
+ >
225
+ {value.map((tag, index) => (
226
+ <span
227
+ key={`${tag}-${index}`}
228
+ data-slot="tags-input-item"
229
+ data-focused={focusedTagIndex === index || undefined}
230
+ className={cn(
231
+ "inline-flex max-w-[160px] items-center gap-1 rounded-md px-2 py-0.5",
232
+ "text-sm font-medium transition-colors",
233
+ disabled
234
+ ? "bg-muted text-muted-foreground"
235
+ : "bg-secondary text-secondary-foreground",
236
+ !disabled && focusedTagIndex === index && "ring-2 ring-ring ring-offset-1 ring-offset-background"
237
+ )}
238
+ >
239
+ <span className="truncate">{tag}</span>
240
+ {!disabled && (
241
+ <button
242
+ type="button"
243
+ data-slot="tags-input-item-delete"
244
+ aria-label={`Remove ${tag}`}
245
+ tabIndex={-1}
246
+ onClick={(e) => {
247
+ e.stopPropagation();
248
+ removeTag(index);
249
+ }}
250
+ className={cn(
251
+ "shrink-0 rounded-sm p-0.5",
252
+ "text-secondary-foreground/70 hover:text-secondary-foreground",
253
+ "transition-colors",
254
+ "focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
255
+ )}
256
+ style={{
257
+ transitionDuration: "var(--duration-fast)",
258
+ transitionTimingFunction: "var(--ease-out)",
259
+ }}
260
+ >
261
+ <XIcon className="size-3" strokeWidth={1.5} aria-hidden />
262
+ </button>
263
+ )}
264
+ </span>
265
+ ))}
266
+ <input
267
+ ref={inputRef}
268
+ type="text"
269
+ role="combobox"
270
+ aria-expanded={isOpen}
271
+ aria-haspopup="listbox"
272
+ aria-controls={isOpen ? listboxId : undefined}
273
+ aria-activedescendant={isOpen && activeIndex >= 0 ? `${listboxId}-${activeIndex}` : undefined}
274
+ aria-autocomplete={suggestions?.length ? "list" : "none"}
275
+ value={inputValue}
276
+ onChange={handleInputChange}
277
+ onKeyDown={handleKeyDown}
278
+ onFocus={() => inputValue && setShowSuggestions(true)}
279
+ onBlur={() => {
280
+ // Small delay so option click fires before blur closes the list
281
+ setTimeout(() => setShowSuggestions(false), 120);
282
+ }}
283
+ disabled={disabled || atMax}
284
+ placeholder={inputPlaceholder}
285
+ aria-label={placeholder ?? "Add tags, press Enter or comma to confirm"}
146
286
  className={cn(
147
- "inline-flex max-w-[160px] items-center gap-1 rounded-md px-2 py-0.5",
148
- "text-sm font-medium transition-colors",
149
- disabled
150
- ? "bg-muted text-muted-foreground"
151
- : "bg-secondary text-secondary-foreground",
152
- !disabled && focusedTagIndex === index && "ring-2 ring-ring ring-offset-1 ring-offset-background"
287
+ "min-w-[80px] flex-1 bg-transparent text-sm outline-none",
288
+ "placeholder:text-muted-foreground",
289
+ "disabled:cursor-not-allowed disabled:opacity-0"
290
+ )}
291
+ />
292
+ </div>
293
+
294
+ {isOpen && (
295
+ <ul
296
+ ref={listboxRef}
297
+ id={listboxId}
298
+ role="listbox"
299
+ aria-label="Suggestions"
300
+ className={cn(
301
+ "absolute left-0 right-0 z-50 mt-1 max-h-56 overflow-y-auto",
302
+ "rounded-md border border-input bg-popover shadow-md",
303
+ "py-1 text-sm text-popover-foreground"
153
304
  )}
154
305
  >
155
- <span className="truncate">{tag}</span>
156
- {!disabled && (
157
- <button
158
- type="button"
159
- data-slot="tags-input-item-delete"
160
- aria-label={`Remove ${tag}`}
161
- tabIndex={-1}
162
- onClick={(e) => {
163
- e.stopPropagation();
164
- removeTag(index);
306
+ {filteredSuggestions.map((suggestion, index) => (
307
+ <li
308
+ key={suggestion}
309
+ id={`${listboxId}-${index}`}
310
+ role="option"
311
+ aria-selected={index === activeIndex}
312
+ onMouseDown={(e) => {
313
+ // prevent input blur before click registers
314
+ e.preventDefault();
315
+ selectSuggestion(suggestion);
165
316
  }}
317
+ onMouseEnter={() => setActiveIndex(index)}
166
318
  className={cn(
167
- "shrink-0 rounded-sm p-0.5",
168
- "text-secondary-foreground/70 hover:text-secondary-foreground",
319
+ "flex items-center gap-2 px-3 py-1.5 cursor-pointer select-none",
169
320
  "transition-colors",
170
- "focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
321
+ index === activeIndex
322
+ ? "bg-accent text-accent-foreground"
323
+ : "hover:bg-accent hover:text-accent-foreground"
171
324
  )}
172
325
  style={{
173
326
  transitionDuration: "var(--duration-fast)",
174
327
  transitionTimingFunction: "var(--ease-out)",
175
328
  }}
176
329
  >
177
- <XIcon className="size-3" strokeWidth={1.5} aria-hidden />
178
- </button>
179
- )}
180
- </span>
181
- ))}
182
- <input
183
- ref={inputRef}
184
- type="text"
185
- value={inputValue}
186
- onChange={handleInputChange}
187
- onKeyDown={handleKeyDown}
188
- disabled={disabled || atMax}
189
- placeholder={inputPlaceholder}
190
- aria-label={placeholder ?? "Add tags, press Enter or comma to confirm"}
191
- className={cn(
192
- "min-w-[80px] flex-1 bg-transparent text-sm outline-none",
193
- "placeholder:text-muted-foreground",
194
- "disabled:cursor-not-allowed disabled:opacity-0"
195
- )}
196
- />
330
+ {suggestion}
331
+ {value.includes(suggestion) && (
332
+ <CheckIcon className="ml-auto h-3.5 w-3.5 text-primary" aria-hidden="true" strokeWidth={1.5} />
333
+ )}
334
+ </li>
335
+ ))}
336
+ </ul>
337
+ )}
197
338
  </div>
198
339
  );
199
340
  }
@@ -24,7 +24,7 @@ export type PrimaryColorOption = {
24
24
  custom?: boolean;
25
25
  /**
26
26
  * Optional override for the picker swatch when the displayed color should
27
- * differ from the applied primary. Carried over from the swimtopia customize
27
+ * differ from the applied primary. Carried over from a client fork's customize
28
28
  * tab (e.g. an "Off White" option that applies dark in light mode but the
29
29
  * picker still reads off-white). BADS' built-in palette doesn't set these.
30
30
  */
package/src/styles.css CHANGED
@@ -480,7 +480,7 @@
480
480
  * role. Disabled state → cursor: not-allowed so "off" reads as
481
481
  * intentional rather than broken.
482
482
  *
483
- * Promoted from swimtopia-prototypes globals.css (2026-06-10) per
483
+ * Promoted from a client fork's globals.css (2026-06-10) per
484
484
  * Sir's "if it's clickable, the cursor says so" rule. */
485
485
  button:not(:disabled),
486
486
  a[href]:not([aria-disabled="true"]),
@@ -524,7 +524,7 @@ html, body {
524
524
  written to --x / --y on <html> before startViewTransition fires (see
525
525
  app/page.tsx toggleDark).
526
526
 
527
- Two deliberate choices, both learned the hard way (swimtopia, 2026-06):
527
+ Two deliberate choices, both learned the hard way (a client fork, 2026-06):
528
528
  1. Radius is a VIEWPORT unit (150vmax), not a percentage. circle(150%)
529
529
  resolves against the snapshot box, so on a large/wide desktop the wipe
530
530
  can finish before it has covered the viewport — a glitch at the END of
@@ -1,133 +0,0 @@
1
- "use client"
2
-
3
- import * as React from "react"
4
-
5
- import { cn } from "../../lib/utils"
6
- import {
7
- Sheet,
8
- SheetClose,
9
- SheetContent,
10
- SheetDescription,
11
- SheetFooter,
12
- SheetHeader,
13
- SheetTitle,
14
- SheetTrigger,
15
- } from "./sheet"
16
-
17
- /**
18
- * BottomSheet — a bottom-anchored disclosure surface, the dominant
19
- * secondary-content container in current production apps (Raycast, Linear
20
- * mobile, Arc). Built on the Radix Dialog–backed Sheet primitive with
21
- * `side="bottom"`, so it inherits Sheet's focus trap, ESC/overlay dismissal,
22
- * scroll lock, and AAA-tuned focus ring for free.
23
- *
24
- * What this adds over `<SheetContent side="bottom">`:
25
- * - Rounded top corners + a centered grab-handle affordance (the visual
26
- * signal users now read as "this panel came from the bottom").
27
- * - Mobile-first sizing: caps at 85svh and scrolls internally so a tall
28
- * sheet never pushes its footer off-screen.
29
- * - A coherent BottomSheet* API surface so callers don't mix Sheet and
30
- * BottomSheet names.
31
- *
32
- * Not draggable. This wrapper is intentionally built on Radix, not vaul, so
33
- * there are no drag-to-dismiss physics or snap points — dismissal is via the
34
- * grab handle (decorative), overlay click, ESC, or an explicit close button.
35
- * If a fork needs true drag/snap behavior, that's a separate vaul-backed
36
- * primitive and a deliberate dependency decision (see CHANGELOG 2026-05-31).
37
- */
38
-
39
- function BottomSheet({ ...props }: React.ComponentProps<typeof Sheet>) {
40
- return <Sheet data-slot="bottom-sheet" {...props} />
41
- }
42
-
43
- function BottomSheetTrigger({
44
- ...props
45
- }: React.ComponentProps<typeof SheetTrigger>) {
46
- return <SheetTrigger data-slot="bottom-sheet-trigger" {...props} />
47
- }
48
-
49
- function BottomSheetClose({
50
- ...props
51
- }: React.ComponentProps<typeof SheetClose>) {
52
- return <SheetClose data-slot="bottom-sheet-close" {...props} />
53
- }
54
-
55
- function BottomSheetContent({
56
- className,
57
- children,
58
- showHandle = true,
59
- showCloseButton = true,
60
- ...props
61
- }: React.ComponentProps<typeof SheetContent> & {
62
- /** Show the decorative grab-handle affordance at the top. Default true. */
63
- showHandle?: boolean
64
- }) {
65
- return (
66
- <SheetContent
67
- side="bottom"
68
- showCloseButton={showCloseButton}
69
- data-slot="bottom-sheet-content"
70
- className={cn(
71
- // Rounded top + capped height + internal scroll so a tall sheet keeps
72
- // its footer reachable. svh tracks the mobile dynamic viewport.
73
- "max-h-[85svh] gap-0 overflow-y-auto rounded-t-xl pb-[max(1rem,env(safe-area-inset-bottom))]",
74
- className
75
- )}
76
- {...props}
77
- >
78
- {showHandle && (
79
- <div
80
- aria-hidden="true"
81
- className="mx-auto mt-3 mb-1 h-1.5 w-12 shrink-0 rounded-full bg-muted-foreground/30"
82
- />
83
- )}
84
- {children}
85
- </SheetContent>
86
- )
87
- }
88
-
89
- // Header/Footer/Title/Description are 1:1 with Sheet's — re-exported under the
90
- // BottomSheet name so callers get a single coherent API.
91
- function BottomSheetHeader({
92
- ...props
93
- }: React.ComponentProps<typeof SheetHeader>) {
94
- return <SheetHeader data-slot="bottom-sheet-header" {...props} />
95
- }
96
-
97
- function BottomSheetFooter({
98
- ...props
99
- }: React.ComponentProps<typeof SheetFooter>) {
100
- return <SheetFooter data-slot="bottom-sheet-footer" {...props} />
101
- }
102
-
103
- function BottomSheetTitle({
104
- className,
105
- children,
106
- ...props
107
- }: React.ComponentProps<typeof SheetTitle>) {
108
- // Render as a real h3 (Sheet/Dialog Title defaults to h2 and ships no size).
109
- // asChild keeps the Radix Title wiring so the sheet stays aria-labelledby it,
110
- // while the h3 carries an explicit heading size for clear hierarchy.
111
- return (
112
- <SheetTitle asChild data-slot="bottom-sheet-title" {...props}>
113
- <h3 className={cn("text-lg", className)}>{children}</h3>
114
- </SheetTitle>
115
- )
116
- }
117
-
118
- function BottomSheetDescription({
119
- ...props
120
- }: React.ComponentProps<typeof SheetDescription>) {
121
- return <SheetDescription data-slot="bottom-sheet-description" {...props} />
122
- }
123
-
124
- export {
125
- BottomSheet,
126
- BottomSheetTrigger,
127
- BottomSheetClose,
128
- BottomSheetContent,
129
- BottomSheetHeader,
130
- BottomSheetFooter,
131
- BottomSheetTitle,
132
- BottomSheetDescription,
133
- }