@behavioral-agentic-design-system/core 0.27.0 → 0.29.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 (113) hide show
  1. package/package.json +5 -5
  2. package/scripts/a11y-lint.cjs +78 -9
  3. package/scripts/build-tokens.cjs +273 -15
  4. package/scripts/wcag-audit.cjs +37 -7
  5. package/src/api/layers/file.ts +1 -0
  6. package/src/app/font-ready.tsx +6 -5
  7. package/src/app/layout.tsx +54 -3
  8. package/src/app/preview/components/page.tsx +5735 -2500
  9. package/src/app/preview/layout.tsx +4 -1
  10. package/src/app/preview/showcase-filter.tsx +66 -0
  11. package/src/app/preview/tab-replay.tsx +63 -0
  12. package/src/app/shell.tsx +91 -18
  13. package/src/components/customize/save-bar.tsx +19 -6
  14. package/src/components/docs-tab.tsx +36 -24
  15. package/src/components/layers-tab.tsx +37 -5
  16. package/src/components/ui/ai-badge.tsx +74 -0
  17. package/src/components/ui/alert.tsx +12 -0
  18. package/src/components/ui/badge.tsx +19 -0
  19. package/src/components/ui/chat-bubble.tsx +298 -0
  20. package/src/components/ui/chat-marker.tsx +120 -0
  21. package/src/components/ui/checkbox.tsx +9 -1
  22. package/src/components/ui/clipboard.tsx +291 -0
  23. package/src/components/ui/close-button.tsx +71 -0
  24. package/src/components/ui/combobox.tsx +62 -3
  25. package/src/components/ui/container.tsx +65 -0
  26. package/src/components/ui/copy-button.tsx +5 -1
  27. package/src/components/ui/data-table.tsx +388 -0
  28. package/src/components/ui/date-field.tsx +368 -0
  29. package/src/components/ui/drawer.tsx +334 -0
  30. package/src/components/ui/file-button.tsx +145 -0
  31. package/src/components/ui/floating-indicator.tsx +217 -0
  32. package/src/components/ui/focus-trap.tsx +184 -0
  33. package/src/components/ui/format-byte.tsx +113 -0
  34. package/src/components/ui/index.ts +28 -0
  35. package/src/components/ui/input.tsx +38 -3
  36. package/src/components/ui/keyboard-shortcut.tsx +146 -0
  37. package/src/components/ui/loading-dots.tsx +99 -0
  38. package/src/components/ui/mark.tsx +69 -0
  39. package/src/components/ui/month-picker.tsx +296 -0
  40. package/src/components/ui/multi-select.tsx +15 -13
  41. package/src/components/ui/nav-link.tsx +200 -0
  42. package/src/components/ui/navigation-rail.tsx +256 -0
  43. package/src/components/ui/notification.tsx +20 -0
  44. package/src/components/ui/password-input.tsx +34 -1
  45. package/src/components/ui/progress.tsx +15 -1
  46. package/src/components/ui/prose.tsx +62 -0
  47. package/src/components/ui/result.tsx +151 -0
  48. package/src/components/ui/rolling-number.tsx +201 -0
  49. package/src/components/ui/simple-grid.tsx +110 -0
  50. package/src/components/ui/skeleton.tsx +52 -3
  51. package/src/components/ui/squircle.tsx +274 -0
  52. package/src/components/ui/stack.tsx +105 -0
  53. package/src/components/ui/status-badge.tsx +93 -0
  54. package/src/components/ui/tabs.tsx +34 -7
  55. package/src/components/ui/tag.tsx +46 -5
  56. package/src/components/ui/theme-icon.tsx +138 -0
  57. package/src/components/ui/timeline.tsx +27 -10
  58. package/src/components/ui/tooltip.tsx +12 -1
  59. package/src/components/ui/tree-select.tsx +386 -0
  60. package/src/components/ui/typing-indicator.tsx +2 -2
  61. package/src/components/ui/word-rotate.tsx +6 -1
  62. package/src/components/ui/year-picker.tsx +307 -0
  63. package/src/data/docs-index.ts +10 -0
  64. package/src/hooks/use-global-primary-color.ts +57 -6
  65. package/src/stories/AiBadge.stories.tsx +67 -0
  66. package/src/stories/Alert.stories.tsx +31 -1
  67. package/src/stories/Badge.stories.tsx +63 -6
  68. package/src/stories/ChatBubble.stories.tsx +222 -0
  69. package/src/stories/ChatMarker.stories.tsx +59 -0
  70. package/src/stories/Checkbox.stories.tsx +5 -0
  71. package/src/stories/Clipboard.stories.tsx +136 -0
  72. package/src/stories/CloseButton.stories.tsx +65 -0
  73. package/src/stories/Combobox.stories.tsx +74 -3
  74. package/src/stories/Container.stories.tsx +134 -0
  75. package/src/stories/CopyButton.stories.tsx +2 -0
  76. package/src/stories/DataTable.stories.tsx +271 -0
  77. package/src/stories/DateField.stories.tsx +114 -0
  78. package/src/stories/Drawer.stories.tsx +211 -0
  79. package/src/stories/FileButton.stories.tsx +117 -0
  80. package/src/stories/FloatingIndicator.stories.tsx +343 -0
  81. package/src/stories/FocusTrap.stories.tsx +218 -0
  82. package/src/stories/FormatByte.stories.tsx +142 -0
  83. package/src/stories/Input.stories.tsx +91 -0
  84. package/src/stories/KeyboardShortcut.stories.tsx +87 -0
  85. package/src/stories/LoadingDots.stories.tsx +73 -0
  86. package/src/stories/Mark.stories.tsx +84 -0
  87. package/src/stories/MonthPicker.stories.tsx +99 -0
  88. package/src/stories/MultiSelect.stories.tsx +3 -1
  89. package/src/stories/NavLink.stories.tsx +213 -0
  90. package/src/stories/NavigationRail.stories.tsx +413 -0
  91. package/src/stories/Notification.stories.tsx +53 -0
  92. package/src/stories/PasswordInput.stories.tsx +21 -0
  93. package/src/stories/Progress.stories.tsx +38 -0
  94. package/src/stories/Prose.stories.tsx +232 -0
  95. package/src/stories/Result.stories.tsx +145 -0
  96. package/src/stories/RollingNumber.stories.tsx +226 -0
  97. package/src/stories/SimpleGrid.stories.tsx +130 -0
  98. package/src/stories/Skeleton.stories.tsx +62 -1
  99. package/src/stories/Squircle.stories.tsx +127 -0
  100. package/src/stories/Stack.stories.tsx +139 -0
  101. package/src/stories/StatusBadge.stories.tsx +125 -0
  102. package/src/stories/Tabs.stories.tsx +56 -1
  103. package/src/stories/Tag.stories.tsx +31 -0
  104. package/src/stories/ThemeIcon.stories.tsx +97 -0
  105. package/src/stories/Timeline.stories.tsx +69 -0
  106. package/src/stories/Tooltip.stories.tsx +18 -0
  107. package/src/stories/TreeSelect.stories.tsx +222 -0
  108. package/src/stories/TypingIndicator.stories.tsx +1 -0
  109. package/src/stories/WordRotate.stories.tsx +1 -0
  110. package/src/stories/YearPicker.stories.tsx +100 -0
  111. package/src/styles.css +289 -15
  112. package/src/tokens.json +96 -1
  113. package/LICENSE +0 -21
@@ -0,0 +1,388 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import {
5
+ type ColumnDef,
6
+ type SortingState,
7
+ type RowSelectionState,
8
+ flexRender,
9
+ getCoreRowModel,
10
+ getSortedRowModel,
11
+ getPaginationRowModel,
12
+ useReactTable,
13
+ } from "@tanstack/react-table"
14
+ import { ChevronUpIcon, ChevronDownIcon, ChevronsUpDownIcon } from "lucide-react"
15
+ import { cva, type VariantProps } from "class-variance-authority"
16
+
17
+ import { cn } from "../../lib/utils"
18
+ import { Button } from "./button"
19
+ import { Checkbox } from "./checkbox"
20
+ import {
21
+ Table,
22
+ TableHeader,
23
+ TableBody,
24
+ TableRow,
25
+ TableHead,
26
+ TableCell,
27
+ } from "./table"
28
+
29
+ // Re-export ColumnDef so consumers don't need a direct @tanstack/react-table import
30
+ export type { ColumnDef }
31
+
32
+ // ---------------------------------------------------------------------------
33
+ // Density variant
34
+ // ---------------------------------------------------------------------------
35
+
36
+ const cellVariants = cva("", {
37
+ variants: {
38
+ density: {
39
+ comfortable: "px-4 py-3",
40
+ dense: "px-3 py-2",
41
+ },
42
+ },
43
+ defaultVariants: {
44
+ density: "comfortable",
45
+ },
46
+ })
47
+
48
+ // ---------------------------------------------------------------------------
49
+ // Props
50
+ // ---------------------------------------------------------------------------
51
+
52
+ export interface DataTablePaginationOptions {
53
+ /** Number of rows per page. Defaults to 10. */
54
+ pageSize?: number
55
+ }
56
+
57
+ export interface DataTableProps<TData> extends VariantProps<typeof cellVariants> {
58
+ columns: ColumnDef<TData>[]
59
+ data: TData[]
60
+ /**
61
+ * Enable column header sorting. Defaults to true.
62
+ */
63
+ sorting?: boolean
64
+ /**
65
+ * When provided, enables built-in pagination. Pass `{}` to use the default
66
+ * pageSize of 10, or `{ pageSize: N }` to override.
67
+ */
68
+ pagination?: DataTablePaginationOptions
69
+ /**
70
+ * When true, prepends a checkbox column for row selection. Tracks selection
71
+ * internally; expose controlled selection by lifting state via a columns
72
+ * definition if needed.
73
+ */
74
+ rowSelection?: boolean
75
+ /**
76
+ * Callback fired when a data row is clicked. Does NOT constitute a
77
+ * selection — pair with rowSelection for accessible multi-select. When
78
+ * provided, rows receive `cursor-pointer` and `data-clickable`.
79
+ */
80
+ onRowClick?: (row: TData) => void
81
+ /**
82
+ * Content to display when the data array is empty.
83
+ * Defaults to the text "No results."
84
+ */
85
+ emptyMessage?: React.ReactNode
86
+ className?: string
87
+ }
88
+
89
+ // ---------------------------------------------------------------------------
90
+ // Sort icon
91
+ // ---------------------------------------------------------------------------
92
+
93
+ function SortIcon({
94
+ direction,
95
+ }: {
96
+ direction: "asc" | "desc" | false
97
+ }) {
98
+ const iconProps = {
99
+ strokeWidth: 1.5 as const,
100
+ className: "size-4 shrink-0",
101
+ }
102
+
103
+ // Wrapper carries the motion transition so the icon itself gets the effect
104
+ const wrapperStyle: React.CSSProperties = {
105
+ transitionDuration: "var(--duration-fast)",
106
+ transitionTimingFunction: "var(--ease-out)",
107
+ transitionProperty: "opacity, transform",
108
+ }
109
+
110
+ if (direction === "asc") {
111
+ return (
112
+ <span
113
+ aria-hidden="true"
114
+ className="inline-flex text-foreground"
115
+ style={wrapperStyle}
116
+ >
117
+ <ChevronUpIcon {...iconProps} />
118
+ </span>
119
+ )
120
+ }
121
+ if (direction === "desc") {
122
+ return (
123
+ <span
124
+ aria-hidden="true"
125
+ className="inline-flex text-foreground"
126
+ style={wrapperStyle}
127
+ >
128
+ <ChevronDownIcon {...iconProps} />
129
+ </span>
130
+ )
131
+ }
132
+ return (
133
+ <span
134
+ aria-hidden="true"
135
+ className="inline-flex text-muted-foreground/60"
136
+ style={wrapperStyle}
137
+ >
138
+ <ChevronsUpDownIcon {...iconProps} />
139
+ </span>
140
+ )
141
+ }
142
+
143
+ // ---------------------------------------------------------------------------
144
+ // SELECT_ALL_COLUMN_ID
145
+ // ---------------------------------------------------------------------------
146
+
147
+ const SELECT_COLUMN_ID = "__select__"
148
+
149
+ function buildSelectionColumn<TData>(): ColumnDef<TData> {
150
+ return {
151
+ id: SELECT_COLUMN_ID,
152
+ header: ({ table }) => (
153
+ <Checkbox
154
+ checked={
155
+ table.getIsAllPageRowsSelected()
156
+ ? true
157
+ : table.getIsSomePageRowsSelected()
158
+ ? "indeterminate"
159
+ : false
160
+ }
161
+ onCheckedChange={(value) =>
162
+ table.toggleAllPageRowsSelected(Boolean(value))
163
+ }
164
+ aria-label="Select all rows on this page"
165
+ className="size-4"
166
+ />
167
+ ),
168
+ cell: ({ row }) => (
169
+ <Checkbox
170
+ checked={row.getIsSelected()}
171
+ onCheckedChange={(value) => row.toggleSelected(Boolean(value))}
172
+ aria-label={`Select row ${row.index + 1}`}
173
+ className="size-4"
174
+ />
175
+ ),
176
+ enableSorting: false,
177
+ enableHiding: false,
178
+ size: 40,
179
+ }
180
+ }
181
+
182
+ // ---------------------------------------------------------------------------
183
+ // DataTable
184
+ // ---------------------------------------------------------------------------
185
+
186
+ function DataTable<TData>({
187
+ columns,
188
+ data,
189
+ sorting: sortingEnabled = true,
190
+ pagination: paginationOptions,
191
+ rowSelection: rowSelectionEnabled = false,
192
+ onRowClick,
193
+ emptyMessage = "No results.",
194
+ density = "comfortable",
195
+ className,
196
+ }: DataTableProps<TData>) {
197
+ const [sortingState, setSortingState] = React.useState<SortingState>([])
198
+ const [rowSelectionState, setRowSelectionState] =
199
+ React.useState<RowSelectionState>({})
200
+
201
+ const resolvedColumns = React.useMemo(() => {
202
+ if (rowSelectionEnabled) {
203
+ return [buildSelectionColumn<TData>(), ...columns]
204
+ }
205
+ return columns
206
+ }, [columns, rowSelectionEnabled])
207
+
208
+ const paginationEnabled = paginationOptions !== undefined
209
+ const pageSize = paginationOptions?.pageSize ?? 10
210
+
211
+ const table = useReactTable<TData>({
212
+ data,
213
+ columns: resolvedColumns,
214
+ state: {
215
+ sorting: sortingState,
216
+ rowSelection: rowSelectionState,
217
+ },
218
+ enableSorting: sortingEnabled,
219
+ enableRowSelection: rowSelectionEnabled,
220
+ onSortingChange: setSortingState,
221
+ onRowSelectionChange: setRowSelectionState,
222
+ getCoreRowModel: getCoreRowModel(),
223
+ getSortedRowModel: sortingEnabled ? getSortedRowModel() : undefined,
224
+ getPaginationRowModel: paginationEnabled
225
+ ? getPaginationRowModel()
226
+ : undefined,
227
+ initialState: {
228
+ pagination: {
229
+ pageSize,
230
+ },
231
+ },
232
+ })
233
+
234
+ const cellClass = cellVariants({ density })
235
+
236
+ return (
237
+ <div
238
+ data-slot="data-table"
239
+ className={cn("rounded-md border bg-card overflow-hidden", className)}
240
+ >
241
+ {/* Scrollable table wrapper */}
242
+ <div className="overflow-x-auto">
243
+ <Table role="grid">
244
+ <TableHeader>
245
+ {table.getHeaderGroups().map((headerGroup) => (
246
+ <TableRow key={headerGroup.id}>
247
+ {headerGroup.headers.map((header) => {
248
+ const isSortable =
249
+ sortingEnabled && header.column.getCanSort()
250
+ const sortDir = header.column.getIsSorted()
251
+ const ariaSortMap = {
252
+ asc: "ascending",
253
+ desc: "descending",
254
+ } as const
255
+
256
+ return (
257
+ <TableHead
258
+ key={header.id}
259
+ style={
260
+ header.column.columnDef.size !== undefined
261
+ ? { width: header.column.columnDef.size }
262
+ : undefined
263
+ }
264
+ className={cn(
265
+ cellClass,
266
+ isSortable &&
267
+ "cursor-pointer select-none hover:text-foreground",
268
+ "text-muted-foreground font-medium text-sm"
269
+ )}
270
+ aria-sort={
271
+ isSortable
272
+ ? sortDir
273
+ ? ariaSortMap[sortDir]
274
+ : "none"
275
+ : undefined
276
+ }
277
+ onClick={
278
+ isSortable
279
+ ? header.column.getToggleSortingHandler()
280
+ : undefined
281
+ }
282
+ tabIndex={isSortable ? 0 : undefined}
283
+ onKeyDown={
284
+ isSortable
285
+ ? (e) => {
286
+ if (e.key === "Enter" || e.key === " ") {
287
+ e.preventDefault()
288
+ header.column.getToggleSortingHandler()?.(e)
289
+ }
290
+ }
291
+ : undefined
292
+ }
293
+ >
294
+ {header.isPlaceholder ? null : (
295
+ <span className="inline-flex items-center gap-1.5">
296
+ {flexRender(
297
+ header.column.columnDef.header,
298
+ header.getContext()
299
+ )}
300
+ {isSortable && <SortIcon direction={sortDir} />}
301
+ </span>
302
+ )}
303
+ </TableHead>
304
+ )
305
+ })}
306
+ </TableRow>
307
+ ))}
308
+ </TableHeader>
309
+
310
+ <TableBody>
311
+ {table.getRowModel().rows.length > 0 ? (
312
+ table.getRowModel().rows.map((row) => (
313
+ <TableRow
314
+ key={row.id}
315
+ data-state={row.getIsSelected() ? "selected" : undefined}
316
+ data-clickable={onRowClick ? true : undefined}
317
+ className={cn(
318
+ onRowClick && "cursor-pointer",
319
+ row.getIsSelected() && "bg-muted"
320
+ )}
321
+ onClick={onRowClick ? () => onRowClick(row.original) : undefined}
322
+ >
323
+ {row.getVisibleCells().map((cell) => (
324
+ <TableCell
325
+ key={cell.id}
326
+ className={cn(cellClass)}
327
+ >
328
+ {flexRender(
329
+ cell.column.columnDef.cell,
330
+ cell.getContext()
331
+ )}
332
+ </TableCell>
333
+ ))}
334
+ </TableRow>
335
+ ))
336
+ ) : (
337
+ <tr>
338
+ <td
339
+ colSpan={resolvedColumns.length}
340
+ className="py-12 text-center text-sm text-muted-foreground"
341
+ >
342
+ {emptyMessage}
343
+ </td>
344
+ </tr>
345
+ )}
346
+ </TableBody>
347
+ </Table>
348
+ </div>
349
+
350
+ {/* Pagination footer */}
351
+ {paginationEnabled && (
352
+ <div className="flex items-center justify-between border-t px-4 py-3">
353
+ <p className="text-sm text-muted-foreground tabular-nums">
354
+ {(() => {
355
+ const { pageIndex, pageSize: ps } = table.getState().pagination
356
+ const total = table.getFilteredRowModel().rows.length
357
+ const from = total === 0 ? 0 : pageIndex * ps + 1
358
+ const to = Math.min((pageIndex + 1) * ps, total)
359
+ return `${from}–${to} of ${total} row${total !== 1 ? "s" : ""}`
360
+ })()}
361
+ </p>
362
+ <div className="flex items-center gap-2">
363
+ <Button
364
+ variant="outline"
365
+ size="sm"
366
+ onClick={() => table.previousPage()}
367
+ disabled={!table.getCanPreviousPage()}
368
+ aria-label="Go to previous page"
369
+ >
370
+ Previous
371
+ </Button>
372
+ <Button
373
+ variant="outline"
374
+ size="sm"
375
+ onClick={() => table.nextPage()}
376
+ disabled={!table.getCanNextPage()}
377
+ aria-label="Go to next page"
378
+ >
379
+ Next
380
+ </Button>
381
+ </div>
382
+ </div>
383
+ )}
384
+ </div>
385
+ )
386
+ }
387
+
388
+ export { DataTable }