cursedbelt 5.94.0 → 5.96.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 (71) hide show
  1. package/dist/react/canvas-hud/index.d.ts +2 -2
  2. package/dist/react/canvas-hud/index.d.ts.map +1 -1
  3. package/dist/react/canvas-hud/index.js +1 -1
  4. package/dist/react/canvas-hud/index.js.map +1 -1
  5. package/dist/react/canvas-hud/viewport.d.ts +32 -0
  6. package/dist/react/canvas-hud/viewport.d.ts.map +1 -1
  7. package/dist/react/canvas-hud/viewport.js +51 -0
  8. package/dist/react/canvas-hud/viewport.js.map +1 -1
  9. package/dist/react/components/AppShell.d.ts +12 -1
  10. package/dist/react/components/AppShell.d.ts.map +1 -1
  11. package/dist/react/components/AppShell.js +24 -5
  12. package/dist/react/components/AppShell.js.map +1 -1
  13. package/dist/react/components/ComboboxField.js +2 -2
  14. package/dist/react/components/ComboboxField.js.map +1 -1
  15. package/dist/react/components/DatePicker.d.ts +9 -5
  16. package/dist/react/components/DatePicker.d.ts.map +1 -1
  17. package/dist/react/components/DatePicker.js +192 -27
  18. package/dist/react/components/DatePicker.js.map +1 -1
  19. package/dist/react/components/InlineEditableText.d.ts +12 -2
  20. package/dist/react/components/InlineEditableText.d.ts.map +1 -1
  21. package/dist/react/components/InlineEditableText.js +11 -8
  22. package/dist/react/components/InlineEditableText.js.map +1 -1
  23. package/dist/react/components/Popover.d.ts +7 -1
  24. package/dist/react/components/Popover.d.ts.map +1 -1
  25. package/dist/react/components/Popover.js +54 -4
  26. package/dist/react/components/Popover.js.map +1 -1
  27. package/dist/react/components/suggestionList.js +2 -2
  28. package/dist/react/components/suggestionList.js.map +1 -1
  29. package/dist/react/lib/dateText.d.ts +21 -0
  30. package/dist/react/lib/dateText.d.ts.map +1 -0
  31. package/dist/react/lib/dateText.js +94 -0
  32. package/dist/react/lib/dateText.js.map +1 -0
  33. package/dist/react/lib/floatingSide.d.ts +42 -0
  34. package/dist/react/lib/floatingSide.d.ts.map +1 -0
  35. package/dist/react/lib/floatingSide.js +54 -0
  36. package/dist/react/lib/floatingSide.js.map +1 -0
  37. package/dist/react/lib/floatingStyles.d.ts +12 -0
  38. package/dist/react/lib/floatingStyles.d.ts.map +1 -1
  39. package/dist/react/lib/floatingStyles.js +12 -0
  40. package/dist/react/lib/floatingStyles.js.map +1 -1
  41. package/dist/styles-areas/analytics.css +11 -10
  42. package/dist/styles-areas/data-table.css +13 -12
  43. package/dist/styles-areas/fields.css +12 -10
  44. package/dist/styles-areas/stats.css +12 -11
  45. package/dist/styles-areas/wizard.css +6 -6
  46. package/dist/styles-utilities.css +15 -0
  47. package/package.json +3 -2
  48. package/src/react/canvas-hud/index.ts +10 -0
  49. package/src/react/canvas-hud/viewport.spec.ts +70 -0
  50. package/src/react/canvas-hud/viewport.ts +77 -0
  51. package/src/react/components/AppShell.spec.tsx +53 -0
  52. package/src/react/components/AppShell.tsx +79 -23
  53. package/src/react/components/ComboboxField.tsx +2 -2
  54. package/src/react/components/ControlHeightScale.spec.tsx +2 -2
  55. package/src/react/components/DatePicker.spec.tsx +186 -5
  56. package/src/react/components/DatePicker.tsx +416 -63
  57. package/src/react/components/InlineEditableText.spec.tsx +29 -0
  58. package/src/react/components/InlineEditableText.tsx +26 -10
  59. package/src/react/components/Popover.tsx +62 -5
  60. package/src/react/components/suggestionList.tsx +2 -2
  61. package/src/react/lib/dateText.ts +94 -0
  62. package/src/react/lib/floatingSide.spec.ts +37 -0
  63. package/src/react/lib/floatingSide.ts +73 -0
  64. package/src/react/lib/floatingStyles.spec.ts +36 -1
  65. package/src/react/lib/floatingStyles.ts +13 -0
  66. package/src/styles-areas/analytics.css +11 -10
  67. package/src/styles-areas/data-table.css +13 -12
  68. package/src/styles-areas/fields.css +12 -10
  69. package/src/styles-areas/stats.css +12 -11
  70. package/src/styles-areas/wizard.css +6 -6
  71. package/src/styles-utilities.css +15 -0
@@ -1,13 +1,21 @@
1
1
  import { describe, expect, test } from 'bun:test';
2
2
  import {
3
3
  centerView,
4
+ clampImageView,
4
5
  clampScale,
5
6
  fitScale,
6
7
  fitView,
8
+ IMAGE_FIT,
9
+ imageWheelFactor,
10
+ imageZoomLabel,
11
+ isImageZoomed,
7
12
  levelOfDetail,
13
+ panImageBy,
14
+ stepImageScale,
8
15
  visibleBounds,
9
16
  wheelZoomFactor,
10
17
  zoomAt,
18
+ zoomImageAt,
11
19
  } from './viewport.js';
12
20
 
13
21
  /** Where a world point lands on screen under a view. */
@@ -103,3 +111,65 @@ describe('levelOfDetail (CNV-5)', () => {
103
111
  expect(levelOfDetail(0.4, { mid: 0.2, close: 0.4 })).toBe('close');
104
112
  });
105
113
  });
114
+
115
+ describe('the image viewer (a picture laid out at its fit, viewed about the stage center; forge task 3780)', () => {
116
+ const picture = { width: 400, height: 300 };
117
+ const stage = { width: 800, height: 300 };
118
+ const photos = { min: 1, max: 8 };
119
+ const family = { min: 0.25, max: 8 };
120
+
121
+ test('🔴 zooming at a point keeps that point of the picture under it', () => {
122
+ // The pointer 100px right of center, over the picture point 100px right of its center.
123
+ const view = zoomImageAt(IMAGE_FIT, 2, { x: 100, y: 0 }, picture, picture, photos);
124
+ expect(view).toEqual({ scale: 2, x: -100, y: 0 });
125
+ expect(100 * view.scale + view.x).toBe(100);
126
+ });
127
+
128
+ test('🔴 a picture is never dragged off the stage: centered on an axis it does not fill, no gap on one it does', () => {
129
+ const view = clampImageView({ scale: 1.5, x: 999, y: 999 }, picture, stage, photos);
130
+ // 600 wide in an 800 stage: centered. 450 tall in a 300 stage: at most 75 either way.
131
+ expect(view).toEqual({ scale: 1.5, x: 0, y: 75 });
132
+ expect(panImageBy(view, 0, -1000, picture, stage, photos).y).toBe(-75);
133
+ });
134
+
135
+ test('the scale stays inside the limits, the fit has no offset, and below the fit the picture stays centered', () => {
136
+ expect(clampImageView({ scale: 0.2, x: 50, y: 50 }, picture, stage, photos)).toEqual(IMAGE_FIT);
137
+ expect(clampImageView({ scale: 40, x: 0, y: 0 }, picture, stage, photos).scale).toBe(8);
138
+ expect(zoomImageAt({ scale: 3, x: 40, y: 10 }, 1, { x: 0, y: 0 }, picture, stage, photos)).toEqual(IMAGE_FIT);
139
+ expect(clampImageView({ scale: 0.1, x: 50, y: -50 }, picture, stage, family)).toEqual({ scale: 0.25, x: 0, y: 0 });
140
+ expect(clampImageView({ scale: Number.NaN, x: 0, y: 0 }, picture, stage, family)).toEqual(IMAGE_FIT);
141
+ });
142
+
143
+ test('the buttons walk the stops inside the limits, from wherever a pinch left the scale', () => {
144
+ expect(stepImageScale(1, 1, photos)).toBe(1.5);
145
+ expect(stepImageScale(2.3, 1, photos)).toBe(3);
146
+ expect(stepImageScale(2.3, -1, photos)).toBe(2);
147
+ expect(stepImageScale(1.2, -1, photos)).toBe(1);
148
+ expect(stepImageScale(1, -1, photos)).toBe(1);
149
+ expect(stepImageScale(8, 1, photos)).toBe(8);
150
+ expect(stepImageScale(1, -1, family)).toBe(0.75);
151
+ expect(stepImageScale(0.25, -1, family)).toBe(0.25);
152
+ expect(stepImageScale(5, 1, { min: 1, max: 5 })).toBe(5);
153
+ expect(stepImageScale(4, 1, { min: 1, max: 5 })).toBe(5);
154
+ });
155
+
156
+ test('a wheel zooms in on a negative delta, out on a positive one, a flung wheel is capped, and it outpaces the canvas', () => {
157
+ expect(imageWheelFactor(-10)).toBeGreaterThan(1);
158
+ expect(imageWheelFactor(10)).toBeLessThan(1);
159
+ expect(imageWheelFactor(-5000)).toBe(imageWheelFactor(-60));
160
+ expect(imageWheelFactor(Number.NaN)).toBe(1);
161
+ expect(imageWheelFactor(-10)).toBeGreaterThan(wheelZoomFactor(-10));
162
+ });
163
+
164
+ test('the readout', () => {
165
+ expect(imageZoomLabel(1)).toBe('Fit');
166
+ expect(imageZoomLabel(1.5)).toBe('1.5×');
167
+ expect(imageZoomLabel(2)).toBe('2×');
168
+ expect(imageZoomLabel(3.4)).toBe('3×');
169
+ expect(imageZoomLabel(0.5)).toBe('0.5×');
170
+ expect(imageZoomLabel(0.25)).toBe('0.25×');
171
+ expect(isImageZoomed(IMAGE_FIT)).toBe(false);
172
+ expect(isImageZoomed({ scale: 1.2, x: 0, y: 0 })).toBe(true);
173
+ expect(isImageZoomed({ scale: 0.5, x: 0, y: 0 })).toBe(true);
174
+ });
175
+ });
@@ -122,3 +122,80 @@ export function levelOfDetail(scale: number, thresholds: LevelOfDetailThresholds
122
122
  if (scale >= thresholds.mid) return 'mid';
123
123
  return 'far';
124
124
  }
125
+
126
+ // ── The image viewer's half ──────────────────────────────────────────────────────────────────
127
+ //
128
+ // A picture viewer (photos' lightbox, family's document canvas) is a canvas whose world is ONE
129
+ // picture, already laid out at its fit. Its view is the same `CanvasView`, read about the STAGE'S
130
+ // CENTER instead of its corner: `x`/`y` are how far the picture's center sits from the stage's,
131
+ // in screen pixels, and `scale` 1 is the fit — so the CSS is `translate(x, y) scale(scale)` with
132
+ // `transform-origin: center`, and an anchor is a point measured from the stage's center. That is
133
+ // why it is centered rather than cornered: the fit is `{ scale: 1, x: 0, y: 0 }` at every stage
134
+ // size, so a resized window or a turned phone keeps the view's meaning, and only the clamp moves.
135
+ // The anchoring arithmetic is the same either way, so it is {@link zoomAt}'s.
136
+
137
+ /** How far a picture viewer zooms: `min` 1 never goes below the fit (photos); under 1 shows it smaller (family's wall-sized prints). */
138
+ export interface ImageZoomLimits {
139
+ min: number;
140
+ max: number;
141
+ }
142
+
143
+ /** The fit: the picture whole and centered. */
144
+ export const IMAGE_FIT: CanvasView = { scale: 1, x: 0, y: 0 };
145
+
146
+ /** The stops the − and + buttons walk, inside a viewer's limits; a pinch or a wheel lands anywhere between. */
147
+ export const IMAGE_ZOOM_STEPS: readonly number[] = [0.25, 0.5, 0.75, 1, 1.5, 2, 3, 4, 6, 8];
148
+
149
+ const finiteScale = (scale: number, limits: ImageZoomLimits): number =>
150
+ clampScale(Number.isFinite(scale) ? scale : 1, limits.min, limits.max);
151
+
152
+ /**
153
+ * The view held inside what the scaled `picture` (its laid-out size at the fit) can show on `stage`:
154
+ * centered on an axis it does not fill, else panned no further than its edge — the picture never
155
+ * slides off and leaves a gap where it could have filled the stage.
156
+ */
157
+ export function clampImageView(view: CanvasView, picture: CanvasSize, stage: CanvasSize, limits: ImageZoomLimits): CanvasView {
158
+ const scale = finiteScale(view.scale, limits);
159
+ const room = (content: number, box: number) => Math.max(0, (content * scale - box) / 2);
160
+ const rx = room(picture.width, stage.width);
161
+ const ry = room(picture.height, stage.height);
162
+ // `+ 0` turns a -0 into 0, so a clamped view compares equal to the fit.
163
+ return { scale, x: clampScale(view.x, -rx, rx) + 0, y: clampScale(view.y, -ry, ry) + 0 };
164
+ }
165
+
166
+ /** Zoom to `scale` keeping `anchor` (screen pixels from the stage's center) over the same spot of the picture, then clamp. */
167
+ export function zoomImageAt(view: CanvasView, scale: number, anchor: CanvasPoint, picture: CanvasSize, stage: CanvasSize, limits: ImageZoomLimits): CanvasView {
168
+ return clampImageView(zoomAt(view, finiteScale(scale, limits), anchor), picture, stage, limits);
169
+ }
170
+
171
+ /** Move the picture by a drag's or a scroll's screen delta, then clamp. */
172
+ export function panImageBy(view: CanvasView, dx: number, dy: number, picture: CanvasSize, stage: CanvasSize, limits: ImageZoomLimits): CanvasView {
173
+ return clampImageView({ ...view, x: view.x + dx, y: view.y + dy }, picture, stage, limits);
174
+ }
175
+
176
+ /** The next button stop in `direction` from wherever a pinch left the scale, inside `limits`. */
177
+ export function stepImageScale(scale: number, direction: 1 | -1, limits: ImageZoomLimits, steps: readonly number[] = IMAGE_ZOOM_STEPS): number {
178
+ const stops = [...new Set([limits.min, ...steps.filter((s) => s > limits.min && s < limits.max), limits.max])];
179
+ if (direction > 0) return stops.find((s) => s > scale + 0.01) ?? limits.max;
180
+ return stops.reverse().find((s) => s < scale - 0.01) ?? limits.min;
181
+ }
182
+
183
+ /**
184
+ * One wheel event's factor for a picture: a trackpad pinch (a ctrl-wheel stream of small deltas)
185
+ * tracks the fingers about 1:1, and a mouse notch (a delta of ~100) is capped at one comfortable
186
+ * step. Faster than {@link wheelZoomFactor}, which a canvas spends over a range of 0.02–4×; a
187
+ * picture's whole range is a few doublings.
188
+ */
189
+ export function imageWheelFactor(deltaY: number): number {
190
+ return Math.exp(-clampScale(Number.isFinite(deltaY) ? deltaY : 0, -60, 60) / 120);
191
+ }
192
+
193
+ /** Is the view anything but the fit's scale? */
194
+ export const isImageZoomed = (view: CanvasView): boolean => Math.abs(view.scale - 1) > 0.001;
195
+
196
+ /** The readout between the buttons: "Fit", "1.5×", "2×", "0.5×". */
197
+ export function imageZoomLabel(scale: number): string {
198
+ if (Math.abs(scale - 1) <= 0.001) return 'Fit';
199
+ const digits = scale < 1 ? 2 : scale < 2 ? 1 : 0;
200
+ return `${Number(scale.toFixed(digits)).toString()}×`;
201
+ }
@@ -58,6 +58,59 @@ describe('AppShell', () => {
58
58
  expect(q(container, '[data-cb-nav-backdrop]')).toBeNull();
59
59
  });
60
60
 
61
+ test('🔴 navCollapsed folds the lg sidebar to the icon rail, and the fold button in the rail head asks for the next state (forge task 3773)', () => {
62
+ const changes: boolean[] = [];
63
+ const { container, rerender } = render(
64
+ <AppShell nav={station} navHeader={<span data-brand=''>Photos</span>} account={<span>CU</span>} onNavCollapsedChange={(next) => changes.push(next)}>
65
+ x
66
+ </AppShell>,
67
+ );
68
+ const [icon, full] = qa(container, '[data-cb-nav-rail]') as [HTMLElement, HTMLElement];
69
+ // Open: the icon rail hides at lg, the full sidebar shows there — as before.
70
+ expect(icon.className).toContain('lg:hidden');
71
+ expect(full.className).toContain('lg:flex');
72
+ // The fold button is in BOTH heads (the rail must be able to unfold itself), and says what it does.
73
+ const folds = qa(container, '[data-cb-rail-fold]');
74
+ expect(folds).toHaveLength(2);
75
+ expect(folds.map((b) => b.getAttribute('aria-label'))).toEqual(['Show the sidebar', 'Hide the sidebar']);
76
+ // With no ⌘K row it sits on the brand line; with one, beside the ⌘K trigger — never a third control
77
+ // beside a worded account launcher, which left the brand no width (photos, WebKit, 2026-10-25).
78
+ const { container: noCommand } = render(
79
+ <AppShell nav={station} commandPalette={false} navHeader={<span>Photos</span>} account={<span>CU</span>} onNavCollapsedChange={() => {}}>
80
+ x
81
+ </AppShell>,
82
+ );
83
+ const fullNoCommand = qa(noCommand, '[data-cb-nav-rail]')[1] as HTMLElement;
84
+ expect(q(fullNoCommand, '[data-cb-rail-command-row]')).toBeNull();
85
+ expect(q(fullNoCommand, '[data-cb-account]')?.parentElement?.querySelector('[data-cb-rail-fold]')).not.toBeNull();
86
+ const { container: withCommand } = render(
87
+ <AppShell nav={station} navHeader={<span>Photos</span>} account={<span>Curt Phillips ▾</span>} onOpenCommand={() => {}} onNavCollapsedChange={() => {}}>
88
+ x
89
+ </AppShell>,
90
+ );
91
+ const fullWithCommand = qa(withCommand, '[data-cb-nav-rail]')[1] as HTMLElement;
92
+ expect(q(fullWithCommand, '[data-cb-account]')?.parentElement?.querySelector('[data-cb-rail-fold]')).toBeNull();
93
+ expect(q(fullWithCommand, '[data-cb-rail-command-row] [data-cb-rail-fold]')).not.toBeNull();
94
+ expect(q(fullWithCommand, '[data-cb-rail-command-row] [data-cb-command-trigger]')).not.toBeNull();
95
+ fireEvent.click(folds[1] as HTMLElement);
96
+ expect(changes).toEqual([true]);
97
+ // Folded: the icon rail stays at lg and the full sidebar is gone from every width.
98
+ rerender(
99
+ <AppShell nav={station} navHeader={<span data-brand=''>Photos</span>} account={<span>CU</span>} navCollapsed onNavCollapsedChange={(next) => changes.push(next)}>
100
+ x
101
+ </AppShell>,
102
+ );
103
+ const [iconFolded, fullFolded] = qa(container, '[data-cb-nav-rail]') as [HTMLElement, HTMLElement];
104
+ expect(iconFolded.className).not.toContain('lg:hidden');
105
+ expect(fullFolded.className).not.toContain('lg:flex');
106
+ expect(fullFolded.className).toContain('hidden');
107
+ fireEvent.click(q(iconFolded, '[data-cb-rail-fold]') as HTMLElement);
108
+ expect(changes).toEqual([true, false]);
109
+ // Without the callback nothing is offered: a shell that cannot remember the choice does not ask for it.
110
+ rerender(<AppShell nav={station}>x</AppShell>);
111
+ expect(qa(container, '[data-cb-rail-fold]')).toHaveLength(0);
112
+ });
113
+
61
114
  test('🔴 NAV-15 · with a sidebar the header is phone-only, and the brand, account and ⌘K head the sidebar (owner, 2026-10-20)', () => {
62
115
  const { container } = render(
63
116
  <AppShell
@@ -18,8 +18,10 @@ import { SideNav } from '../nav/SideNav.js';
18
18
  import { TopBarPlaces } from '../nav/TopBar.js';
19
19
  import { CommandSourceProvider, useCommandSources } from '../palette/commandSources.js';
20
20
  import { useCommandPalette } from '../palette/useCommandPalette.js';
21
+ import { IconSidebar } from '../icons.js';
21
22
  import { AmbientBackdrop, type AmbientBackdropProps } from './AmbientBackdrop.js';
22
23
  import { BannerLane, type ShellBanner } from './BannerLane.js';
24
+ import { IconButton } from './IconButton.js';
23
25
  import { lazyPart } from './DataTable/lazyPart.js';
24
26
  import { ScrollArea, type ScrollAreaSpace } from './ScrollArea.js';
25
27
 
@@ -79,6 +81,18 @@ export interface AppShellProps {
79
81
  * the section's NEXT state. */
80
82
  onNavSectionToggle?: (section: string, collapsed: boolean) => void;
81
83
 
84
+ /**
85
+ * The 240px sidebar folded to the 64px icon rail at every width — the reader's choice, to see
86
+ * the page wider (a photo archive's grid, a canvas): Linear's `⌘\` and Notion's `«` fold theirs
87
+ * the same way. Controlled: the app remembers it (a setting, `localStorage`) and passes it back.
88
+ * With `onNavCollapsedChange` the rail head carries the fold button (`IconSidebar`, a tooltip
89
+ * either way); without it the sidebar is fixed open, as before. The rail keeps its places, the
90
+ * account and the ⌘K trigger folded (NAV-2, NAV-15); a phone is never folded — it has no sidebar.
91
+ */
92
+ navCollapsed?: boolean;
93
+ /** The fold button was pressed; `collapsed` is the sidebar's NEXT state. */
94
+ onNavCollapsedChange?: (collapsed: boolean) => void;
95
+
82
96
  /** Dynamic per-place badge (unread counts), keyed by domain id. A badge may carry its own tone (`{ value, tone }`) — see {@link NavBadge}. */
83
97
  navBadges?: Record<string, NavBadge>;
84
98
  /** How those counts READ — `alert` (default, red) for "this needs you", `neutral` or
@@ -233,7 +247,7 @@ const UNSECTIONED_MAX_PLACES = 7;
233
247
  * <header h-[--header-h]> ← left: brand · center: places or ⌘K field · right: account
234
248
  * <BannerLane /> ← NAV-10, only when there is a banner
235
249
  * <div flex min-h-0 grow> ← sidebar + content row
236
- * <aside md:flex lg:hidden w-16 /> ← 6+ places: the icon rail
250
+ * <aside md:flex lg:hidden w-16 /> ← 6+ places: the icon rail (and at lg, folded by `navCollapsed`)
237
251
  * <aside lg:flex w-60 /> ← 6+ places: the sectioned SideNav
238
252
  * <main><ScrollArea>{children}</ScrollArea></main> ← THE ONLY page scroll container
239
253
  * </div>
@@ -266,6 +280,8 @@ function Shell({
266
280
  onNavPrefsChange,
267
281
  navCollapsedSections,
268
282
  onNavSectionToggle,
283
+ navCollapsed = false,
284
+ onNavCollapsedChange,
269
285
  navBadges,
270
286
  navBadgeTone,
271
287
  navHeader,
@@ -354,8 +370,31 @@ function Shell({
354
370
  * rail (md–lg) gets the account and the square ⌘K trigger; `onCapture` stays on the full sidebar
355
371
  * and the phone's PlaceBar, as a worded primary button cannot fit a 64px rail.
356
372
  */
357
- const railCommand = (collapsed: boolean) =>
358
- openCommand || (!collapsed && (onCapture || commandBarExtra)) ? (
373
+ // The fold button (`navCollapsed`): only where the app takes the choice back — a shell that cannot
374
+ // remember it does not offer it. On the icon rail it stacks under the account. On the full sidebar it
375
+ // sits at the leading edge of the ⌘K row, NOT on the brand line: the account launcher there is a
376
+ // worded control (cursedauth's "Curt Phillips ▾", 175px in a 240px rail), and a third control on
377
+ // that line left the brand no width at all (photos, WebKit, 2026-10-25). A shell with no ⌘K row
378
+ // keeps it on the brand line, where there is room.
379
+ const foldButton = (collapsed: boolean) =>
380
+ onNavCollapsedChange ? (
381
+ <IconButton
382
+ data-cb-rail-fold=''
383
+ aria-pressed={collapsed}
384
+ label={collapsed ? 'Show the sidebar' : 'Hide the sidebar'}
385
+ tooltip={collapsed ? 'Show the sidebar with its names' : 'Fold the sidebar to icons, for a wider page'}
386
+ size='sm'
387
+ variant='ghost'
388
+ className='mt-0.5'
389
+ onClick={() => onNavCollapsedChange(!collapsed)}
390
+ >
391
+ <IconSidebar />
392
+ </IconButton>
393
+ ) : null;
394
+ const hasCommandRow = (collapsed: boolean) => Boolean(openCommand || (!collapsed && (onCapture || commandBarExtra)));
395
+ const railCommand = (collapsed: boolean) => {
396
+ if (!hasCommandRow(collapsed)) return null;
397
+ const bar = (
359
398
  <CommandBar
360
399
  className={collapsed ? 'flex-col' : 'w-full min-w-0 flex-wrap'}
361
400
  compact={collapsed}
@@ -366,22 +405,36 @@ function Shell({
366
405
  commandHint={commandHint}
367
406
  extra={collapsed ? undefined : commandBarExtra}
368
407
  />
369
- ) : null;
370
- const railHead = (collapsed: boolean) => (
371
- <div data-cb-rail-head='' className={cn('flex flex-col gap-3', collapsed && 'items-center')}>
372
- {(navHeader && !collapsed) || account ? (
373
- <div className={cn('flex min-w-0 items-center gap-2', collapsed && 'flex-col')}>
374
- {navHeader && !collapsed ? <div className='flex min-w-0 flex-1 items-center overflow-hidden'>{navHeader}</div> : null}
375
- {account ? (
376
- <div data-cb-account='' className='shrink-0'>
377
- {account}
378
- </div>
379
- ) : null}
380
- </div>
381
- ) : null}
382
- {railCommand(collapsed)}
383
- </div>
384
- );
408
+ );
409
+ const fold = collapsed ? null : foldButton(false);
410
+ return fold ? (
411
+ <div data-cb-rail-command-row='' className='flex w-full min-w-0 items-start gap-1'>
412
+ {fold}
413
+ <div className='min-w-0 flex-1'>{bar}</div>
414
+ </div>
415
+ ) : (
416
+ bar
417
+ );
418
+ };
419
+ const railHead = (collapsed: boolean) => {
420
+ const foldOnBrandLine = collapsed || !hasCommandRow(collapsed);
421
+ return (
422
+ <div data-cb-rail-head='' className={cn('flex flex-col gap-3', collapsed && 'items-center')}>
423
+ {(navHeader && !collapsed) || account || (foldOnBrandLine && onNavCollapsedChange) ? (
424
+ <div className={cn('flex min-w-0 items-center gap-2', collapsed && 'flex-col')}>
425
+ {navHeader && !collapsed ? <div className='flex min-w-0 flex-1 items-center overflow-hidden'>{navHeader}</div> : null}
426
+ {account ? (
427
+ <div data-cb-account='' className='shrink-0'>
428
+ {account}
429
+ </div>
430
+ ) : null}
431
+ {foldOnBrandLine ? foldButton(collapsed) : null}
432
+ </div>
433
+ ) : null}
434
+ {railCommand(collapsed)}
435
+ </div>
436
+ );
437
+ };
385
438
 
386
439
  const sideNavProps = {
387
440
  model: nav as NavigationModel,
@@ -483,15 +536,17 @@ function Shell({
483
536
  <div className='relative flex min-h-0 grow overflow-hidden'>
484
537
  {/* 6+ places: the labeled, sectioned sidebar at lg (240px), the icon rail at md–lg
485
538
  (64px — a 240px rail on an ~820px screen squeezes the workspace, owner tablet
486
- teardown 2026-07-15 §4). Two CSS-switched renders: SideNav's `collapsed` is a
487
- prop, not a media query, and the rail is cheap to render twice. */}
539
+ teardown 2026-07-15 §4) — and at lg too while the reader has folded it (`navCollapsed`).
540
+ Two CSS-switched renders: SideNav's `collapsed` is a prop, not a media query, and the
541
+ rail is cheap to render twice. */}
488
542
  {pattern === 'side' && (
489
543
  <>
490
544
  <aside
491
545
  data-cb-nav-rail=''
492
546
  data-cb-nav-collapsed=''
493
547
  className={cn(
494
- 'hidden w-[var(--rail-w-collapsed)] border-r border-border md:flex md:shrink-0 md:flex-col lg:hidden',
548
+ 'hidden w-[var(--rail-w-collapsed)] border-r border-border md:flex md:shrink-0 md:flex-col',
549
+ !navCollapsed && 'lg:hidden',
495
550
  chrome,
496
551
  )}
497
552
  >
@@ -500,7 +555,8 @@ function Shell({
500
555
  <aside
501
556
  data-cb-nav-rail=''
502
557
  className={cn(
503
- 'hidden w-[var(--rail-w)] border-r border-border lg:flex lg:shrink-0 lg:flex-col',
558
+ 'hidden w-[var(--rail-w)] border-r border-border',
559
+ !navCollapsed && 'lg:flex lg:shrink-0 lg:flex-col',
504
560
  chrome,
505
561
  )}
506
562
  >
@@ -11,7 +11,7 @@ import {
11
11
  choiceFieldWidth,
12
12
  declareFieldWidth,
13
13
  } from '../lib/field.js';
14
- import { FLOATING_COLLISION_PADDING,
14
+ import { BASE_UI_POSITIONER, FLOATING_COLLISION_PADDING,
15
15
  FLOATING_CONTENT_BASE, FLOATING_ITEM_BASE } from '../lib/floatingStyles.js';
16
16
  import { TAP_TARGET, TAP_TARGET_HEIGHT } from '../lib/tapTarget.js';
17
17
 
@@ -336,7 +336,7 @@ export function ComboboxField(props: ComboboxFieldProps) {
336
336
  <Combobox.Positioner
337
337
  sideOffset={4}
338
338
  collisionPadding={FLOATING_COLLISION_PADDING}
339
- className='z-[var(--z-popover)]'
339
+ className={BASE_UI_POSITIONER}
340
340
  >
341
341
  <Combobox.Popup
342
342
  className={cn(
@@ -72,9 +72,9 @@ describe('control-height-tokens: cross-component parity', () => {
72
72
  expect(getByRole('button').className).toContain(TOKEN.lg);
73
73
  });
74
74
 
75
- test('DatePicker trigger honors `size`', () => {
75
+ test('DatePicker field honors `size`', () => {
76
76
  const { getByRole } = render(<DatePicker size='sm' placeholder='Pick' onChange={() => {}} />);
77
- expect(getByRole('button').className).toContain(TOKEN.sm);
77
+ expect(getByRole('textbox').className).toContain(TOKEN.sm);
78
78
  });
79
79
 
80
80
  test('ColorField container honors `size`', () => {
@@ -1,5 +1,5 @@
1
1
  import { afterEach, describe, expect, mock, test } from 'bun:test';
2
- import { cleanup, fireEvent, render } from '@testing-library/react';
2
+ import { act, cleanup, fireEvent, render, screen } from '@testing-library/react';
3
3
  import { DatePicker } from './DatePicker.js';
4
4
  import { DateRangePicker } from './DateRangePicker.js';
5
5
  import { DateTimeField } from './DateTimeField.js';
@@ -54,13 +54,194 @@ describe('DatePicker', () => {
54
54
  expect(btn).toHaveProperty('disabled', true);
55
55
  });
56
56
 
57
- test('aria-invalid and aria-describedby are forwarded to the trigger', () => {
57
+ test('aria-invalid and aria-describedby are forwarded to the text field', () => {
58
58
  const { getByRole } = render(
59
59
  <DatePicker aria-invalid={true} aria-describedby='err' onChange={() => {}} />,
60
60
  );
61
- const btn = getByRole('button');
62
- expect(btn.getAttribute('aria-invalid')).toBe('true');
63
- expect(btn.getAttribute('aria-describedby')).toBe('err');
61
+ const field = getByRole('textbox');
62
+ expect(field.getAttribute('aria-invalid')).toBe('true');
63
+ expect(field.getAttribute('aria-describedby')).toBe('err');
64
+ });
65
+ });
66
+
67
+ /** Type `text` into the field and leave it (blur commits). */
68
+ function typeAndBlur(field: HTMLElement, text: string) {
69
+ fireEvent.change(field, { target: { value: text } });
70
+ fireEvent.blur(field);
71
+ }
72
+
73
+ describe('DatePicker typing', () => {
74
+ const forms: Array<[string, string]> = [
75
+ ['2015-12-05', '2015-12-05'],
76
+ ['2015-12-5', '2015-12-05'],
77
+ ['12/5/2015', '2015-12-05'],
78
+ ['12/05/2015', '2015-12-05'],
79
+ ['12-5-2015', '2015-12-05'],
80
+ ['12.5.2015', '2015-12-05'],
81
+ ['12/05/15', '2015-12-05'],
82
+ ['12/05/99', '1999-12-05'],
83
+ ['Dec 5 2015', '2015-12-05'],
84
+ ['Dec 5, 2015', '2015-12-05'],
85
+ ['December 5, 2015', '2015-12-05'],
86
+ ['5 Dec 2015', '2015-12-05'],
87
+ ['Dec 5th, 2015', '2015-12-05'],
88
+ ['2015 Dec 5', '2015-12-05'],
89
+ [' dec 5 2015 ', '2015-12-05'],
90
+ ['2/29/2024', '2024-02-29'],
91
+ ];
92
+ for (const [typed, iso] of forms) {
93
+ test(`"${typed}" normalizes to ${iso}`, () => {
94
+ const onChange = mock((_v: string | undefined) => {});
95
+ const { getByRole } = render(<DatePicker onChange={onChange} />);
96
+ typeAndBlur(getByRole('textbox'), typed);
97
+ expect(onChange.mock.calls).toEqual([[iso]]);
98
+ expect(getByRole('textbox').getAttribute('aria-invalid')).toBeNull();
99
+ });
100
+ }
101
+
102
+ test('Enter commits like blur', () => {
103
+ const onChange = mock((_v: string | undefined) => {});
104
+ const { getByRole } = render(<DatePicker onChange={onChange} />);
105
+ const field = getByRole('textbox');
106
+ fireEvent.change(field, { target: { value: '12/5/2015' } });
107
+ fireEvent.keyDown(field, { key: 'Enter' });
108
+ expect(onChange.mock.calls).toEqual([['2015-12-05']]);
109
+ });
110
+
111
+ test('a committed value shows in the display format', () => {
112
+ const { getByRole, rerender } = render(<DatePicker value='2015-12-05' onChange={() => {}} />);
113
+ expect((getByRole('textbox') as HTMLInputElement).value).toContain('2015');
114
+ rerender(<DatePicker value='2024-03-15' onChange={() => {}} />);
115
+ expect((getByRole('textbox') as HTMLInputElement).value).toContain('2024');
116
+ });
117
+
118
+ const garbage = ['hello', '13/45/2015', '2/30/2015', '12/5', 'Dec 2015', '12/5/215', 'Foo 5 2015', '0000-00-00'];
119
+ for (const text of garbage) {
120
+ test(`garbage "${text}" never reaches onChange and shows a reason`, () => {
121
+ const onChange = mock((_v: string | undefined) => {});
122
+ const { getByRole } = render(<DatePicker value='2020-01-01' onChange={onChange} />);
123
+ const field = getByRole('textbox');
124
+ typeAndBlur(field, text);
125
+ expect(onChange.mock.calls).toEqual([]);
126
+ expect(field.getAttribute('aria-invalid')).toBe('true');
127
+ expect(getByRole('alert').textContent?.length).toBeGreaterThan(0);
128
+ expect(field.getAttribute('aria-describedby')).toBe(getByRole('alert').id);
129
+ });
130
+ }
131
+
132
+ test('Escape on invalid text restores the last good value', () => {
133
+ const onChange = mock((_v: string | undefined) => {});
134
+ const { getByRole, queryByRole } = render(<DatePicker value='2020-01-01' onChange={onChange} />);
135
+ const field = getByRole('textbox') as HTMLInputElement;
136
+ const before = field.value;
137
+ typeAndBlur(field, 'nonsense');
138
+ fireEvent.keyDown(field, { key: 'Escape' });
139
+ expect(field.value).toBe(before);
140
+ expect(field.getAttribute('aria-invalid')).toBeNull();
141
+ expect(queryByRole('alert')).toBeNull();
142
+ expect(onChange.mock.calls).toEqual([]);
143
+ });
144
+
145
+ test('a date before min or after max is refused, and says which bound', () => {
146
+ const onChange = mock((_v: string | undefined) => {});
147
+ const { getByRole } = render(
148
+ <DatePicker min='2010-01-01' max='2020-12-31' onChange={onChange} />,
149
+ );
150
+ const field = getByRole('textbox');
151
+ typeAndBlur(field, '12/31/2009');
152
+ expect(getByRole('alert').textContent).toContain('on or after');
153
+ typeAndBlur(field, '1/1/2021');
154
+ expect(getByRole('alert').textContent).toContain('on or before');
155
+ expect(onChange.mock.calls).toEqual([]);
156
+ typeAndBlur(field, '1/1/2020');
157
+ expect(onChange.mock.calls).toEqual([['2020-01-01']]);
158
+ });
159
+
160
+ test('clearing the text clears the value', () => {
161
+ const onChange = mock((_v: string | undefined) => {});
162
+ const { getByRole } = render(<DatePicker value='2020-01-01' onChange={onChange} />);
163
+ typeAndBlur(getByRole('textbox'), '');
164
+ expect(onChange.mock.calls).toEqual([[undefined]]);
165
+ });
166
+
167
+ test('the calendar opens on a typed date', () => {
168
+ const { getByRole, container } = render(<DatePicker value='2024-03-01' onChange={() => {}} />);
169
+ typeAndBlur(getByRole('textbox'), 'Jul 4 1985');
170
+ fireEvent.click(container.querySelector('button[aria-haspopup="dialog"]') as HTMLElement);
171
+ expect(screen.getByRole('button', { name: /July 1985, choose month and year/ })).not.toBeNull();
172
+ });
173
+ });
174
+
175
+ describe('DatePicker calendar navigation', () => {
176
+ function open(value = '2024-03-15', props: Partial<React.ComponentProps<typeof DatePicker>> = {}) {
177
+ const utils = render(<DatePicker value={value} onChange={() => {}} {...props} />);
178
+ fireEvent.click(utils.container.querySelector('button[aria-haspopup="dialog"]') as HTMLElement);
179
+ return utils;
180
+ }
181
+ const caption = (re: RegExp) => screen.getByRole('button', { name: re });
182
+
183
+ test('Next/Previous year buttons move a year', () => {
184
+ open();
185
+ fireEvent.click(screen.getByRole('button', { name: 'Previous year' }));
186
+ expect(caption(/March 2023/)).not.toBeNull();
187
+ fireEvent.click(screen.getByRole('button', { name: 'Next year' }));
188
+ fireEvent.click(screen.getByRole('button', { name: 'Next year' }));
189
+ expect(caption(/March 2025/)).not.toBeNull();
190
+ });
191
+
192
+ test('month buttons still move a month', () => {
193
+ open();
194
+ fireEvent.click(screen.getByRole('button', { name: 'Next month' }));
195
+ expect(caption(/April 2024/)).not.toBeNull();
196
+ });
197
+
198
+ test('a year step clamps to the min month, and is disabled once there', () => {
199
+ open('2024-03-15', { min: '2024-01-10', max: '2024-06-20' });
200
+ fireEvent.click(screen.getByRole('button', { name: 'Previous year' }));
201
+ expect(caption(/January 2024/)).not.toBeNull();
202
+ expect((screen.getByRole('button', { name: 'Previous year' }) as HTMLButtonElement).disabled).toBe(true);
203
+ fireEvent.click(screen.getByRole('button', { name: 'Next year' }));
204
+ expect(caption(/June 2024/)).not.toBeNull();
205
+ expect((screen.getByRole('button', { name: 'Next year' }) as HTMLButtonElement).disabled).toBe(true);
206
+ });
207
+
208
+ test('year buttons are disabled when min and max pin the month', () => {
209
+ open('2024-03-15', { min: '2024-03-01', max: '2024-03-31' });
210
+ expect((screen.getByRole('button', { name: 'Previous year' }) as HTMLButtonElement).disabled).toBe(true);
211
+ expect((screen.getByRole('button', { name: 'Next year' }) as HTMLButtonElement).disabled).toBe(true);
212
+ });
213
+
214
+ test('Shift+PageUp moves a year, PageUp a month (and the Shift forms go forward)', () => {
215
+ open();
216
+ const press = (name: RegExp, key: string, shiftKey = false) => {
217
+ const day = screen.getByRole('button', { name });
218
+ act(() => day.focus());
219
+ fireEvent.keyDown(day, { key, shiftKey });
220
+ };
221
+ press(/March 15th, 2024/, 'PageUp', true);
222
+ expect(caption(/March 2023/)).not.toBeNull();
223
+ press(/March 15th, 2023/, 'PageUp');
224
+ expect(caption(/February 2023/)).not.toBeNull();
225
+ press(/February 15th, 2023/, 'PageDown', true);
226
+ expect(caption(/February 2024/)).not.toBeNull();
227
+ });
228
+
229
+ test('the caption opens a year grid, then months: 2024 to 1985 in two picks', () => {
230
+ open();
231
+ fireEvent.click(caption(/March 2024, choose month and year/));
232
+ fireEvent.click(screen.getByRole('button', { name: '1985' }));
233
+ fireEvent.click(screen.getByRole('button', { name: /July 1985/ }));
234
+ expect(caption(/July 1985/)).not.toBeNull();
235
+ });
236
+
237
+ test('the month chooser disables months outside min/max', () => {
238
+ open('2024-03-15', { min: '2023-05-01', max: '2024-08-31' });
239
+ fireEvent.click(caption(/March 2024, choose month and year/));
240
+ expect(screen.queryByRole('button', { name: '2022' })).toBeNull();
241
+ fireEvent.click(screen.getByRole('button', { name: '2023' }));
242
+ const month = (re: RegExp) => screen.getByRole('button', { name: re }) as HTMLButtonElement;
243
+ expect(month(/April 2023/).disabled).toBe(true);
244
+ expect(month(/May 2023/).disabled).toBe(false);
64
245
  });
65
246
  });
66
247