@dashforge/tw 0.2.1-beta → 0.4.0-beta

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 (86) hide show
  1. package/CHANGELOG.md +257 -0
  2. package/CONSUMER-VALIDATION.md +130 -0
  3. package/PARITY.md +483 -0
  4. package/PERFORMANCE.md +169 -0
  5. package/dist/index.esm.js +801 -42
  6. package/dist/src/components/Accordion/Accordion.d.ts +21 -0
  7. package/dist/src/components/Accordion/Accordion.d.ts.map +1 -0
  8. package/dist/src/components/Accordion/accordion.types.d.ts +74 -0
  9. package/dist/src/components/Accordion/accordion.types.d.ts.map +1 -0
  10. package/dist/src/components/Accordion/accordion.variants.d.ts +58 -0
  11. package/dist/src/components/Accordion/accordion.variants.d.ts.map +1 -0
  12. package/dist/src/components/AppShell/AppShell.d.ts +14 -0
  13. package/dist/src/components/AppShell/AppShell.d.ts.map +1 -1
  14. package/dist/src/components/AppShell/appShell.variants.d.ts.map +1 -1
  15. package/dist/src/components/Autocomplete/Autocomplete.d.ts.map +1 -1
  16. package/dist/src/components/Autocomplete/autocomplete.variants.d.ts.map +1 -1
  17. package/dist/src/components/Breadcrumbs/breadcrumbs.variants.d.ts.map +1 -1
  18. package/dist/src/components/Checkbox/Checkbox.d.ts.map +1 -1
  19. package/dist/src/components/Dialog/Dialog.d.ts +17 -0
  20. package/dist/src/components/Dialog/Dialog.d.ts.map +1 -0
  21. package/dist/src/components/Dialog/dialog.types.d.ts +75 -0
  22. package/dist/src/components/Dialog/dialog.types.d.ts.map +1 -0
  23. package/dist/src/components/Dialog/dialog.variants.d.ts +80 -0
  24. package/dist/src/components/Dialog/dialog.variants.d.ts.map +1 -0
  25. package/dist/src/components/LeftNav/leftNav.variants.d.ts.map +1 -1
  26. package/dist/src/components/Popover/Popover.d.ts +15 -0
  27. package/dist/src/components/Popover/Popover.d.ts.map +1 -0
  28. package/dist/src/components/Popover/popover.types.d.ts +45 -0
  29. package/dist/src/components/Popover/popover.types.d.ts.map +1 -0
  30. package/dist/src/components/Popover/popover.variants.d.ts +34 -0
  31. package/dist/src/components/Popover/popover.variants.d.ts.map +1 -0
  32. package/dist/src/components/Snackbar/snackbar.variants.d.ts.map +1 -1
  33. package/dist/src/components/Switch/switch.variants.d.ts.map +1 -1
  34. package/dist/src/components/Tabs/Tabs.d.ts +15 -0
  35. package/dist/src/components/Tabs/Tabs.d.ts.map +1 -0
  36. package/dist/src/components/Tabs/tabs.types.d.ts +55 -0
  37. package/dist/src/components/Tabs/tabs.types.d.ts.map +1 -0
  38. package/dist/src/components/Tabs/tabs.variants.d.ts +82 -0
  39. package/dist/src/components/Tabs/tabs.variants.d.ts.map +1 -0
  40. package/dist/src/components/TextField/TextField.d.ts.map +1 -1
  41. package/dist/src/components/TextField/textField.types.d.ts +29 -3
  42. package/dist/src/components/TextField/textField.types.d.ts.map +1 -1
  43. package/dist/src/components/TextField/textField.variants.d.ts +6 -0
  44. package/dist/src/components/TextField/textField.variants.d.ts.map +1 -1
  45. package/dist/src/components/Tooltip/Tooltip.d.ts +29 -0
  46. package/dist/src/components/Tooltip/Tooltip.d.ts.map +1 -0
  47. package/dist/src/components/Tooltip/tooltip.types.d.ts +47 -0
  48. package/dist/src/components/Tooltip/tooltip.types.d.ts.map +1 -0
  49. package/dist/src/components/Tooltip/tooltip.variants.d.ts +34 -0
  50. package/dist/src/components/Tooltip/tooltip.variants.d.ts.map +1 -0
  51. package/dist/src/index.d.ts +16 -1
  52. package/dist/src/index.d.ts.map +1 -1
  53. package/package.json +6 -1
  54. package/src/components/Accordion/Accordion.test.tsx +95 -0
  55. package/src/components/Accordion/Accordion.tsx +97 -0
  56. package/src/components/Accordion/accordion.types.ts +66 -0
  57. package/src/components/Accordion/accordion.variants.ts +30 -0
  58. package/src/components/AppShell/AppShell.tsx +126 -1
  59. package/src/components/AppShell/appShell.variants.ts +8 -2
  60. package/src/components/Autocomplete/Autocomplete.tsx +77 -4
  61. package/src/components/Autocomplete/autocomplete.variants.ts +6 -0
  62. package/src/components/Breadcrumbs/breadcrumbs.variants.ts +5 -0
  63. package/src/components/Checkbox/Checkbox.tsx +43 -9
  64. package/src/components/Dialog/Dialog.test.tsx +96 -0
  65. package/src/components/Dialog/Dialog.tsx +93 -0
  66. package/src/components/Dialog/dialog.types.ts +62 -0
  67. package/src/components/Dialog/dialog.variants.ts +62 -0
  68. package/src/components/LeftNav/leftNav.variants.ts +12 -1
  69. package/src/components/Popover/Popover.test.tsx +72 -0
  70. package/src/components/Popover/Popover.tsx +55 -0
  71. package/src/components/Popover/popover.types.ts +42 -0
  72. package/src/components/Popover/popover.variants.ts +18 -0
  73. package/src/components/Snackbar/snackbar.variants.ts +4 -2
  74. package/src/components/Switch/switch.variants.ts +6 -1
  75. package/src/components/Tabs/Tabs.test.tsx +74 -0
  76. package/src/components/Tabs/Tabs.tsx +66 -0
  77. package/src/components/Tabs/tabs.types.ts +49 -0
  78. package/src/components/Tabs/tabs.variants.ts +58 -0
  79. package/src/components/TextField/TextField.tsx +29 -0
  80. package/src/components/TextField/textField.types.ts +23 -3
  81. package/src/components/TextField/textField.variants.ts +18 -0
  82. package/src/components/Tooltip/Tooltip.test.tsx +73 -0
  83. package/src/components/Tooltip/Tooltip.tsx +70 -0
  84. package/src/components/Tooltip/tooltip.types.ts +44 -0
  85. package/src/components/Tooltip/tooltip.variants.ts +18 -0
  86. package/src/index.ts +40 -1
@@ -0,0 +1,30 @@
1
+ import { tv, type VariantProps } from 'tailwind-variants';
2
+
3
+ export const accordionVariants = tv({
4
+ slots: {
5
+ root: 'w-full',
6
+ item: 'border-b border-neutral-200 dark:border-neutral-800',
7
+ header: 'flex',
8
+ trigger: [
9
+ 'flex flex-1 items-center justify-between py-3 text-left',
10
+ 'text-sm font-medium text-neutral-900 dark:text-neutral-50',
11
+ 'transition-all hover:underline',
12
+ 'focus:outline-none focus-visible:ring-2 focus-visible:ring-primary-500 focus-visible:rounded',
13
+ '[&[data-state=open]>svg]:rotate-180',
14
+ 'disabled:opacity-50 disabled:pointer-events-none',
15
+ 'motion-reduce:transition-none',
16
+ ],
17
+ content: [
18
+ 'overflow-hidden text-sm text-neutral-700 dark:text-neutral-300',
19
+ 'data-[state=open]:animate-accordion-down',
20
+ 'data-[state=closed]:animate-accordion-up',
21
+ 'motion-reduce:animate-none',
22
+ ],
23
+ chevron: [
24
+ 'h-4 w-4 shrink-0 text-neutral-500 transition-transform duration-200',
25
+ 'motion-reduce:transition-none motion-reduce:duration-0',
26
+ ],
27
+ },
28
+ });
29
+
30
+ export type AccordionVariants = VariantProps<typeof accordionVariants>;
@@ -1,8 +1,32 @@
1
- import { useEffect } from 'react';
1
+ import { useEffect, useRef } from 'react';
2
2
  import { cn } from '../../utils/cn.js';
3
3
  import { appShellVariants } from './appShell.variants.js';
4
4
  import type { AppShellProps } from './appShell.types.js';
5
5
 
6
+ /**
7
+ * Query selector for natively-focusable elements + anything with an
8
+ * explicit positive (or implicit `0`) tabindex. Used by the focus
9
+ * trap to enumerate the drawer's interactive content.
10
+ *
11
+ * Notes:
12
+ * - Excludes `[tabindex="-1"]` (intentionally non-tabbable).
13
+ * - Excludes `:disabled` — the browser already skips them in tab
14
+ * order; including them here would route focus to dead elements.
15
+ * - `details > summary` is the standard way to get a focusable
16
+ * `<details>` toggle.
17
+ *
18
+ * @internal
19
+ */
20
+ const FOCUSABLE_SELECTOR = [
21
+ 'a[href]',
22
+ 'button:not(:disabled)',
23
+ 'input:not(:disabled):not([type="hidden"])',
24
+ 'select:not(:disabled)',
25
+ 'textarea:not(:disabled)',
26
+ '[tabindex]:not([tabindex="-1"]):not(:disabled)',
27
+ 'details > summary:first-of-type',
28
+ ].join(',');
29
+
6
30
  /**
7
31
  * Dashforge TW AppShell — top-level layout orchestrator.
8
32
  *
@@ -31,6 +55,20 @@ import type { AppShellProps } from './appShell.types.js';
31
55
  * - The mobile drawer + backdrop participate in the standard
32
56
  * "click outside to close" pattern — `Escape` closes the drawer
33
57
  * too (added via global keydown).
58
+ * - **Focus trap** (WCAG 2.4.3) — when the mobile drawer opens:
59
+ * 1. The previously-focused element is captured.
60
+ * 2. Focus moves to the first focusable element inside the drawer.
61
+ * 3. Tab / Shift+Tab wrap inside the drawer (cycle from
62
+ * last → first and first → last) — Tab can never escape
63
+ * to the page underneath while the drawer is open.
64
+ * 4. On close, focus returns to the captured element (typically
65
+ * the hamburger toggle the user pressed to open the drawer).
66
+ * This pattern matches WAI-ARIA APG's modal dialog guidance even
67
+ * though the drawer isn't strictly a dialog — same focus
68
+ * management makes keyboard users' experience predictable.
69
+ * - **`role="dialog"` + `aria-modal="true"`** are applied to the
70
+ * drawer when open so screen readers announce it as a modal
71
+ * overlay rather than just an aside.
34
72
  */
35
73
  export function AppShell(props: AppShellProps) {
36
74
  const {
@@ -66,6 +104,86 @@ export function AppShell(props: AppShellProps) {
66
104
  return () => document.removeEventListener('keydown', handler);
67
105
  }, [navOpen, onNavOpenChange]);
68
106
 
107
+ /*
108
+ * Focus trap for the mobile drawer.
109
+ *
110
+ * Implementation:
111
+ * - On open: capture the currently-focused element (`document.activeElement`)
112
+ * so we can restore it on close. Then move focus to the first
113
+ * focusable element inside the drawer.
114
+ * - While open: a Tab/Shift+Tab keydown listener wraps focus inside
115
+ * the drawer subtree (last → first on Tab from end, first → last
116
+ * on Shift+Tab from start).
117
+ * - On close: restore focus to the captured element.
118
+ *
119
+ * Hand-rolled (no `focus-trap-react` dep) — the logic is ~20 LOC and
120
+ * scoped to a single drawer; adding a runtime dep felt like overkill.
121
+ * If we ever need more sophisticated trap semantics (nested traps,
122
+ * sentinel nodes, etc.) the dep is the right call.
123
+ */
124
+ const drawerRef = useRef<HTMLDivElement | null>(null);
125
+ const restoreFocusRef = useRef<HTMLElement | null>(null);
126
+
127
+ useEffect(() => {
128
+ if (!navOpen) return;
129
+ // 1) Capture the element that had focus before the drawer opened.
130
+ restoreFocusRef.current = document.activeElement as HTMLElement | null;
131
+
132
+ // 2) Move focus to the first focusable element inside the drawer.
133
+ // Defer via rAF so the drawer DOM (slide-in animation start) has
134
+ // settled and the elements are actually visible/focusable.
135
+ const raf = requestAnimationFrame(() => {
136
+ const drawer = drawerRef.current;
137
+ if (!drawer) return;
138
+ const first = drawer.querySelector<HTMLElement>(FOCUSABLE_SELECTOR);
139
+ first?.focus();
140
+ });
141
+
142
+ // 3) Trap Tab / Shift+Tab inside the drawer.
143
+ const onKeyDown = (event: KeyboardEvent) => {
144
+ if (event.key !== 'Tab') return;
145
+ const drawer = drawerRef.current;
146
+ if (!drawer) return;
147
+ const focusables = Array.from(
148
+ drawer.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR)
149
+ );
150
+ if (focusables.length === 0) {
151
+ event.preventDefault();
152
+ return;
153
+ }
154
+ const first = focusables[0];
155
+ const last = focusables[focusables.length - 1];
156
+ const active = document.activeElement as HTMLElement | null;
157
+ if (event.shiftKey) {
158
+ // Shift+Tab on first → wrap to last.
159
+ if (active === first || !drawer.contains(active)) {
160
+ event.preventDefault();
161
+ last.focus();
162
+ }
163
+ } else {
164
+ // Tab on last → wrap to first.
165
+ if (active === last || !drawer.contains(active)) {
166
+ event.preventDefault();
167
+ first.focus();
168
+ }
169
+ }
170
+ };
171
+ document.addEventListener('keydown', onKeyDown);
172
+
173
+ return () => {
174
+ cancelAnimationFrame(raf);
175
+ document.removeEventListener('keydown', onKeyDown);
176
+ // 4) Restore focus to the previously-focused element on close.
177
+ // Guard against the element being removed from the DOM (rare
178
+ // but possible if the consumer re-renders the page while the
179
+ // drawer is open).
180
+ const restore = restoreFocusRef.current;
181
+ if (restore && document.body.contains(restore)) {
182
+ restore.focus();
183
+ }
184
+ };
185
+ }, [navOpen]);
186
+
69
187
  return (
70
188
  <div className={cn(v.root(), sx, slotProps?.root?.className)}>
71
189
  {header && (
@@ -81,8 +199,15 @@ export function AppShell(props: AppShellProps) {
81
199
  {nav}
82
200
  </aside>
83
201
  <aside
202
+ ref={drawerRef}
84
203
  className={cn(v.navMobile(), slotProps?.navMobile?.className)}
85
204
  aria-hidden={!navOpen}
205
+ // When open, the drawer is a modal overlay — `dialog` +
206
+ // `aria-modal="true"` so screen readers announce it as
207
+ // such. When closed, drop both attributes (the aria-
208
+ // hidden=true above already removes it from the AT tree).
209
+ role={navOpen ? 'dialog' : undefined}
210
+ aria-modal={navOpen ? true : undefined}
86
211
  // The drawer is the SAME nav content rendered twice — once
87
212
  // inline (desktop) and once as a slide-in (mobile). We
88
213
  // mark the inactive copy hidden from AT to avoid double
@@ -21,14 +21,20 @@ export const appShellVariants = tv({
21
21
  nav: 'hidden md:flex shrink-0',
22
22
  navMobile: [
23
23
  'flex md:hidden fixed inset-y-0 left-0 z-40',
24
- 'transition-transform duration-200 ease-out',
24
+ // Drawer slide-in is the most prominent motion in AppShell and
25
+ // a clear WCAG 2.3.3 candidate. Gate the transition on
26
+ // `prefers-reduced-motion: no-preference`; the data-driven
27
+ // `-translate-x-full` / `translate-x-0` still applies, just
28
+ // without the smooth slide.
29
+ 'transition-transform duration-200 ease-out motion-reduce:transition-none motion-reduce:duration-0',
25
30
  '-translate-x-full',
26
31
  ],
27
32
  main: 'flex-1 min-w-0 overflow-y-auto',
28
33
  footer: 'shrink-0',
29
34
  backdrop: [
30
35
  'md:hidden fixed inset-0 z-30 bg-black/40',
31
- 'transition-opacity duration-200',
36
+ // Backdrop opacity fade — micro motion, gated for consistency.
37
+ 'transition-opacity duration-200 motion-reduce:transition-none motion-reduce:duration-0',
32
38
  'opacity-0 pointer-events-none',
33
39
  ],
34
40
  },
@@ -23,6 +23,61 @@ import type {
23
23
  AutocompleteValue,
24
24
  } from './autocomplete.types.js';
25
25
 
26
+ /**
27
+ * Inline SVG icons used by the Autocomplete chrome (chip remove, clear,
28
+ * dropdown caret). Stroke uses `currentColor` so the parent's `text-*`
29
+ * propagates — same pattern as Checkbox's CheckIcon.
30
+ *
31
+ * Why inline SVG (not lucide / heroicons / unicode glyphs):
32
+ * - Zero icon-library dependency: keeps `@dashforge/tw` self-contained.
33
+ * - Crisp at every size (the unicode `×` / `▾` glyphs we shipped pre-
34
+ * 0.2.2 rendered as chunky font characters that looked unpolished
35
+ * next to the rest of the design system).
36
+ * - SVG scales with parent font-size cleanly via `width="1em" height="1em"`.
37
+ *
38
+ * @internal
39
+ */
40
+ function CloseIcon({ className }: { className?: string }) {
41
+ return (
42
+ <svg
43
+ aria-hidden="true"
44
+ viewBox="0 0 16 16"
45
+ width="1em"
46
+ height="1em"
47
+ fill="none"
48
+ className={className}
49
+ >
50
+ <path
51
+ d="M4 4l8 8M12 4l-8 8"
52
+ stroke="currentColor"
53
+ strokeWidth="1.75"
54
+ strokeLinecap="round"
55
+ />
56
+ </svg>
57
+ );
58
+ }
59
+
60
+ function ChevronDownIcon({ className }: { className?: string }) {
61
+ return (
62
+ <svg
63
+ aria-hidden="true"
64
+ viewBox="0 0 16 16"
65
+ width="1em"
66
+ height="1em"
67
+ fill="none"
68
+ className={className}
69
+ >
70
+ <path
71
+ d="M4 6l4 4 4-4"
72
+ stroke="currentColor"
73
+ strokeWidth="1.75"
74
+ strokeLinecap="round"
75
+ strokeLinejoin="round"
76
+ />
77
+ </svg>
78
+ );
79
+ }
80
+
26
81
  /**
27
82
  * Coerce a raw value (from bridge / props) into a canonical shape:
28
83
  *
@@ -402,7 +457,17 @@ export function Autocomplete<TOption = AutocompleteOption>(
402
457
  if (next == null) {
403
458
  setInputValue('');
404
459
  } else {
405
- const found = options.find((opt) => getOptionValue(opt) === next);
460
+ // Look up the label in the EFFECTIVE option pool (static
461
+ // `options` + async `asyncOptions` when `loadOptions` is
462
+ // configured). Looking only at the static `options` here
463
+ // means async-loaded picks never update the input — the
464
+ // user sees their search query stick instead of the
465
+ // selected label after click. Same lookup logic mirrored in
466
+ // `displayInputValue` so the two paths can't drift.
467
+ const pool = loadOptions && asyncOptions !== null
468
+ ? asyncOptions
469
+ : options;
470
+ const found = pool.find((opt) => getOptionValue(opt) === next);
406
471
  const found_label = found ? labelAsString(found) : undefined;
407
472
  if (found_label !== undefined) {
408
473
  setInputValue(found_label);
@@ -434,6 +499,8 @@ export function Autocomplete<TOption = AutocompleteOption>(
434
499
  // eslint-disable-next-line react-hooks/exhaustive-deps
435
500
  [
436
501
  options,
502
+ asyncOptions,
503
+ loadOptions,
437
504
  isFormMode,
438
505
  bridge,
439
506
  name,
@@ -837,7 +904,7 @@ export function Autocomplete<TOption = AutocompleteOption>(
837
904
  slotProps?.chipRemove?.className
838
905
  )}
839
906
  >
840
- ×
907
+ <CloseIcon />
841
908
  </button>
842
909
  )}
843
910
  </span>
@@ -893,7 +960,7 @@ export function Autocomplete<TOption = AutocompleteOption>(
893
960
  tabIndex={-1}
894
961
  className={cn(v.clearButton(), slotProps?.clearButton?.className)}
895
962
  >
896
- ×
963
+ <CloseIcon />
897
964
  </button>
898
965
  )}
899
966
 
@@ -908,7 +975,13 @@ export function Autocomplete<TOption = AutocompleteOption>(
908
975
  disabled={effectiveDisabled}
909
976
  className={cn(v.trigger(), slotProps?.trigger?.className)}
910
977
  >
911
- ▾
978
+ {/*
979
+ * Chevron flips up when popover is open (CSS-only, driven by
980
+ * the `aria-expanded` attribute selector on the parent
981
+ * `<button>`). See autocomplete.variants.ts → `trigger` slot
982
+ * for the `aria-expanded:rotate-180` rule.
983
+ */}
984
+ <ChevronDownIcon />
912
985
  </button>
913
986
 
914
987
  {isOpen && (
@@ -44,6 +44,12 @@ export const autocompleteVariants = tv({
44
44
  'text-neutral-600 hover:text-neutral-900',
45
45
  'disabled:cursor-not-allowed disabled:opacity-40',
46
46
  'transition-colors',
47
+ // Chevron flip on open — targets the SVG child via the aria-
48
+ // expanded state on the button itself (set by React). Smooth
49
+ // rotate gated on prefers-reduced-motion (WCAG 2.3.3); the
50
+ // 180° state still applies, just without the animated tween.
51
+ '[&[aria-expanded=true]>svg]:rotate-180',
52
+ '[&>svg]:transition-transform [&>svg]:duration-150 motion-reduce:[&>svg]:transition-none',
47
53
  ],
48
54
  clearButton: [
49
55
  'flex items-center justify-center shrink-0 px-2',
@@ -23,6 +23,11 @@ export const breadcrumbsVariants = tv({
23
23
  'rounded-sm outline-none',
24
24
  'focus-visible:ring-2 focus-visible:ring-primary-500/50',
25
25
  'transition-colors',
26
+ // Defensive `no-underline` — see the matching comment in
27
+ // LeftNav itemLink slot. The Breadcrumbs root cause covers
28
+ // TopBar too because Breadcrumbs is typically rendered in
29
+ // TopBar's center slot.
30
+ 'no-underline hover:no-underline',
26
31
  ],
27
32
  current: [
28
33
  'inline-flex items-center gap-1 truncate',
@@ -10,8 +10,8 @@ import { checkboxVariants } from './checkbox.variants.js';
10
10
  import type { CheckboxProps } from './checkbox.types.js';
11
11
 
12
12
  /**
13
- * Inline checkmark SVG used by `Radix.Indicator`. Stroke uses
14
- * `currentColor` so the parent's `text-white` propagates correctly.
13
+ * Inline checkmark SVG used by `Radix.Indicator` when fully checked.
14
+ * Stroke uses `currentColor` so the parent's `text-white` propagates.
15
15
  *
16
16
  * @internal
17
17
  */
@@ -34,6 +34,37 @@ function CheckIcon({ className }: { className?: string }) {
34
34
  );
35
35
  }
36
36
 
37
+ /**
38
+ * Inline dash SVG used by `Radix.Indicator` when the checkbox is in
39
+ * the `indeterminate` tri-state ("some, but not all, children
40
+ * selected" — the canonical "select all" partial state).
41
+ *
42
+ * Pre-0.2.2-beta the indicator rendered the CheckIcon for BOTH
43
+ * checked and indeterminate (Radix mounts the Indicator for either
44
+ * state). We now discriminate via the `data-state` attribute Radix
45
+ * sets on the Indicator element itself — see the parent `Indicator`
46
+ * rendering below for the CSS toggle.
47
+ *
48
+ * @internal
49
+ */
50
+ function DashIcon({ className }: { className?: string }) {
51
+ return (
52
+ <svg
53
+ aria-hidden="true"
54
+ viewBox="0 0 16 16"
55
+ fill="none"
56
+ className={className}
57
+ >
58
+ <path
59
+ d="M3 8h10"
60
+ stroke="currentColor"
61
+ strokeWidth="2.5"
62
+ strokeLinecap="round"
63
+ />
64
+ </svg>
65
+ );
66
+ }
67
+
37
68
  /**
38
69
  * Dashforge TW Checkbox — bridge-integrated form control.
39
70
  *
@@ -212,16 +243,19 @@ export function Checkbox(props: CheckboxProps) {
212
243
  * modes — controlled, uncontrolled, bridge). Indicator mounts
213
244
  * exactly when the checkbox is checked OR indeterminate.
214
245
  *
215
- * Indeterminate caveat: this renders the check glyph for
216
- * BOTH checked AND indeterminate states. Previously
217
- * indeterminate rendered nothing inside the blue square
218
- * (same level of broken). A future improvement would render
219
- * a dash for indeterminate — out of scope here.
246
+ * Per-state glyph (Sprint 2 P4): when Indicator is mounted we
247
+ * render BOTH glyphs and toggle visibility via the Indicator's
248
+ * own `data-state` attribute. The `group` class on Indicator
249
+ * lets the SVG children target the parent's state with
250
+ * `group-data-[state=checked]:hidden` / `…:indeterminate:hidden`.
251
+ * No React state required — Radix's data-state attribute is
252
+ * the single source of truth.
220
253
  */}
221
254
  <RadixCheckbox.Indicator
222
- className={cn(v.indicator(), slotProps?.indicator?.className)}
255
+ className={cn(v.indicator(), 'group', slotProps?.indicator?.className)}
223
256
  >
224
- <CheckIcon className="h-full w-full" />
257
+ <CheckIcon className="h-full w-full group-data-[state=indeterminate]:hidden" />
258
+ <DashIcon className="h-full w-full group-data-[state=checked]:hidden" />
225
259
  </RadixCheckbox.Indicator>
226
260
  </RadixCheckbox.Root>
227
261
 
@@ -0,0 +1,96 @@
1
+ // @vitest-environment jsdom
2
+ import * as React from 'react';
3
+ import { describe, it, expect, afterEach } from 'vitest';
4
+ import { render, screen, fireEvent, cleanup } from '@testing-library/react';
5
+ import { Dialog } from './Dialog.js';
6
+
7
+ void React;
8
+ afterEach(() => cleanup());
9
+
10
+ describe('Dialog — rendering', () => {
11
+ it('renders nothing when open=false', () => {
12
+ render(
13
+ <Dialog open={false} onOpenChange={() => {}}>
14
+ <p>body</p>
15
+ </Dialog>
16
+ );
17
+ expect(screen.queryByText('body')).toBeNull();
18
+ });
19
+
20
+ it('renders title + body + close button when open', () => {
21
+ render(
22
+ <Dialog open onOpenChange={() => {}} title="Confirm action">
23
+ <p>body content</p>
24
+ </Dialog>
25
+ );
26
+ expect(screen.queryByText('Confirm action')).not.toBeNull();
27
+ expect(screen.queryByText('body content')).not.toBeNull();
28
+ expect(screen.queryByLabelText('Close')).not.toBeNull();
29
+ });
30
+
31
+ it('honors showCloseButton={false}', () => {
32
+ render(
33
+ <Dialog open onOpenChange={() => {}} showCloseButton={false}>
34
+ <p>body</p>
35
+ </Dialog>
36
+ );
37
+ expect(screen.queryByLabelText('Close')).toBeNull();
38
+ });
39
+
40
+ it('emits onOpenChange(false) when close button is clicked', () => {
41
+ let lastOpen: boolean | null = null;
42
+ render(
43
+ <Dialog open onOpenChange={(o) => (lastOpen = o)}>
44
+ <p>body</p>
45
+ </Dialog>
46
+ );
47
+ fireEvent.click(screen.getByLabelText('Close'));
48
+ expect(lastOpen).toBe(false);
49
+ });
50
+
51
+ it('renders description when provided', () => {
52
+ render(
53
+ <Dialog open onOpenChange={() => {}} title="Title" description="Hint text">
54
+ <p>body</p>
55
+ </Dialog>
56
+ );
57
+ expect(screen.queryByText('Hint text')).not.toBeNull();
58
+ });
59
+ });
60
+
61
+ describe('Dialog — size variants', () => {
62
+ it.each(['sm', 'md', 'lg'] as const)('renders size=%s without crashing', (size) => {
63
+ render(
64
+ <Dialog open onOpenChange={() => {}} size={size}>
65
+ <p>body</p>
66
+ </Dialog>
67
+ );
68
+ expect(screen.queryByText('body')).not.toBeNull();
69
+ });
70
+ });
71
+
72
+ describe('Dialog — sx + slotProps', () => {
73
+ it('appends sx to the content element', () => {
74
+ render(
75
+ <Dialog open onOpenChange={() => {}} sx="custom-sx-class">
76
+ <p>body</p>
77
+ </Dialog>
78
+ );
79
+ const content = screen.getByText('body').closest('[role="dialog"]');
80
+ expect(content?.className).toContain('custom-sx-class');
81
+ });
82
+
83
+ it('applies slotProps.title.className', () => {
84
+ render(
85
+ <Dialog
86
+ open
87
+ onOpenChange={() => {}}
88
+ title="T"
89
+ slotProps={{ title: { className: 'tw-title-override' } }}
90
+ >
91
+ <p>body</p>
92
+ </Dialog>
93
+ );
94
+ expect(screen.getByText('T').className).toContain('tw-title-override');
95
+ });
96
+ });
@@ -0,0 +1,93 @@
1
+ import * as RadixDialog from '@radix-ui/react-dialog';
2
+ import { cn } from '../../utils/cn.js';
3
+ import { dialogVariants } from './dialog.variants.js';
4
+ import type { DialogProps } from './dialog.types.js';
5
+
6
+ /**
7
+ * Dashforge TW `<Dialog>` — declarative modal dialog.
8
+ *
9
+ * Built on `@radix-ui/react-dialog`:
10
+ * - APG dialog pattern out of the box (focus trap, restore focus on
11
+ * close, Esc-to-close, `aria-modal`, `aria-labelledby`).
12
+ * - Renders into a portal (no z-index hell).
13
+ * - Scroll lock on `<body>` while open.
14
+ *
15
+ * Use the imperative `useDialog()` (export from this same module) if
16
+ * you want a `confirm()`-style return value pattern (similar to
17
+ * `useConfirm()` from `ConfirmDialog`). Use `<Dialog>` when you want
18
+ * the control flow living in your component tree.
19
+ */
20
+ export function Dialog(props: DialogProps) {
21
+ const {
22
+ open,
23
+ onOpenChange,
24
+ children,
25
+ title,
26
+ description,
27
+ showCloseButton = true,
28
+ disableBackdropClose = false,
29
+ disableEscapeClose = false,
30
+ size = 'md',
31
+ sx,
32
+ slotProps,
33
+ } = props;
34
+
35
+ const v = dialogVariants({ size });
36
+
37
+ return (
38
+ <RadixDialog.Root open={open} onOpenChange={onOpenChange}>
39
+ <RadixDialog.Portal>
40
+ <RadixDialog.Overlay
41
+ className={cn(v.overlay(), slotProps?.overlay?.className)}
42
+ />
43
+ <RadixDialog.Content
44
+ className={cn(v.content(), sx, slotProps?.content?.className)}
45
+ onPointerDownOutside={(event) => {
46
+ if (disableBackdropClose) event.preventDefault();
47
+ }}
48
+ onEscapeKeyDown={(event) => {
49
+ if (disableEscapeClose) event.preventDefault();
50
+ }}
51
+ >
52
+ {title != null && (
53
+ <RadixDialog.Title
54
+ className={cn(v.title(), slotProps?.title?.className)}
55
+ >
56
+ {title}
57
+ </RadixDialog.Title>
58
+ )}
59
+ {description != null && (
60
+ <RadixDialog.Description
61
+ className={cn(v.description(), slotProps?.description?.className)}
62
+ >
63
+ {description}
64
+ </RadixDialog.Description>
65
+ )}
66
+ <div className={cn(v.body(), slotProps?.body?.className)}>
67
+ {children}
68
+ </div>
69
+ {showCloseButton && (
70
+ <RadixDialog.Close
71
+ aria-label="Close"
72
+ className={cn(v.closeButton(), slotProps?.closeButton?.className)}
73
+ >
74
+ <svg
75
+ width="1em"
76
+ height="1em"
77
+ viewBox="0 0 16 16"
78
+ fill="none"
79
+ stroke="currentColor"
80
+ strokeWidth="1.5"
81
+ strokeLinecap="round"
82
+ strokeLinejoin="round"
83
+ aria-hidden="true"
84
+ >
85
+ <path d="M4 4l8 8M12 4l-8 8" />
86
+ </svg>
87
+ </RadixDialog.Close>
88
+ )}
89
+ </RadixDialog.Content>
90
+ </RadixDialog.Portal>
91
+ </RadixDialog.Root>
92
+ );
93
+ }