@behavioral-agentic-design-system/core 0.42.0 → 0.47.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 (314) hide show
  1. package/package.json +38 -8
  2. package/scripts/a11y-lint.cjs +101 -14
  3. package/scripts/bads-sync.mjs +1 -1
  4. package/scripts/build-tokens.cjs +122 -7
  5. package/scripts/check-dark-contrast.mjs +204 -0
  6. package/scripts/check-flush-edges.mjs +245 -0
  7. package/scripts/check-spec.mjs +73 -0
  8. package/scripts/deal-directions.mjs +186 -0
  9. package/scripts/design-system-advisory/README.md +239 -0
  10. package/scripts/design-system-advisory/check-copy-punctuation.mjs +44 -0
  11. package/scripts/design-system-advisory/check-even-padding.mjs +35 -0
  12. package/scripts/design-system-advisory/check-hand-built-button.mjs +46 -0
  13. package/scripts/design-system-advisory/check-html-nesting.mjs +51 -0
  14. package/scripts/design-system-advisory/check-icon-sizing.mjs +79 -0
  15. package/scripts/design-system-advisory/check-label-case.mjs +92 -0
  16. package/scripts/design-system-advisory/check-native-form-controls.mjs +53 -0
  17. package/scripts/design-system-advisory/check-radius.mjs +56 -0
  18. package/scripts/design-system-advisory/check-raw-values.mjs +61 -0
  19. package/scripts/design-system-advisory/check-small-text.mjs +72 -0
  20. package/scripts/design-system-advisory/check-tap-target.mjs +70 -0
  21. package/scripts/design-system-advisory/defaults.mjs +90 -0
  22. package/scripts/design-system-advisory/fixtures/clean.tsx.fixture +12 -0
  23. package/scripts/design-system-advisory/fixtures/violations.tsx.fixture +19 -0
  24. package/scripts/design-system-advisory/lib.mjs +255 -0
  25. package/scripts/design-system-advisory/run.mjs +189 -0
  26. package/scripts/design-system-advisory/workflow.yml +82 -0
  27. package/scripts/health-report.mjs +20 -14
  28. package/scripts/lib/copy-strings.mjs +146 -0
  29. package/scripts/lib/counted-lint.mjs +100 -0
  30. package/scripts/lib/dark-contrast.mjs +120 -0
  31. package/scripts/lib/flush-edges.mjs +294 -0
  32. package/scripts/lib/lab-lint.mjs +62 -0
  33. package/scripts/lib/marketing-library.mjs +129 -0
  34. package/scripts/lib/mount-page.mjs +25 -0
  35. package/scripts/lib/on-system.mjs +249 -0
  36. package/scripts/lib/random.mjs +22 -0
  37. package/scripts/lib/source-scan.mjs +173 -0
  38. package/scripts/lib/spec-parse.d.mts +25 -0
  39. package/scripts/lib/spec-parse.mjs +188 -0
  40. package/scripts/lib/tells.mjs +366 -0
  41. package/scripts/lint-arbitrary-tokens.mjs +47 -0
  42. package/scripts/lint-component-token-refs.mjs +63 -0
  43. package/scripts/lint-content-hierarchy.mjs +114 -0
  44. package/scripts/lint-control-baseline.mjs +72 -0
  45. package/scripts/lint-copy-punctuation.mjs +60 -0
  46. package/scripts/lint-css-vars.mjs +175 -0
  47. package/scripts/lint-even-padding.mjs +58 -0
  48. package/scripts/lint-html-nesting.mjs +116 -0
  49. package/scripts/lint-label-case.mjs +219 -0
  50. package/scripts/lint-live-ctas.mjs +138 -0
  51. package/scripts/lint-microanimation.mjs +2 -2
  52. package/scripts/lint-proximity.mjs +181 -0
  53. package/scripts/lint-slop.mjs +1 -1
  54. package/scripts/lint-spacing-scale.mjs +78 -0
  55. package/scripts/lint-target-size.cjs +132 -0
  56. package/scripts/lint-token-primitives.mjs +307 -0
  57. package/scripts/on-system-score.mjs +95 -0
  58. package/scripts/size-audit.cjs +2 -2
  59. package/scripts/slop-rules.mjs +1 -1
  60. package/scripts/source-images.mjs +180 -0
  61. package/scripts/ux-tells.mjs +80 -0
  62. package/scripts/wcag-audit.cjs +25 -4
  63. package/src/api/brand-colors.ts +3 -0
  64. package/src/api/brand-fonts.ts +3 -0
  65. package/src/api/brand-mark.ts +6 -1
  66. package/src/api/dev-write-guard.ts +53 -0
  67. package/src/api/layers/file.ts +9 -4
  68. package/src/api/onboarding-extract.ts +85 -30
  69. package/src/api/onboarding.ts +3 -0
  70. package/src/api/save-tokens.ts +3 -0
  71. package/src/api/site-auth.ts +14 -2
  72. package/src/app/layout.tsx +6 -0
  73. package/src/app/preview/canvas/page.tsx +12 -0
  74. package/src/app/preview/components/page.tsx +828 -14
  75. package/src/app/preview/sticker-sheet/page.tsx +329 -0
  76. package/src/app/preview/sticker-sheet/specimens.tsx +296 -0
  77. package/src/app/preview/studio/blank-screen.tsx +143 -0
  78. package/src/app/preview/studio/page.tsx +7 -0
  79. package/src/app/shell.tsx +164 -47
  80. package/src/components/Foundations/Colors.stories.tsx +119 -8
  81. package/src/components/canvas/canvas.tsx +458 -0
  82. package/src/components/canvas/layout.ts +72 -0
  83. package/src/components/canvas/parse-canvas.ts +32 -0
  84. package/src/components/canvas/sample.ts +90 -0
  85. package/src/components/canvas/spec-frame.tsx +43 -0
  86. package/src/components/canvas/types.ts +33 -0
  87. package/src/components/docs-tab.tsx +7 -7
  88. package/src/components/home-recent.tsx +73 -0
  89. package/src/components/home-tab.tsx +19 -14
  90. package/src/components/layers-tab.tsx +2 -2
  91. package/src/components/markdown-preview.tsx +60 -12
  92. package/src/components/onboarding-wizard.tsx +1 -1
  93. package/src/components/studio/control-panel.tsx +299 -0
  94. package/src/components/studio/control-row.tsx +77 -0
  95. package/src/components/studio/preview-frame.tsx +165 -0
  96. package/src/components/studio/preview-pane.tsx +247 -0
  97. package/src/components/studio/studio.tsx +133 -128
  98. package/src/components/studio/types.ts +218 -0
  99. package/src/components/studio/use-studio-tweaks.ts +128 -0
  100. package/src/components/studio/use-studio-view-state.ts +72 -0
  101. package/src/components/ui/autocomplete.tsx +1 -1
  102. package/src/components/ui/avatar.tsx +4 -0
  103. package/src/components/ui/chart.tsx +134 -42
  104. package/src/components/ui/checkbox-group.tsx +1 -1
  105. package/src/components/ui/checkbox.tsx +1 -1
  106. package/src/components/ui/color-picker.tsx +20 -4
  107. package/src/components/ui/combobox.tsx +1 -0
  108. package/src/components/ui/command.tsx +1 -1
  109. package/src/components/ui/data-table.tsx +64 -3
  110. package/src/components/ui/date-field.tsx +1 -1
  111. package/src/components/ui/date-picker.tsx +2 -0
  112. package/src/components/ui/date-range-picker.tsx +4 -0
  113. package/src/components/ui/editable.tsx +1 -0
  114. package/src/components/ui/faceted-filter.tsx +187 -0
  115. package/src/components/ui/file-upload.tsx +21 -2
  116. package/src/components/ui/gauge-chart.tsx +18 -4
  117. package/src/components/ui/heatmap.tsx +3 -1
  118. package/src/components/ui/inline-edit.tsx +175 -0
  119. package/src/components/ui/input-group.tsx +5 -2
  120. package/src/components/ui/month-picker.tsx +1 -1
  121. package/src/components/ui/multi-select.tsx +1 -0
  122. package/src/components/ui/number-input.tsx +28 -5
  123. package/src/components/ui/otp-input.tsx +208 -0
  124. package/src/components/ui/phone-input.tsx +274 -0
  125. package/src/components/ui/radio-group.tsx +2 -2
  126. package/src/components/ui/search-input.tsx +1 -1
  127. package/src/components/ui/sparkline.tsx +33 -4
  128. package/src/components/ui/spinner.tsx +23 -4
  129. package/src/components/ui/table.tsx +9 -0
  130. package/src/components/ui/tags-input.tsx +1 -1
  131. package/src/components/ui/timer.tsx +1 -0
  132. package/src/components/ui/transfer-list.tsx +13 -26
  133. package/src/components/ui/week-picker.tsx +1 -13
  134. package/src/components/ui/year-picker.tsx +1 -1
  135. package/src/data/component-added.json +966 -0
  136. package/src/data/docs-index.ts +35 -2
  137. package/src/data/history.json +161 -161
  138. package/src/data/sticker-sheet.json +9244 -0
  139. package/src/docs-trace-globs.json +1 -0
  140. package/src/hooks/use-global-mono-font.ts +1 -0
  141. package/src/hooks/use-global-primary-color.ts +1 -0
  142. package/src/hooks/use-global-sans-font.ts +1 -0
  143. package/src/hooks/use-global-serif-font.ts +1 -0
  144. package/src/hooks/use-global-type-scale.ts +17 -2
  145. package/src/hooks/use-mobile.ts +2 -0
  146. package/src/hooks/use-sync-type-scale.ts +7 -11
  147. package/src/lib/chart-motion.ts +41 -0
  148. package/src/lib/get-icon-color.ts +1 -1
  149. package/src/lib/spec-parse.ts +4 -0
  150. package/src/lib/svg-sanitize.ts +19 -9
  151. package/src/stories/Accordion.stories.tsx +7 -0
  152. package/src/stories/ActionBar.stories.tsx +5 -0
  153. package/src/stories/Affix.stories.tsx +4 -0
  154. package/src/stories/AiBadge.stories.tsx +9 -7
  155. package/src/stories/Alert.stories.tsx +13 -0
  156. package/src/stories/AlertDialog.stories.tsx +4 -0
  157. package/src/stories/Anchor.stories.tsx +5 -0
  158. package/src/stories/AngleSlider.stories.tsx +6 -3
  159. package/src/stories/AspectRatio.stories.tsx +4 -0
  160. package/src/stories/Autocomplete.stories.tsx +8 -0
  161. package/src/stories/Avatar.stories.tsx +10 -0
  162. package/src/stories/Badge.stories.tsx +14 -6
  163. package/src/stories/Blockquote.stories.tsx +6 -0
  164. package/src/stories/BottomNavigation.stories.tsx +4 -0
  165. package/src/stories/Breadcrumb.stories.tsx +3 -0
  166. package/src/stories/Burger.stories.tsx +1 -0
  167. package/src/stories/Button.stories.tsx +24 -0
  168. package/src/stories/ButtonGroup.stories.tsx +9 -0
  169. package/src/stories/Calendar.stories.tsx +3 -0
  170. package/src/stories/Canvas.stories.tsx +45 -0
  171. package/src/stories/Card.stories.tsx +4 -0
  172. package/src/stories/Carousel.stories.tsx +6 -0
  173. package/src/stories/Cascader.stories.tsx +4 -0
  174. package/src/stories/Chart.stories.tsx +46 -1
  175. package/src/stories/ChatBubble.stories.tsx +8 -2
  176. package/src/stories/ChatMarker.stories.tsx +1 -0
  177. package/src/stories/Checkbox.stories.tsx +40 -0
  178. package/src/stories/CheckboxCard.stories.tsx +8 -0
  179. package/src/stories/CheckboxGroup.stories.tsx +19 -0
  180. package/src/stories/Chip.stories.tsx +10 -19
  181. package/src/stories/CircularProgress.stories.tsx +13 -27
  182. package/src/stories/Clipboard.stories.tsx +6 -0
  183. package/src/stories/CloseButton.stories.tsx +6 -4
  184. package/src/stories/Code.stories.tsx +8 -1
  185. package/src/stories/Collapsible.stories.tsx +2 -0
  186. package/src/stories/ColorPicker.stories.tsx +46 -0
  187. package/src/stories/ColorSwatch.stories.tsx +1 -0
  188. package/src/stories/Combobox.stories.tsx +9 -0
  189. package/src/stories/Command.stories.tsx +2 -0
  190. package/src/stories/Container.stories.tsx +8 -0
  191. package/src/stories/ContextMenu.stories.tsx +9 -0
  192. package/src/stories/CopyButton.stories.tsx +12 -36
  193. package/src/stories/DataList.stories.tsx +8 -0
  194. package/src/stories/DataTable.stories.tsx +39 -0
  195. package/src/stories/DateField.stories.tsx +28 -0
  196. package/src/stories/DatePicker.stories.tsx +34 -0
  197. package/src/stories/DateRangePicker.stories.tsx +32 -0
  198. package/src/stories/Dialog.stories.tsx +8 -0
  199. package/src/stories/Drawer.stories.tsx +6 -0
  200. package/src/stories/DropdownMenu.stories.tsx +2 -0
  201. package/src/stories/Editable.stories.tsx +12 -0
  202. package/src/stories/EmptyState.stories.tsx +9 -0
  203. package/src/stories/FacetedFilter.stories.tsx +197 -0
  204. package/src/stories/Field.stories.tsx +7 -0
  205. package/src/stories/Fieldset.stories.tsx +8 -0
  206. package/src/stories/FileButton.stories.tsx +4 -0
  207. package/src/stories/FileUpload.stories.tsx +16 -17
  208. package/src/stories/FloatLabel.stories.tsx +3 -8
  209. package/src/stories/FloatingActionButton.stories.tsx +10 -0
  210. package/src/stories/FloatingIndicator.stories.tsx +4 -0
  211. package/src/stories/FloatingPanel.stories.tsx +6 -0
  212. package/src/stories/FocusTrap.stories.tsx +5 -0
  213. package/src/stories/FormatByte.stories.tsx +6 -0
  214. package/src/stories/FormatDate.stories.tsx +8 -0
  215. package/src/stories/FormatNumber.stories.tsx +9 -0
  216. package/src/stories/GaugeChart.stories.tsx +9 -3
  217. package/src/stories/Heatmap.stories.tsx +11 -0
  218. package/src/stories/Highlight.stories.tsx +6 -0
  219. package/src/stories/HoverCard.stories.tsx +4 -0
  220. package/src/stories/Image.stories.tsx +9 -0
  221. package/src/stories/Indicator.stories.tsx +19 -0
  222. package/src/stories/InlineEdit.stories.tsx +106 -0
  223. package/src/stories/Input.stories.tsx +7 -0
  224. package/src/stories/InputClearButton.stories.tsx +3 -0
  225. package/src/stories/InputGroup.stories.tsx +40 -0
  226. package/src/stories/Kbd.stories.tsx +7 -1
  227. package/src/stories/KeyboardShortcut.stories.tsx +2 -0
  228. package/src/stories/Label.stories.tsx +2 -0
  229. package/src/stories/Link.stories.tsx +9 -0
  230. package/src/stories/List.stories.tsx +8 -0
  231. package/src/stories/Listbox.stories.tsx +1 -0
  232. package/src/stories/LoadingDots.stories.tsx +5 -3
  233. package/src/stories/LoadingOverlay.stories.tsx +5 -1
  234. package/src/stories/Mark.stories.tsx +5 -0
  235. package/src/stories/MarkdownPreview.stories.tsx +53 -0
  236. package/src/stories/Marquee.stories.tsx +4 -0
  237. package/src/stories/Masonry.stories.tsx +5 -0
  238. package/src/stories/Menubar.stories.tsx +3 -0
  239. package/src/stories/Meter.stories.tsx +11 -17
  240. package/src/stories/MonthPicker.stories.tsx +26 -1
  241. package/src/stories/MotionToggle.stories.tsx +1 -0
  242. package/src/stories/MultiSelect.stories.tsx +9 -0
  243. package/src/stories/NativeSelect.stories.tsx +1 -0
  244. package/src/stories/NavLink.stories.tsx +7 -0
  245. package/src/stories/NavigationMenu.stories.tsx +5 -0
  246. package/src/stories/NavigationRail.stories.tsx +10 -0
  247. package/src/stories/Notification.stories.tsx +13 -34
  248. package/src/stories/NumberInput.stories.tsx +33 -1
  249. package/src/stories/OtpInput.stories.tsx +110 -0
  250. package/src/stories/Overlay.stories.tsx +5 -1
  251. package/src/stories/Pagination.stories.tsx +8 -0
  252. package/src/stories/PasswordInput.stories.tsx +2 -0
  253. package/src/stories/PhoneInput.stories.tsx +127 -0
  254. package/src/stories/PinInput.stories.tsx +9 -2
  255. package/src/stories/Popover.stories.tsx +2 -0
  256. package/src/stories/Progress.stories.tsx +6 -1
  257. package/src/stories/Prose.stories.tsx +8 -0
  258. package/src/stories/QrCode.stories.tsx +2 -0
  259. package/src/stories/Questionnaire.stories.tsx +7 -0
  260. package/src/stories/RadioGroup.stories.tsx +40 -0
  261. package/src/stories/RatingGroup.stories.tsx +8 -4
  262. package/src/stories/Resizable.stories.tsx +4 -2
  263. package/src/stories/Result.stories.tsx +3 -0
  264. package/src/stories/Reveal.stories.tsx +2 -0
  265. package/src/stories/RollingNumber.stories.tsx +5 -0
  266. package/src/stories/ScrollArea.stories.tsx +3 -1
  267. package/src/stories/SearchInput.stories.tsx +10 -6
  268. package/src/stories/SegmentedControl.stories.tsx +11 -0
  269. package/src/stories/Select.stories.tsx +7 -0
  270. package/src/stories/Separator.stories.tsx +6 -0
  271. package/src/stories/Sheet.stories.tsx +5 -0
  272. package/src/stories/Sidebar.stories.tsx +40 -1
  273. package/src/stories/SimpleGrid.stories.tsx +5 -0
  274. package/src/stories/Skeleton.stories.tsx +8 -0
  275. package/src/stories/SkeletonTable.stories.tsx +6 -5
  276. package/src/stories/SkipLink.stories.tsx +3 -0
  277. package/src/stories/Slider.stories.tsx +2 -1
  278. package/src/stories/Sonner.stories.tsx +7 -0
  279. package/src/stories/Sparkline.stories.tsx +14 -1
  280. package/src/stories/Spinner.stories.tsx +20 -10
  281. package/src/stories/Spoiler.stories.tsx +5 -0
  282. package/src/stories/Squircle.stories.tsx +7 -0
  283. package/src/stories/Stack.stories.tsx +7 -0
  284. package/src/stories/StatusBadge.stories.tsx +12 -6
  285. package/src/stories/Stepper.stories.tsx +5 -0
  286. package/src/stories/Switch.stories.tsx +4 -0
  287. package/src/stories/Table.stories.tsx +10 -1
  288. package/src/stories/Tabs.stories.tsx +8 -0
  289. package/src/stories/Tag.stories.tsx +13 -5
  290. package/src/stories/TagsInput.stories.tsx +15 -0
  291. package/src/stories/Text.stories.tsx +12 -0
  292. package/src/stories/Textarea.stories.tsx +9 -0
  293. package/src/stories/ThemeIcon.stories.tsx +6 -3
  294. package/src/stories/TimePicker.stories.tsx +2 -0
  295. package/src/stories/Timeline.stories.tsx +12 -0
  296. package/src/stories/Timer.stories.tsx +30 -0
  297. package/src/stories/Toggle.stories.tsx +7 -5
  298. package/src/stories/ToggleGroup.stories.tsx +5 -0
  299. package/src/stories/ToggleTip.stories.tsx +4 -0
  300. package/src/stories/Toolbar.stories.tsx +6 -0
  301. package/src/stories/Tooltip.stories.tsx +3 -0
  302. package/src/stories/Tour.stories.tsx +3 -0
  303. package/src/stories/TransferList.stories.tsx +7 -0
  304. package/src/stories/TreeSelect.stories.tsx +4 -0
  305. package/src/stories/TreeView.stories.tsx +5 -0
  306. package/src/stories/TypingIndicator.stories.tsx +4 -0
  307. package/src/stories/VisuallyHidden.stories.tsx +3 -0
  308. package/src/stories/Watermark.stories.tsx +6 -0
  309. package/src/stories/WeekPicker.stories.tsx +25 -1
  310. package/src/stories/WordRotate.stories.tsx +5 -0
  311. package/src/stories/YearPicker.stories.tsx +26 -11
  312. package/src/stories/story-groups.json +22 -16
  313. package/src/styles.css +50 -2
  314. package/src/tokens.json +86 -58
@@ -0,0 +1,247 @@
1
+ "use client";
2
+
3
+ import type { ReactNode } from "react";
4
+ import {
5
+ Columns2,
6
+ Maximize2,
7
+ Monitor,
8
+ Moon,
9
+ PanelLeftOpen,
10
+ Smartphone,
11
+ Sun,
12
+ SunMoon,
13
+ Tablet,
14
+ } from "lucide-react";
15
+ import { Button } from "../ui/button";
16
+ import { SegmentedControl, SegmentedControlItem } from "../ui/segmented-control";
17
+ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../ui/tooltip";
18
+ import { PreviewFrame } from "./preview-frame";
19
+ import {
20
+ STUDIO_SUBJECTS,
21
+ STUDIO_THEMES,
22
+ STUDIO_VIEWPORTS,
23
+ type StudioPreviewTheme,
24
+ type StudioSubject,
25
+ type StudioViewport,
26
+ type StudioViewState,
27
+ } from "./types";
28
+
29
+ const VIEWPORT_ICON: Record<StudioViewport, ReactNode> = {
30
+ fill: <Maximize2 strokeWidth={1.5} aria-hidden="true" />,
31
+ "390": <Smartphone strokeWidth={1.5} aria-hidden="true" />,
32
+ "768": <Tablet strokeWidth={1.5} aria-hidden="true" />,
33
+ "1280": <Monitor strokeWidth={1.5} aria-hidden="true" />,
34
+ };
35
+
36
+ const VIEWPORT_LABEL: Record<StudioViewport, string> = {
37
+ fill: "Fill width",
38
+ "390": "390 pixels",
39
+ "768": "768 pixels",
40
+ "1280": "1280 pixels",
41
+ };
42
+
43
+ /**
44
+ * One icon-only viewport option with a tooltip. It is a component with its own `value`
45
+ * prop (not a bare Tooltip child) so SegmentedControl can still count and index it.
46
+ */
47
+ function ViewportItem({
48
+ value,
49
+ onSelect,
50
+ }: {
51
+ value: StudioViewport;
52
+ onSelect: (value: StudioViewport) => void;
53
+ }) {
54
+ return (
55
+ <Tooltip>
56
+ <TooltipTrigger asChild>
57
+ {/* Explicit onClick: the tooltip trigger's merged props spread after the item's own
58
+ handler, so without this the Radix onClick would replace the selection click. */}
59
+ <SegmentedControlItem
60
+ value={value}
61
+ aria-label={VIEWPORT_LABEL[value]}
62
+ className="min-w-11 px-2"
63
+ onClick={() => onSelect(value)}
64
+ >
65
+ {VIEWPORT_ICON[value]}
66
+ </SegmentedControlItem>
67
+ </TooltipTrigger>
68
+ <TooltipContent>{VIEWPORT_LABEL[value]}</TooltipContent>
69
+ </Tooltip>
70
+ );
71
+ }
72
+
73
+ const THEME_ICON: Record<StudioPreviewTheme, ReactNode> = {
74
+ match: <SunMoon strokeWidth={1.5} aria-hidden="true" />,
75
+ light: <Sun strokeWidth={1.5} aria-hidden="true" />,
76
+ dark: <Moon strokeWidth={1.5} aria-hidden="true" />,
77
+ both: <Columns2 strokeWidth={1.5} aria-hidden="true" />,
78
+ };
79
+
80
+ /** Icon-only theme option with a tooltip; accessible name stays the visible label. */
81
+ function ThemeItem({
82
+ value,
83
+ label,
84
+ onSelect,
85
+ }: {
86
+ value: StudioPreviewTheme;
87
+ label: string;
88
+ onSelect: (value: StudioPreviewTheme) => void;
89
+ }) {
90
+ return (
91
+ <Tooltip>
92
+ <TooltipTrigger asChild>
93
+ <SegmentedControlItem
94
+ value={value}
95
+ aria-label={label}
96
+ className="min-w-11 px-2"
97
+ onClick={() => onSelect(value)}
98
+ >
99
+ {THEME_ICON[value]}
100
+ </SegmentedControlItem>
101
+ </TooltipTrigger>
102
+ <TooltipContent>{label}</TooltipContent>
103
+ </Tooltip>
104
+ );
105
+ }
106
+
107
+ function subjectLabel(subject: StudioSubject): string {
108
+ return STUDIO_SUBJECTS.find((s) => s.value === subject)?.label ?? subject;
109
+ }
110
+
111
+ function themeLabel(theme: StudioPreviewTheme): string {
112
+ return STUDIO_THEMES.find((t) => t.value === theme)?.label ?? theme;
113
+ }
114
+
115
+ export function PreviewPane({
116
+ view,
117
+ setView,
118
+ appDark,
119
+ isMobile,
120
+ onExpandControls,
121
+ }: {
122
+ view: StudioViewState;
123
+ setView: <K extends keyof StudioViewState>(key: K, value: StudioViewState[K]) => void;
124
+ appDark: boolean;
125
+ isMobile: boolean;
126
+ /** Non-null only while the controls pane is collapsed. */
127
+ onExpandControls: (() => void) | null;
128
+ }) {
129
+ // On mobile there is one frame at Fill and no Both. The URL may still say otherwise.
130
+ const theme: StudioPreviewTheme = isMobile && view.theme === "both" ? "match" : view.theme;
131
+ const viewport: StudioViewport = isMobile ? "fill" : view.viewport;
132
+ const both = theme === "both";
133
+ const width = both ? null : (STUDIO_VIEWPORTS.find((v) => v.value === viewport)?.width ?? null);
134
+
135
+ const subject = STUDIO_SUBJECTS.find((s) => s.value === view.subject) ?? STUDIO_SUBJECTS[0];
136
+
137
+ const forcedFor = (t: StudioPreviewTheme): boolean | null =>
138
+ t === "match" ? null : t === "dark";
139
+
140
+ return (
141
+ <TooltipProvider>
142
+ <div data-slot="studio-preview-pane" className="flex h-full min-h-0 min-w-0 flex-col">
143
+ <div className="flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 px-2 py-1">
144
+ {onExpandControls ? (
145
+ <Tooltip>
146
+ <TooltipTrigger asChild>
147
+ <Button
148
+ variant="ghost"
149
+ size="icon-xl"
150
+ aria-label="Show controls"
151
+ onClick={onExpandControls}
152
+ >
153
+ <PanelLeftOpen strokeWidth={1.5} aria-hidden="true" />
154
+ </Button>
155
+ </TooltipTrigger>
156
+ <TooltipContent>Show controls</TooltipContent>
157
+ </Tooltip>
158
+ ) : null}
159
+
160
+ <SegmentedControl
161
+ label="Preview subject"
162
+ value={view.subject}
163
+ onValueChange={(v) => setView("subject", v as StudioSubject)}
164
+ >
165
+ {STUDIO_SUBJECTS.map((s) => (
166
+ <SegmentedControlItem key={s.value} value={s.value} className="px-2">
167
+ {s.label}
168
+ </SegmentedControlItem>
169
+ ))}
170
+ </SegmentedControl>
171
+
172
+ {isMobile ? null : (
173
+ <>
174
+ <SegmentedControl
175
+ label="Preview width"
176
+ value={viewport}
177
+ disabled={both}
178
+ onValueChange={(v) => setView("viewport", v as StudioViewport)}
179
+ >
180
+ {STUDIO_VIEWPORTS.map((v) => (
181
+ <ViewportItem
182
+ key={v.value}
183
+ value={v.value}
184
+ onSelect={(next) => setView("viewport", next)}
185
+ />
186
+ ))}
187
+ </SegmentedControl>
188
+
189
+ <SegmentedControl
190
+ label="Preview theme"
191
+ value={theme}
192
+ onValueChange={(v) => setView("theme", v as StudioPreviewTheme)}
193
+ >
194
+ {STUDIO_THEMES.map((t) => (
195
+ <ThemeItem
196
+ key={t.value}
197
+ value={t.value}
198
+ label={t.label}
199
+ onSelect={(next) => setView("theme", next)}
200
+ />
201
+ ))}
202
+ </SegmentedControl>
203
+ </>
204
+ )}
205
+
206
+ {both ? (
207
+ <p className="ml-auto min-w-0 truncate text-xs text-muted-foreground">
208
+ Width follows the pane in Both
209
+ </p>
210
+ ) : null}
211
+ </div>
212
+
213
+ <div className="flex min-h-0 flex-1 gap-4 bg-muted p-4">
214
+ {both ? (
215
+ <>
216
+ <PreviewFrame
217
+ src={subject.src}
218
+ forcedDark={false}
219
+ appDark={appDark}
220
+ width={null}
221
+ caption="Light"
222
+ title={`Studio preview, ${subjectLabel(view.subject)}, Light`}
223
+ />
224
+ <PreviewFrame
225
+ src={subject.src}
226
+ forcedDark={true}
227
+ appDark={appDark}
228
+ width={null}
229
+ caption="Dark"
230
+ title={`Studio preview, ${subjectLabel(view.subject)}, Dark`}
231
+ />
232
+ </>
233
+ ) : (
234
+ <PreviewFrame
235
+ src={subject.src}
236
+ forcedDark={forcedFor(theme)}
237
+ appDark={appDark}
238
+ width={width}
239
+ caption={themeLabel(theme)}
240
+ title={`Studio preview, ${subjectLabel(view.subject)}, ${themeLabel(theme)}`}
241
+ />
242
+ )}
243
+ </div>
244
+ </div>
245
+ </TooltipProvider>
246
+ );
247
+ }
@@ -1,153 +1,158 @@
1
1
  "use client";
2
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";
3
+ import { useCallback, useEffect, useRef, useState } from "react";
4
+ import { usePanelRef } from "react-resizable-panels";
5
+ import {
6
+ ResizableHandle,
7
+ ResizablePanel,
8
+ ResizablePanelGroup,
9
+ } from "@behavioral-agentic-design-system/core/components/ui/resizable";
11
10
  import {
12
11
  SegmentedControl,
13
12
  SegmentedControlItem,
14
13
  } from "@behavioral-agentic-design-system/core/components/ui/segmented-control";
14
+ import { useIsMobile } from "@behavioral-agentic-design-system/core/hooks/use-mobile";
15
+ import { ControlPanel } from "./control-panel";
16
+ import { PreviewPane } from "./preview-pane";
17
+ import { useStudioViewState } from "./use-studio-view-state";
15
18
 
16
19
  /**
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.
20
+ * Studio: tweak on the left, see the result on the right.
36
21
  *
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:
22
+ * Plan: docs/plans/2026-10-07-studio-screen.md. Token values live in the
23
+ * existing global hooks (localStorage plus storage events). View state
24
+ * (subject, width, theme, panel mode, collapse) lives in the URL.
39
25
  *
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.
26
+ * The preview is an iframe. The old comment here claimed an iframe would keep
27
+ * stale values; that was measured and does not hold, because every preview
28
+ * route mounts the global hooks, which listen for the `storage` event (see the
29
+ * first acceptance criterion of WP3 in the plan). The iframe is what gives an
30
+ * independent theme and real viewport widths.
45
31
  */
46
32
 
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;
33
+ function isTypingTarget(el: EventTarget | null): boolean {
34
+ if (!(el instanceof HTMLElement)) return false;
35
+ return el.closest("input, textarea, select, [contenteditable]:not([contenteditable='false'])") !== null;
36
+ }
55
37
 
56
- export default function Studio() {
57
- const [collapsed, setCollapsed] = useState(false);
58
- const [specimen, setSpecimen] = useState<string>("cards");
38
+ export default function Studio({ dark }: { dark: boolean }) {
39
+ const { state: view, set } = useStudioViewState();
40
+ const isMobile = useIsMobile();
41
+ const panelRef = usePanelRef();
42
+ const [mobileView, setMobileView] = useState<"tweak" | "preview">("tweak");
59
43
 
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
- });
44
+ // Latest collapse flag for callbacks that must not close over a stale value.
45
+ const collapsedRef = useRef(view.controlsCollapsed);
46
+ collapsedRef.current = view.controlsCollapsed;
70
47
 
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;
48
+ // View state drives the panel: covers the URL restore after mount.
49
+ useEffect(() => {
50
+ if (isMobile) return;
51
+ const panel = panelRef.current;
52
+ if (!panel) return;
53
+ const id = requestAnimationFrame(() => {
54
+ if (view.controlsCollapsed && !panel.isCollapsed()) panel.collapse();
55
+ else if (!view.controlsCollapsed && panel.isCollapsed()) panel.expand();
80
56
  });
81
- }
57
+ return () => cancelAnimationFrame(id);
58
+ }, [view.controlsCollapsed, isMobile, panelRef]);
82
59
 
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
- )}
60
+ // The panel drives view state: covers drag-to-collapse and the keyboard.
61
+ const handleResize = useCallback(() => {
62
+ const panel = panelRef.current;
63
+ if (!panel) return;
64
+ const collapsed = panel.isCollapsed();
65
+ if (collapsed !== collapsedRef.current) set("controlsCollapsed", collapsed);
66
+ }, [panelRef, set]);
113
67
 
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}
68
+ const collapse = useCallback(() => set("controlsCollapsed", true), [set]);
69
+ const expand = useCallback(() => set("controlsCollapsed", false), [set]);
70
+
71
+ // Mod+\ toggles the controls (Figma's hide-UI chord). Ignored while typing.
72
+ useEffect(() => {
73
+ if (isMobile) return;
74
+ const onKey = (e: KeyboardEvent) => {
75
+ if (!(e.metaKey || e.ctrlKey) || e.key !== "\\") return;
76
+ if (isTypingTarget(e.target)) return;
77
+ e.preventDefault();
78
+ set("controlsCollapsed", !collapsedRef.current);
79
+ };
80
+ window.addEventListener("keydown", onKey);
81
+ return () => window.removeEventListener("keydown", onKey);
82
+ }, [isMobile, set]);
83
+
84
+ const preview = (
85
+ <PreviewPane
86
+ view={view}
87
+ setView={set}
88
+ appDark={dark}
89
+ isMobile={isMobile}
90
+ onExpandControls={view.controlsCollapsed ? expand : null}
91
+ />
92
+ );
93
+
94
+ if (isMobile) {
95
+ return (
96
+ <div className="flex size-full min-h-0 flex-col">
97
+ <div className="flex shrink-0 items-center px-4 py-2">
128
98
  <SegmentedControl
129
- value={specimen}
130
- onValueChange={setSpecimen}
131
- label="Specimen set"
99
+ value={mobileView}
100
+ onValueChange={(v) => setMobileView(v as "tweak" | "preview")}
101
+ label="Studio view"
132
102
  >
133
- {SPECIMENS.map((s) => (
134
- <SegmentedControlItem key={s.id} value={s.id}>
135
- {s.label}
136
- </SegmentedControlItem>
137
- ))}
103
+ <SegmentedControlItem value="tweak">Controls</SegmentedControlItem>
104
+ <SegmentedControlItem value="preview">Preview</SegmentedControlItem>
138
105
  </SegmentedControl>
139
- <p className="truncate text-sm text-muted-foreground">
140
- Real compositions. They repaint as you change a value.
141
- </p>
142
106
  </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>
107
+ {/* Both stay mounted so the iframe never cold-loads twice. */}
108
+ <div className="min-h-0 flex-1" hidden={mobileView !== "tweak"}>
109
+ <ControlPanel
110
+ mode={view.panel}
111
+ onModeChange={(m) => set("panel", m)}
112
+ />
113
+ </div>
114
+ <div className="min-h-0 flex-1" hidden={mobileView !== "preview"}>
115
+ {preview}
116
+ </div>
150
117
  </div>
151
- </div>
118
+ );
119
+ }
120
+
121
+ return (
122
+ <ResizablePanelGroup
123
+ orientation="horizontal"
124
+ className="size-full min-h-0"
125
+ resizeTargetMinimumSize={{ coarse: 44, fine: 44 }}
126
+ >
127
+ <ResizablePanel
128
+ id="studio-controls"
129
+ panelRef={panelRef}
130
+ defaultSize="340px"
131
+ minSize="280px"
132
+ maxSize="480px"
133
+ collapsible
134
+ collapsedSize="0px"
135
+ onResize={handleResize}
136
+ >
137
+ <div className="h-full min-h-0 overflow-hidden">
138
+ <ControlPanel
139
+ mode={view.panel}
140
+ onModeChange={(m) => set("panel", m)}
141
+ onCollapse={collapse}
142
+ />
143
+ </div>
144
+ </ResizablePanel>
145
+ <ResizableHandle
146
+ className="bg-transparent after:w-11"
147
+ aria-label="Resize controls"
148
+ style={{
149
+ transitionDuration: "var(--duration-fast)",
150
+ transitionTimingFunction: "var(--ease-out)",
151
+ }}
152
+ />
153
+ <ResizablePanel id="studio-preview" minSize="360px">
154
+ <div className="h-full min-h-0 min-w-0">{preview}</div>
155
+ </ResizablePanel>
156
+ </ResizablePanelGroup>
152
157
  );
153
158
  }