@behavioral-agentic-design-system/core 0.40.0 → 0.42.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 (60) hide show
  1. package/README.md +2 -0
  2. package/package.json +19 -3
  3. package/scripts/a11y-lint.cjs +41 -2
  4. package/scripts/health-report.mjs +16 -2
  5. package/scripts/lint-slop.mjs +25 -1
  6. package/scripts/wcag-audit.cjs +72 -5
  7. package/src/app/opengraph-image.tsx +5 -0
  8. package/src/app/preview/components/page.tsx +1269 -2
  9. package/src/app/shell.tsx +8 -5
  10. package/src/components/Foundations/Motion.stories.tsx +1 -0
  11. package/src/components/customize/design-controls.tsx +16 -1
  12. package/src/components/studio/studio.tsx +153 -0
  13. package/src/components/ui/anchor.tsx +37 -3
  14. package/src/components/ui/attachment.tsx +211 -0
  15. package/src/components/ui/chart.tsx +3 -0
  16. package/src/components/ui/code.tsx +1 -1
  17. package/src/components/ui/color-picker.tsx +1 -1
  18. package/src/components/ui/gauge-chart.tsx +238 -0
  19. package/src/components/ui/heatmap.tsx +256 -0
  20. package/src/components/ui/index.ts +9 -0
  21. package/src/components/ui/infinite-scroll.tsx +103 -0
  22. package/src/components/ui/json-input.tsx +351 -0
  23. package/src/components/ui/navigation-progress.tsx +281 -0
  24. package/src/components/ui/number-input.tsx +1 -4
  25. package/src/components/ui/password-input.tsx +2 -1
  26. package/src/components/ui/password-strength-input.tsx +288 -0
  27. package/src/components/ui/pill.tsx +140 -0
  28. package/src/components/ui/popover.tsx +27 -4
  29. package/src/components/ui/scroll-progress.tsx +100 -0
  30. package/src/components/ui/snackbar.tsx +393 -0
  31. package/src/components/ui/sortable-list.tsx +342 -0
  32. package/src/components/ui/squircle.tsx +1 -1
  33. package/src/components/ui/table.tsx +1 -1
  34. package/src/components/ui/tour.tsx +1 -3
  35. package/src/data/docs-index.ts +24 -0
  36. package/src/lib/clamp.ts +2 -0
  37. package/src/stories/Anchor.stories.tsx +54 -0
  38. package/src/stories/Attachment.stories.tsx +189 -0
  39. package/src/stories/Chart.stories.tsx +4 -0
  40. package/src/stories/Code.stories.tsx +1 -0
  41. package/src/stories/ColorPicker.stories.tsx +1 -0
  42. package/src/stories/GaugeChart.stories.tsx +163 -0
  43. package/src/stories/Heatmap.stories.tsx +172 -0
  44. package/src/stories/InfiniteScroll.stories.tsx +225 -0
  45. package/src/stories/JsonInput.stories.tsx +212 -0
  46. package/src/stories/NavigationProgress.stories.tsx +159 -0
  47. package/src/stories/NumberInput.stories.tsx +1 -0
  48. package/src/stories/PasswordInput.stories.tsx +4 -0
  49. package/src/stories/PasswordStrengthInput.stories.tsx +211 -0
  50. package/src/stories/Pill.stories.tsx +201 -0
  51. package/src/stories/Popover.stories.tsx +29 -1
  52. package/src/stories/Portal.stories.tsx +3 -1
  53. package/src/stories/ScrollProgress.stories.tsx +117 -0
  54. package/src/stories/Snackbar.stories.tsx +315 -0
  55. package/src/stories/SortableList.stories.tsx +263 -0
  56. package/src/stories/Squircle.stories.tsx +1 -0
  57. package/src/stories/Table.stories.tsx +1 -0
  58. package/src/stories/Tour.stories.tsx +1 -0
  59. package/src/stories/story-groups.json +17 -6
  60. package/LICENSE +0 -21
package/src/app/shell.tsx CHANGED
@@ -6,7 +6,7 @@ import { Sheet, SheetContent, SheetHeader, SheetTitle } from "@behavioral-agenti
6
6
  import { Button } from "@behavioral-agentic-design-system/core/components/ui/button";
7
7
  import {
8
8
  Sun, Moon, BookOpen, X, ExternalLink, Menu,
9
- House, Blocks, LayoutGrid, LayoutDashboard,
9
+ House, Blocks,
10
10
  Type, Shapes, FileText, Layers as LayersIcon, Activity, GitCommitHorizontal, SlidersHorizontal as StudioIcon,
11
11
  } from "lucide-react";
12
12
  import registry from "@/layer-5-component-registry/component-registry.json";
@@ -31,7 +31,7 @@ function GithubMark({ className }: { className?: string }) {
31
31
  );
32
32
  }
33
33
  import { brand } from "@/brand.config";
34
- import Studio from "@/components/examples/studio/studio";
34
+ import Studio from "../components/studio/studio";
35
35
  import { LayersTab } from "@behavioral-agentic-design-system/core/components/layers-tab";
36
36
  import { HomeTab } from "@behavioral-agentic-design-system/core/components/home-tab";
37
37
  import { DocsTab } from "@behavioral-agentic-design-system/core/components/docs-tab";
@@ -268,9 +268,12 @@ function RailTrigger({ tab, className }: { tab: ShellTab; className: string }) {
268
268
  {Icon ? <Icon className="size-4 shrink-0" strokeWidth={1.5} /> : null}
269
269
  <span className="min-w-0 flex-1 truncate text-left">{tab.label}</span>
270
270
  {typeof tab.count === "number" ? (
271
- <span className="shrink-0 text-xs tabular-nums text-muted-foreground">
272
- {tab.count}
273
- </span>
271
+ // No explicit color here on purpose: it inherits from the trigger, exactly like the
272
+ // label span above it. RAIL_ITEM already sets the right color per data-state (muted when
273
+ // inactive, --primary-foreground when active). A hardcoded text-muted-foreground here
274
+ // used to win over that inheritance, so the count stayed muted-gray even on the active
275
+ // row's near-black bg-primary pill -- dark-gray-on-near-black, unreadable.
276
+ <span className="shrink-0 text-xs tabular-nums">{tab.count}</span>
274
277
  ) : null}
275
278
  </TabsTrigger>
276
279
  );
@@ -259,6 +259,7 @@ export const ReducedMotion: Story = {
259
259
  {/* The transition only exists under no-preference, so reduced-motion
260
260
  users get an instant jump — the point of this story. When disarmed
261
261
  we also force transition:none so the snap-to-start never animates. */}
262
+ {/* allow-inline-style: this story's whole point is demonstrating the reduced-motion media-query gate via raw CSS. */}
262
263
  <style>{`
263
264
  @media (prefers-reduced-motion: no-preference) {
264
265
  .reduced-motion-demo[data-armed="true"] {
@@ -90,6 +90,21 @@ function SpacingPreview({ value }: { value: number }) {
90
90
  );
91
91
  }
92
92
 
93
+ // Static lookup, not a template-literal interpolation. Tailwind's build-time
94
+ // scanner reads literal text in source, not runtime JS values — a
95
+ // `` `shadow-${s}` `` interpolation is never seen by the scanner, so none of
96
+ // the four classes generate CSS in a production build and every swatch
97
+ // below silently rendered with no shadow at all. Writing the four class
98
+ // names out literally (even inside an object the scanner doesn't
99
+ // "understand") is what makes them visible to it. Caught by
100
+ // scripts/lint-static-classes.mjs, 2026-09-14.
101
+ const SHADOW_CLASS: Record<"sm" | "md" | "lg" | "xl", string> = {
102
+ sm: "shadow-sm",
103
+ md: "shadow-md",
104
+ lg: "shadow-lg",
105
+ xl: "shadow-xl",
106
+ };
107
+
93
108
  function ShadowPreview() {
94
109
  const sizes = ["sm", "md", "lg", "xl"] as const;
95
110
  return (
@@ -97,7 +112,7 @@ function ShadowPreview() {
97
112
  {sizes.map((s) => (
98
113
  <div key={s} className="flex flex-col items-center gap-1.5">
99
114
  <div
100
- className={`h-10 w-10 rounded-md bg-card shadow-${s}`}
115
+ className={`h-10 w-10 rounded-md bg-card ${SHADOW_CLASS[s]}`}
101
116
  />
102
117
  <span className="text-xs text-muted-foreground font-mono">{s}</span>
103
118
  </div>
@@ -0,0 +1,153 @@
1
+ "use client";
2
+
3
+ import { useState } from "react";
4
+ import { PanelLeftClose, PanelLeftOpen } from "lucide-react";
5
+ import { Button } from "@behavioral-agentic-design-system/core/components/ui/button";
6
+ import { ScrollArea } from "@behavioral-agentic-design-system/core/components/ui/scroll-area";
7
+ import { ColorPalette } from "@behavioral-agentic-design-system/core/components/customize-tab";
8
+ import { DisciplineSection } from "@behavioral-agentic-design-system/core/components/customize/discipline-section";
9
+ import CardsDemo from "@/components/examples/cards";
10
+ import DashboardDemo from "@/components/examples/dashboard";
11
+ import {
12
+ SegmentedControl,
13
+ SegmentedControlItem,
14
+ } from "@behavioral-agentic-design-system/core/components/ui/segmented-control";
15
+
16
+ /**
17
+ * Studio — tune the system and watch real compositions respond.
18
+ *
19
+ * Replaces the Customize tab, and absorbs what Cards showed. The problem it
20
+ * solves is that those were separate destinations: you changed a token in one
21
+ * and had to navigate to another to see what it did, which meant the authoring
22
+ * surface could not show you the consequence of authoring.
23
+ *
24
+ * ONE architectural constraint decides this whole component, and it is why the
25
+ * specimens are rendered INLINE rather than in an <IframePreview> like every
26
+ * other showcase surface:
27
+ *
28
+ * `useTokenOverrides` writes to `document.documentElement.style`.
29
+ *
30
+ * An iframe is a separate document with its own documentElement, so an iframed
31
+ * specimen would keep its old values until reloaded. Inline, the specimens sit
32
+ * under the same root the overrides are written to, so a colour change repaints
33
+ * them on the same frame with no wiring at all. Do not "tidy" this into an
34
+ * iframe later — the live repaint is the feature, and the iframe is what broke
35
+ * it in the first place.
36
+ *
37
+ * Direction A ("The Inspector"), chosen 2026-09-09. Two costs were named at
38
+ * sketch time and both are answered here rather than shipped:
39
+ *
40
+ * - Two nested columns eat horizontal space beside a 240px rail. So the
41
+ * controls column collapses, and the collapse state persists.
42
+ * - A flat list of primitives is a poor authoring interface (the token-vs-
43
+ * editor critique). So controls are grouped by DECISION with the section
44
+ * saying what it governs, not by raw token name.
45
+ */
46
+
47
+ const COLLAPSE_KEY = "bads:studio:controls-collapsed";
48
+
49
+ /** The specimen sets Studio absorbs. Cards is the default: it is the denser
50
+ * read on a token change, and it fits the pane without horizontal scroll. */
51
+ const SPECIMENS = [
52
+ { id: "cards", label: "Cards" },
53
+ { id: "dashboard", label: "Dashboard" },
54
+ ] as const;
55
+
56
+ export default function Studio() {
57
+ const [collapsed, setCollapsed] = useState(false);
58
+ const [specimen, setSpecimen] = useState<string>("cards");
59
+
60
+ // Restore the collapse choice. Read lazily rather than in useState's
61
+ // initialiser so the server render and the first client render agree.
62
+ useState(() => {
63
+ if (typeof window === "undefined") return;
64
+ try {
65
+ if (window.localStorage.getItem(COLLAPSE_KEY) === "1") setCollapsed(true);
66
+ } catch {
67
+ // Storage disabled — open is the safe default.
68
+ }
69
+ });
70
+
71
+ function toggle() {
72
+ setCollapsed((prev) => {
73
+ const next = !prev;
74
+ try {
75
+ window.localStorage.setItem(COLLAPSE_KEY, next ? "1" : "0");
76
+ } catch {
77
+ // Non-fatal: the panel still toggles for this session.
78
+ }
79
+ return next;
80
+ });
81
+ }
82
+
83
+ return (
84
+ <div className="flex size-full min-h-0">
85
+ {/* ── Controls ───────────────────────────────────────────────────── */}
86
+ {collapsed ? null : (
87
+ <div className="@container/panel flex w-[360px] shrink-0 flex-col border-r">
88
+ <div className="flex h-14 shrink-0 items-center justify-between border-b px-4">
89
+ <h2 className="text-sm font-semibold">Controls</h2>
90
+ <Button
91
+ variant="ghost"
92
+ size="icon"
93
+ onClick={toggle}
94
+ aria-label="Collapse controls"
95
+ className="size-11"
96
+ >
97
+ <PanelLeftClose className="size-4" strokeWidth={1.5} />
98
+ </Button>
99
+ </div>
100
+ <ScrollArea className="min-h-0 flex-1">
101
+ {/* The existing, working panels — re-housed, not rewritten. They
102
+ already carry their own previews (swatches, font specimens),
103
+ which is what makes a decision legible instead of a raw value. */}
104
+ <div className="flex flex-col gap-10 px-4 py-5">
105
+ {/* Re-homed here when Studio replaced CustomizeTab. Renders null
106
+ on a single-discipline fork, so upstream sees nothing. */}
107
+ <DisciplineSection />
108
+ <ColorPalette />
109
+ </div>
110
+ </ScrollArea>
111
+ </div>
112
+ )}
113
+
114
+ {/* ── Specimens ──────────────────────────────────────────────────── */}
115
+ <div className="flex min-w-0 flex-1 flex-col">
116
+ <div className="flex h-14 shrink-0 items-center gap-3 border-b px-4">
117
+ {collapsed ? (
118
+ <Button
119
+ variant="ghost"
120
+ size="icon"
121
+ onClick={toggle}
122
+ aria-label="Show controls"
123
+ className="size-11"
124
+ >
125
+ <PanelLeftOpen className="size-4" strokeWidth={1.5} />
126
+ </Button>
127
+ ) : null}
128
+ <SegmentedControl
129
+ value={specimen}
130
+ onValueChange={setSpecimen}
131
+ label="Specimen set"
132
+ >
133
+ {SPECIMENS.map((s) => (
134
+ <SegmentedControlItem key={s.id} value={s.id}>
135
+ {s.label}
136
+ </SegmentedControlItem>
137
+ ))}
138
+ </SegmentedControl>
139
+ <p className="truncate text-sm text-muted-foreground">
140
+ Real compositions. They repaint as you change a value.
141
+ </p>
142
+ </div>
143
+ <ScrollArea className="min-h-0 flex-1">
144
+ {/* Dashboard is a wide layout; it gets its own horizontal scroll
145
+ rather than forcing the whole pane wide. */}
146
+ <div className={specimen === "dashboard" ? "min-w-[960px]" : "p-6"}>
147
+ {specimen === "dashboard" ? <DashboardDemo withSidebar={false} /> : <CardsDemo />}
148
+ </div>
149
+ </ScrollArea>
150
+ </div>
151
+ </div>
152
+ );
153
+ }
@@ -19,6 +19,15 @@ interface AnchorProps extends React.ComponentProps<"nav"> {
19
19
  label?: string
20
20
  /** Offset in px from the top of the viewport for IntersectionObserver rootMargin. Default 0. */
21
21
  offset?: number
22
+ /**
23
+ * Controlled active item. When provided, the component highlights this id
24
+ * instead of its own scroll-spy result; the observer keeps running and
25
+ * reports what it sees through `onActiveChange`, so the consumer can mirror
26
+ * it into a URL hash, a store, or a sibling surface. Omit for uncontrolled.
27
+ */
28
+ activeId?: string | null
29
+ /** Fires whenever the scroll-spy resolves a new visible section. */
30
+ onActiveChange?: (id: string) => void
22
31
  }
23
32
 
24
33
  // Each depth level adds pl-3 of indentation. Clamped at depth 2.
@@ -31,15 +40,35 @@ const DEPTH_PADDING = ["pl-3", "pl-6", "pl-9"] as const
31
40
  *
32
41
  * Distinct from NavigationMenu (multi-page) and Breadcrumb (path hierarchy).
33
42
  * Cross-system references: Mantine TableOfContents, Ant Design Anchor.
43
+ * This IS BADS's table-of-contents primitive — the name follows Ant Design,
44
+ * and the registry lists `TableOfContents` as an alias so the candidate
45
+ * pre-screen doesn't re-propose it (ledgers/component-builds.jsonl,
46
+ * 2026-08-21 and 2026-09-15).
47
+ *
48
+ * Uncontrolled by default. Pass `activeId` (+ `onActiveChange`) to control
49
+ * the highlight — e.g. to drive it from the URL hash or a shared store.
34
50
  */
35
51
  function Anchor({
36
52
  items,
37
53
  label = "On this page",
38
54
  offset = 0,
55
+ activeId: activeIdProp,
56
+ onActiveChange,
39
57
  className,
40
58
  ...props
41
59
  }: AnchorProps) {
42
- const [activeId, setActiveId] = React.useState<string | null>(null)
60
+ const [internalActiveId, setInternalActiveId] = React.useState<
61
+ string | null
62
+ >(null)
63
+ const isControlled = activeIdProp !== undefined
64
+ const activeId = isControlled ? activeIdProp : internalActiveId
65
+
66
+ // Latest-callback ref so the observer effect doesn't re-subscribe every
67
+ // render when the consumer passes an inline arrow for onActiveChange.
68
+ const onActiveChangeRef = React.useRef(onActiveChange)
69
+ React.useEffect(() => {
70
+ onActiveChangeRef.current = onActiveChange
71
+ }, [onActiveChange])
43
72
 
44
73
  // Key the effect off the id list (not array identity) so consumers can
45
74
  // inline `items` without tearing the observer down on every render.
@@ -62,7 +91,12 @@ function Anchor({
62
91
  // is visible wins. Keep the previous active id while nothing is
63
92
  // visible (e.g. mid-jump between long sections).
64
93
  const first = ids.find((id) => visible.has(id))
65
- if (first) setActiveId(first)
94
+ if (first) {
95
+ // Uncontrolled: own the highlight. Controlled: only report; the
96
+ // consumer decides whether to mirror it back through `activeId`.
97
+ if (!isControlled) setInternalActiveId(first)
98
+ onActiveChangeRef.current?.(first)
99
+ }
66
100
  },
67
101
  { rootMargin: `${-offset}px 0px 0px 0px`, threshold: 0 }
68
102
  )
@@ -73,7 +107,7 @@ function Anchor({
73
107
  }
74
108
 
75
109
  return () => observer.disconnect()
76
- }, [idKey, offset])
110
+ }, [idKey, offset, isControlled])
77
111
 
78
112
  return (
79
113
  <nav
@@ -0,0 +1,211 @@
1
+ "use client"
2
+
3
+ /**
4
+ * Attachment — pre-send file chip for a chat composer.
5
+ *
6
+ * Appears inside the composer input area after a user picks a file and
7
+ * before the message is sent: file-type icon, truncated file name, formatted
8
+ * size, and a remove control. Pairs with ChatInput (the composer) and
9
+ * FileButton (the picker). It is the third leg of the attach flow — pick
10
+ * (FileButton) → review (Attachment) → send (ChatInput).
11
+ *
12
+ * Sources: shadcn/ui July 2026 chat release (Attachment); Mantine FileButton
13
+ * + Pill attachment pattern. Convention: Slack, Linear, and Intercom composer
14
+ * chips.
15
+ *
16
+ * NOT a drop zone (FileUpload) and NOT a post-send file card in the
17
+ * conversation (FileCard). Attachment is the chip the user can still back out
18
+ * of.
19
+ *
20
+ * Composition (bucket C): CloseButton for the remove control (inherits
21
+ * Button's focus ring, disabled handling, and 1.5-stroke X) and FormatByte
22
+ * for the size (SI scale, exact byte count on title). No new tokens.
23
+ *
24
+ * Accessibility:
25
+ * - root is role="group" with aria-label "Attached file: <name>" so a screen
26
+ * reader hears the chip as one unit before reaching the remove button
27
+ * - remove button is a 44px CloseButton (size="icon-xl", SC 2.5.5 Enhanced)
28
+ * with aria-label "Remove <name>" — the chip is a flow-changing control
29
+ * inside a composer, so the dense-chrome 36px exception does not apply
30
+ * - file name truncates (min-w-0 truncate) and rides the title attribute so
31
+ * the full string is recoverable on hover; the group's aria-label carries
32
+ * it for assistive tech
33
+ *
34
+ * Motion (spec §4c): remove-button hover is transition-colors driven by
35
+ * --duration-fast / --ease-out. No entrance or exit animation — the chip
36
+ * mounts and unmounts with the composer's own layout; animating removal
37
+ * would delay the user's undo-the-mistake action.
38
+ */
39
+
40
+ import * as React from "react"
41
+ import {
42
+ File,
43
+ FileArchive,
44
+ FileAudio,
45
+ FileCode,
46
+ FileImage,
47
+ FileText,
48
+ FileVideo,
49
+ type LucideIcon,
50
+ } from "lucide-react"
51
+
52
+ import { cn } from "../../lib/utils"
53
+ import { CloseButton } from "./close-button"
54
+ import { FormatByte } from "./format-byte"
55
+
56
+ const CODE_MIME = new Set([
57
+ "application/json",
58
+ "application/javascript",
59
+ "application/typescript",
60
+ "application/xml",
61
+ "application/x-sh",
62
+ "application/x-yaml",
63
+ "text/javascript",
64
+ "text/typescript",
65
+ "text/css",
66
+ "text/html",
67
+ "text/xml",
68
+ "text/markdown",
69
+ "text/x-python",
70
+ "text/x-java-source",
71
+ "text/x-c",
72
+ "text/yaml",
73
+ ])
74
+
75
+ const ARCHIVE_MIME = new Set([
76
+ "application/zip",
77
+ "application/x-zip-compressed",
78
+ "application/gzip",
79
+ "application/x-gzip",
80
+ "application/x-tar",
81
+ "application/x-7z-compressed",
82
+ "application/x-rar-compressed",
83
+ "application/vnd.rar",
84
+ "application/x-bzip2",
85
+ ])
86
+
87
+ const CODE_EXT = new Set([
88
+ "js", "jsx", "ts", "tsx", "mjs", "cjs", "json", "css", "scss", "html",
89
+ "xml", "yml", "yaml", "md", "py", "rb", "go", "rs", "java", "kt", "swift",
90
+ "c", "h", "cpp", "cs", "sh", "sql", "toml",
91
+ ])
92
+
93
+ const ARCHIVE_EXT = new Set(["zip", "gz", "tgz", "tar", "7z", "rar", "bz2"])
94
+ const IMAGE_EXT = new Set(["png", "jpg", "jpeg", "gif", "webp", "svg", "avif", "heic"])
95
+ const TEXT_EXT = new Set(["pdf", "txt", "doc", "docx", "rtf", "csv", "odt"])
96
+ const AUDIO_EXT = new Set(["mp3", "wav", "m4a", "ogg", "flac", "aac"])
97
+ const VIDEO_EXT = new Set(["mp4", "mov", "webm", "mkv", "avi"])
98
+
99
+ /**
100
+ * Picks the lucide glyph for a file. MIME type wins (it is what
101
+ * `File.type` reports); the extension is the fallback when the browser gives
102
+ * an empty or generic type (`application/octet-stream` is common on Windows
103
+ * for anything it does not recognize).
104
+ */
105
+ function iconForFile(fileName: string, fileType?: string): LucideIcon {
106
+ const mime = (fileType ?? "").toLowerCase()
107
+
108
+ if (mime.startsWith("image/")) return FileImage
109
+ if (mime.startsWith("audio/")) return FileAudio
110
+ if (mime.startsWith("video/")) return FileVideo
111
+ if (CODE_MIME.has(mime)) return FileCode
112
+ if (ARCHIVE_MIME.has(mime)) return FileArchive
113
+ if (mime === "application/pdf" || mime.startsWith("text/")) return FileText
114
+ if (mime.startsWith("application/vnd.") || mime === "application/msword")
115
+ return FileText
116
+
117
+ const dot = fileName.lastIndexOf(".")
118
+ const ext = dot >= 0 ? fileName.slice(dot + 1).toLowerCase() : ""
119
+ if (IMAGE_EXT.has(ext)) return FileImage
120
+ if (AUDIO_EXT.has(ext)) return FileAudio
121
+ if (VIDEO_EXT.has(ext)) return FileVideo
122
+ if (CODE_EXT.has(ext)) return FileCode
123
+ if (ARCHIVE_EXT.has(ext)) return FileArchive
124
+ if (TEXT_EXT.has(ext)) return FileText
125
+
126
+ return File
127
+ }
128
+
129
+ export interface AttachmentProps
130
+ extends Omit<React.ComponentProps<"div">, "children"> {
131
+ /** The file's name, shown truncated; the full value rides `title` and the group's aria-label. */
132
+ fileName: string
133
+ /** Size in bytes. Rendered via FormatByte (SI scale: 42.7 KB, 1.5 MB). Omit to hide. */
134
+ fileSize?: number
135
+ /** MIME type (`File.type`) used to pick the icon. Falls back to the file extension. */
136
+ fileType?: string
137
+ /**
138
+ * Called when the user activates the remove control. When absent the
139
+ * remove button is not rendered — the chip becomes read-only.
140
+ */
141
+ onRemove?: () => void
142
+ /** Dims the chip and disables the remove control (for example while the message is sending). */
143
+ disabled?: boolean
144
+ }
145
+
146
+ function Attachment({
147
+ fileName,
148
+ fileSize,
149
+ fileType,
150
+ onRemove,
151
+ disabled = false,
152
+ className,
153
+ ...props
154
+ }: AttachmentProps) {
155
+ const Icon = iconForFile(fileName, fileType)
156
+
157
+ return (
158
+ <div
159
+ role="group"
160
+ aria-label={`Attached file: ${fileName}`}
161
+ aria-disabled={disabled || undefined}
162
+ data-slot="attachment"
163
+ data-disabled={disabled || undefined}
164
+ className={cn(
165
+ "inline-flex min-h-11 max-w-xs min-w-0 items-center gap-2 overflow-hidden rounded-lg border bg-muted/50 py-1 pl-3 text-foreground",
166
+ onRemove ? "pr-1" : "pr-3",
167
+ disabled && "opacity-50",
168
+ className
169
+ )}
170
+ {...props}
171
+ >
172
+ <Icon
173
+ strokeWidth={1.5}
174
+ aria-hidden="true"
175
+ className="size-5 shrink-0 text-muted-foreground"
176
+ />
177
+ <span className="flex min-w-0 flex-1 flex-col leading-tight">
178
+ <span
179
+ data-slot="attachment-name"
180
+ className="min-w-0 truncate text-sm font-medium"
181
+ title={fileName}
182
+ >
183
+ {fileName}
184
+ </span>
185
+ {typeof fileSize === "number" && (
186
+ <FormatByte
187
+ data-slot="attachment-size"
188
+ value={fileSize}
189
+ className="text-xs text-muted-foreground"
190
+ />
191
+ )}
192
+ </span>
193
+ {onRemove && (
194
+ <CloseButton
195
+ data-slot="attachment-remove"
196
+ size="icon-xl"
197
+ aria-label={`Remove ${fileName}`}
198
+ disabled={disabled}
199
+ onClick={onRemove}
200
+ className="-my-1"
201
+ style={{
202
+ transitionDuration: "var(--duration-fast)",
203
+ transitionTimingFunction: "var(--ease-out)",
204
+ }}
205
+ />
206
+ )}
207
+ </div>
208
+ )
209
+ }
210
+
211
+ export { Attachment }
@@ -183,6 +183,9 @@ const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
183
183
  }
184
184
 
185
185
  return (
186
+ // allow-inline-style: generates N custom-property writes scoped to a
187
+ // runtime [data-chart=${id}] selector — no static class can express
188
+ // per-instance generated CSS, and the values written ARE tokens.
186
189
  <style
187
190
  dangerouslySetInnerHTML={{
188
191
  __html: `
@@ -10,7 +10,7 @@ const codeVariants = cva("font-mono text-muted-foreground bg-muted", {
10
10
  variant: {
11
11
  inline: "inline rounded px-[0.3em] py-[0.1em] text-xs",
12
12
  block:
13
- "block w-full rounded-md border border-border px-3 py-2.5 text-sm leading-relaxed overflow-x-auto scrollbar-thin scrollbar-thumb-border scrollbar-track-transparent whitespace-pre outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",
13
+ "block w-full rounded-md border border-border px-3 py-2.5 text-sm leading-relaxed overflow-x-auto [scrollbar-width:thin] [scrollbar-color:theme(colors.border)_transparent] whitespace-pre outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",
14
14
  },
15
15
  size: {
16
16
  sm: "",
@@ -10,7 +10,7 @@ import { Button } from "./button";
10
10
  /* Helpers */
11
11
  /* -------------------------------------------------------------------------- */
12
12
 
13
- const clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v));
13
+ import { clamp } from "../../lib/clamp";
14
14
 
15
15
  function hexToRgb(hex: string): [number, number, number] | null {
16
16
  if (!isValidHex(hex)) return null;