@behavioral-agentic-design-system/core 0.26.0 → 0.28.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 (36) hide show
  1. package/package.json +4 -4
  2. package/scripts/build-tokens.cjs +8 -0
  3. package/src/app/preview/components/page.tsx +1004 -22
  4. package/src/app/shell.tsx +17 -0
  5. package/src/components/ui/ai-badge.tsx +74 -0
  6. package/src/components/ui/chat-bubble.tsx +298 -0
  7. package/src/components/ui/clipboard.tsx +291 -0
  8. package/src/components/ui/copy-button.tsx +5 -1
  9. package/src/components/ui/data-table.tsx +388 -0
  10. package/src/components/ui/floating-action-button.tsx +179 -0
  11. package/src/components/ui/focus-trap.tsx +184 -0
  12. package/src/components/ui/index.ts +8 -0
  13. package/src/components/ui/mark.tsx +69 -0
  14. package/src/components/ui/meter.tsx +4 -4
  15. package/src/components/ui/rolling-number.tsx +200 -0
  16. package/src/components/ui/transfer-list.tsx +48 -13
  17. package/src/components/ui/typing-indicator.tsx +96 -0
  18. package/src/components/ui/word-rotate.tsx +87 -0
  19. package/src/data/docs-index.ts +1 -0
  20. package/src/stories/Affix.stories.tsx +1 -1
  21. package/src/stories/AiBadge.stories.tsx +67 -0
  22. package/src/stories/Anchor.stories.tsx +4 -4
  23. package/src/stories/ChatBubble.stories.tsx +222 -0
  24. package/src/stories/Clipboard.stories.tsx +136 -0
  25. package/src/stories/CopyButton.stories.tsx +2 -0
  26. package/src/stories/DataTable.stories.tsx +271 -0
  27. package/src/stories/FloatingActionButton.stories.tsx +215 -0
  28. package/src/stories/FocusTrap.stories.tsx +218 -0
  29. package/src/stories/Mark.stories.tsx +84 -0
  30. package/src/stories/Meter.stories.tsx +7 -0
  31. package/src/stories/RollingNumber.stories.tsx +226 -0
  32. package/src/stories/TransferList.stories.tsx +21 -0
  33. package/src/stories/TypingIndicator.stories.tsx +140 -0
  34. package/src/stories/WordRotate.stories.tsx +102 -0
  35. package/src/styles.css +8 -0
  36. package/src/tokens.json +1 -1
@@ -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 }
@@ -0,0 +1,179 @@
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
+ /**
10
+ * FloatingActionButton — fixed-position circular button that triggers a
11
+ * single primary action, pinned to a viewport corner. The single-action
12
+ * counterpart to SpeedDial (which opens a submenu of 2–5 quick actions).
13
+ * Cross-library Tier 1 pattern: MUI `Fab` + Ant Design `FloatButton`.
14
+ *
15
+ * Wraps the Button primitive, so focus ring, loading (spinner + aria-busy +
16
+ * disabled), and disabled affordances are inherited — this file only owns
17
+ * positioning, shape, size contract, and entrance motion.
18
+ *
19
+ * Accessible name is REQUIRED: either a visible `label` (extended/pill form)
20
+ * or `aria-label` when icon-only. A dev-mode warning fires when both are
21
+ * missing.
22
+ *
23
+ * Motion:
24
+ * - entrance: tw-animate-css `animate-in fade-in-0 zoom-in-75` (existing
25
+ * keyframe utility — spec §4 pattern (a), same family Dialog/Tooltip use)
26
+ * - hover/active: shadow elevation shift on `transition-shadow` with inline
27
+ * token vars (spec §4 pattern (c)); bg hover comes from Button's own
28
+ * `transition-colors` variant classes
29
+ * - reduced motion: base-layer prefers-reduced-motion kill-switch, no
30
+ * per-component guard needed
31
+ *
32
+ * Exit motion on unmount is deliberately out of scope — the element is
33
+ * removed before an exit keyframe could play; animated dismissal needs
34
+ * presence management (a future follow-up, same limitation as Ant
35
+ * FloatButton).
36
+ */
37
+ const fabVariants = cva(
38
+ // fixed + z-50 floats above page content; rounded-full is the FAB shape
39
+ // contract; shadow ladder (lg → xl on hover → md on active) is the lift
40
+ // affordance — never hover:scale (BADS-SLOP-3 anti-default). The explicit
41
+ // property list replaces Button's `transition-colors` (same tailwind-merge
42
+ // group) so bg hover AND elevation both animate — never `transition-all`.
43
+ "fixed z-50 rounded-full shadow-lg transition-[background-color,color,box-shadow] hover:shadow-xl active:shadow-md animate-in fade-in-0 zoom-in-75",
44
+ {
45
+ variants: {
46
+ size: {
47
+ // sm is 40px — BELOW the 44px SC 2.5.5 floor. Dense/desktop-secondary
48
+ // chrome only; never a primary CTA (registry antiPatterns).
49
+ sm: "min-h-10 min-w-10 [&_svg:not([class*='size-'])]:size-5",
50
+ // md 56px is the thumb-target convention both source systems default to.
51
+ md: "min-h-14 min-w-14 [&_svg:not([class*='size-'])]:size-6",
52
+ lg: "min-h-16 min-w-16 [&_svg:not([class*='size-'])]:size-6",
53
+ },
54
+ corner: {
55
+ "bottom-right": "bottom-6 right-6",
56
+ "bottom-left": "bottom-6 left-6",
57
+ "top-right": "top-6 right-6",
58
+ "top-left": "top-6 left-6",
59
+ },
60
+ // extended = visible label → pill form. Explicit h-* + px-* override
61
+ // Button's size classes via tailwind-merge; round form zeroes padding so
62
+ // min-h/min-w keep the button square.
63
+ extended: {
64
+ false: "px-0 py-0",
65
+ true: "gap-2 text-sm font-medium",
66
+ },
67
+ },
68
+ compoundVariants: [
69
+ { extended: false, size: "sm", class: "h-10 w-10" },
70
+ { extended: false, size: "md", class: "h-14 w-14" },
71
+ { extended: false, size: "lg", class: "h-16 w-16" },
72
+ { extended: true, size: "sm", class: "h-10 px-4" },
73
+ { extended: true, size: "md", class: "h-14 px-5" },
74
+ { extended: true, size: "lg", class: "h-16 px-6" },
75
+ ],
76
+ defaultVariants: {
77
+ size: "md",
78
+ corner: "bottom-right",
79
+ extended: false,
80
+ },
81
+ }
82
+ );
83
+
84
+ interface FloatingActionButtonProps
85
+ extends Omit<React.ComponentProps<"button">, "children">,
86
+ Omit<VariantProps<typeof fabVariants>, "extended"> {
87
+ /** Required — the icon rendered inside. Lucide at strokeWidth 1.5 by convention. */
88
+ icon: React.ReactNode;
89
+ /** Visible label beside the icon — switches to the extended (pill) FAB form. */
90
+ label?: string;
91
+ /** Maps to Button variants: primary → default, secondary → secondary. */
92
+ variant?: "primary" | "secondary";
93
+ /** Spinner replaces the icon; aria-busy + disabled via Button. Dimensions stay stable. */
94
+ loading?: boolean;
95
+ /**
96
+ * Render via Radix Slot (e.g. a Next.js Link). The composed icon + label
97
+ * are injected as the child's children; if the child already has its own
98
+ * children, those win (compose the icon yourself in that case). Button's
99
+ * asChild contract applies: `loading` is a no-op with asChild.
100
+ */
101
+ asChild?: boolean;
102
+ children?: React.ReactNode;
103
+ }
104
+
105
+ function FloatingActionButton({
106
+ icon,
107
+ label,
108
+ size = "md",
109
+ corner = "bottom-right",
110
+ variant = "primary",
111
+ loading = false,
112
+ asChild = false,
113
+ className,
114
+ style,
115
+ children,
116
+ ...props
117
+ }: FloatingActionButtonProps) {
118
+ if (process.env.NODE_ENV !== "production") {
119
+ if (
120
+ !label &&
121
+ !props["aria-label"] &&
122
+ !props["aria-labelledby"] &&
123
+ !asChild
124
+ ) {
125
+ console.warn(
126
+ "FloatingActionButton: icon-only FABs need an accessible name — pass `aria-label` (or a visible `label`)."
127
+ );
128
+ }
129
+ }
130
+
131
+ const content = (
132
+ <>
133
+ {/* Button renders its own aria-hidden spinner when loading; hide the
134
+ icon then so the round form stays a single centered glyph. */}
135
+ {loading && !asChild ? null : icon}
136
+ {label ? <span>{label}</span> : null}
137
+ </>
138
+ );
139
+
140
+ let inner: React.ReactNode = content;
141
+ if (asChild && React.isValidElement(children)) {
142
+ const child = children as React.ReactElement<{
143
+ children?: React.ReactNode;
144
+ }>;
145
+ // Slot needs exactly one child; inject the composed icon/label into it
146
+ // unless the consumer already hand-composed the child's content.
147
+ inner =
148
+ child.props.children != null
149
+ ? child
150
+ : React.cloneElement(child, undefined, content);
151
+ }
152
+
153
+ return (
154
+ <Button
155
+ asChild={asChild}
156
+ variant={variant === "secondary" ? "secondary" : "default"}
157
+ loading={loading}
158
+ data-slot="floating-action-button"
159
+ data-state="visible"
160
+ className={cn(fabVariants({ size, corner, extended: Boolean(label) }), className)}
161
+ // Elevation lift timing rides the motion tokens (spec §4 pattern (c));
162
+ // CSS vars resolve at runtime against :root, so tokens.json changes
163
+ // propagate without a rebuild of this file. Consumer style merges on
164
+ // top (but the motion tokens are listed first so an explicit consumer
165
+ // override still wins).
166
+ style={{
167
+ transitionDuration: "var(--duration-fast)",
168
+ transitionTimingFunction: "var(--ease-out)",
169
+ ...style,
170
+ }}
171
+ {...props}
172
+ >
173
+ {inner}
174
+ </Button>
175
+ );
176
+ }
177
+
178
+ export { FloatingActionButton, fabVariants };
179
+ export type { FloatingActionButtonProps };