@dashforge/tw 0.1.0-beta → 0.2.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 (185) hide show
  1. package/CHANGELOG.md +108 -0
  2. package/dist/index.d.ts +1 -82
  3. package/dist/index.esm.js +1563 -2
  4. package/dist/src/components/AspectRatio/AspectRatio.d.ts +36 -0
  5. package/dist/src/components/AspectRatio/AspectRatio.d.ts.map +1 -0
  6. package/dist/src/components/AspectRatio/aspectRatio.types.d.ts +50 -0
  7. package/dist/src/components/AspectRatio/aspectRatio.types.d.ts.map +1 -0
  8. package/dist/src/components/Box/Box.d.ts +36 -0
  9. package/dist/src/components/Box/Box.d.ts.map +1 -0
  10. package/dist/src/components/Box/box.types.d.ts +54 -0
  11. package/dist/src/components/Box/box.types.d.ts.map +1 -0
  12. package/dist/src/components/Box/box.variants.d.ts +402 -0
  13. package/dist/src/components/Box/box.variants.d.ts.map +1 -0
  14. package/dist/src/components/Container/Container.d.ts +35 -0
  15. package/dist/src/components/Container/Container.d.ts.map +1 -0
  16. package/dist/src/components/Container/container.types.d.ts +41 -0
  17. package/dist/src/components/Container/container.types.d.ts.map +1 -0
  18. package/dist/src/components/Container/container.variants.d.ts +93 -0
  19. package/dist/src/components/Container/container.variants.d.ts.map +1 -0
  20. package/dist/src/components/Divider/Divider.d.ts +50 -0
  21. package/dist/src/components/Divider/Divider.d.ts.map +1 -0
  22. package/dist/src/components/Divider/divider.types.d.ts +47 -0
  23. package/dist/src/components/Divider/divider.types.d.ts.map +1 -0
  24. package/dist/src/components/Divider/divider.variants.d.ts +129 -0
  25. package/dist/src/components/Divider/divider.variants.d.ts.map +1 -0
  26. package/dist/src/components/Grid/Grid.d.ts +32 -0
  27. package/dist/src/components/Grid/Grid.d.ts.map +1 -0
  28. package/dist/src/components/Grid/grid.types.d.ts +103 -0
  29. package/dist/src/components/Grid/grid.types.d.ts.map +1 -0
  30. package/dist/src/components/Grid/grid.variants.d.ts +453 -0
  31. package/dist/src/components/Grid/grid.variants.d.ts.map +1 -0
  32. package/dist/src/components/Stack/Stack.d.ts +24 -0
  33. package/dist/src/components/Stack/Stack.d.ts.map +1 -0
  34. package/dist/src/components/Stack/stack.types.d.ts +61 -0
  35. package/dist/src/components/Stack/stack.types.d.ts.map +1 -0
  36. package/dist/src/components/Stack/stack.variants.d.ts +163 -0
  37. package/dist/src/components/Stack/stack.variants.d.ts.map +1 -0
  38. package/dist/src/components/Typography/Typography.d.ts +42 -0
  39. package/dist/src/components/Typography/Typography.d.ts.map +1 -0
  40. package/dist/src/components/Typography/typography.types.d.ts +61 -0
  41. package/dist/src/components/Typography/typography.types.d.ts.map +1 -0
  42. package/dist/src/components/Typography/typography.variants.d.ts +167 -0
  43. package/dist/src/components/Typography/typography.variants.d.ts.map +1 -0
  44. package/dist/src/components/VisuallyHidden/VisuallyHidden.d.ts +42 -0
  45. package/dist/src/components/VisuallyHidden/VisuallyHidden.d.ts.map +1 -0
  46. package/dist/src/components/VisuallyHidden/visuallyHidden.types.d.ts +42 -0
  47. package/dist/src/components/VisuallyHidden/visuallyHidden.types.d.ts.map +1 -0
  48. package/dist/src/index.d.ts +22 -0
  49. package/dist/src/index.d.ts.map +1 -1
  50. package/package.json +3 -3
  51. package/src/components/AspectRatio/AspectRatio.test.tsx +173 -0
  52. package/src/components/AspectRatio/AspectRatio.tsx +73 -0
  53. package/src/components/AspectRatio/aspectRatio.types.ts +54 -0
  54. package/src/components/Box/Box.test.tsx +349 -0
  55. package/src/components/Box/Box.tsx +83 -0
  56. package/src/components/Box/box.types.ts +61 -0
  57. package/src/components/Box/box.variants.ts +211 -0
  58. package/src/components/Container/Container.test.tsx +209 -0
  59. package/src/components/Container/Container.tsx +74 -0
  60. package/src/components/Container/container.types.ts +45 -0
  61. package/src/components/Container/container.variants.ts +81 -0
  62. package/src/components/Divider/Divider.test.tsx +241 -0
  63. package/src/components/Divider/Divider.tsx +140 -0
  64. package/src/components/Divider/divider.types.ts +52 -0
  65. package/src/components/Divider/divider.variants.ts +115 -0
  66. package/src/components/Grid/Grid.test.tsx +321 -0
  67. package/src/components/Grid/Grid.tsx +148 -0
  68. package/src/components/Grid/grid.types.ts +112 -0
  69. package/src/components/Grid/grid.variants.ts +133 -0
  70. package/src/components/Stack/Stack.test.tsx +309 -0
  71. package/src/components/Stack/Stack.tsx +115 -0
  72. package/src/components/Stack/stack.types.ts +68 -0
  73. package/src/components/Stack/stack.variants.ts +80 -0
  74. package/src/components/Typography/Typography.test.tsx +230 -0
  75. package/src/components/Typography/Typography.tsx +112 -0
  76. package/src/components/Typography/typography.types.ts +65 -0
  77. package/src/components/Typography/typography.variants.ts +113 -0
  78. package/src/components/VisuallyHidden/VisuallyHidden.test.tsx +86 -0
  79. package/src/components/VisuallyHidden/VisuallyHidden.tsx +59 -0
  80. package/src/components/VisuallyHidden/visuallyHidden.types.ts +45 -0
  81. package/src/index.ts +49 -0
  82. package/dist/components/AppShell/AppShell.d.ts +0 -32
  83. package/dist/components/AppShell/AppShell.d.ts.map +0 -1
  84. package/dist/components/AppShell/appShell.types.d.ts +0 -62
  85. package/dist/components/AppShell/appShell.types.d.ts.map +0 -1
  86. package/dist/components/AppShell/appShell.variants.d.ts +0 -65
  87. package/dist/components/AppShell/appShell.variants.d.ts.map +0 -1
  88. package/dist/components/Autocomplete/Autocomplete.d.ts +0 -32
  89. package/dist/components/Autocomplete/Autocomplete.d.ts.map +0 -1
  90. package/dist/components/Autocomplete/autocomplete.types.d.ts +0 -214
  91. package/dist/components/Autocomplete/autocomplete.types.d.ts.map +0 -1
  92. package/dist/components/Autocomplete/autocomplete.variants.d.ts +0 -214
  93. package/dist/components/Autocomplete/autocomplete.variants.d.ts.map +0 -1
  94. package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +0 -23
  95. package/dist/components/Breadcrumbs/Breadcrumbs.d.ts.map +0 -1
  96. package/dist/components/Breadcrumbs/breadcrumbs.types.d.ts +0 -98
  97. package/dist/components/Breadcrumbs/breadcrumbs.types.d.ts.map +0 -1
  98. package/dist/components/Breadcrumbs/breadcrumbs.variants.d.ts +0 -85
  99. package/dist/components/Breadcrumbs/breadcrumbs.variants.d.ts.map +0 -1
  100. package/dist/components/Button/Button.d.ts +0 -44
  101. package/dist/components/Button/Button.d.ts.map +0 -1
  102. package/dist/components/Button/button.types.d.ts +0 -66
  103. package/dist/components/Button/button.types.d.ts.map +0 -1
  104. package/dist/components/Button/button.variants.d.ts +0 -104
  105. package/dist/components/Button/button.variants.d.ts.map +0 -1
  106. package/dist/components/Checkbox/Checkbox.d.ts +0 -31
  107. package/dist/components/Checkbox/Checkbox.d.ts.map +0 -1
  108. package/dist/components/Checkbox/checkbox.types.d.ts +0 -86
  109. package/dist/components/Checkbox/checkbox.types.d.ts.map +0 -1
  110. package/dist/components/Checkbox/checkbox.variants.d.ts +0 -109
  111. package/dist/components/Checkbox/checkbox.variants.d.ts.map +0 -1
  112. package/dist/components/ConfirmDialog/ConfirmDialog.d.ts +0 -38
  113. package/dist/components/ConfirmDialog/ConfirmDialog.d.ts.map +0 -1
  114. package/dist/components/ConfirmDialog/confirmDialog.types.d.ts +0 -80
  115. package/dist/components/ConfirmDialog/confirmDialog.types.d.ts.map +0 -1
  116. package/dist/components/ConfirmDialog/confirmDialog.variants.d.ts +0 -90
  117. package/dist/components/ConfirmDialog/confirmDialog.variants.d.ts.map +0 -1
  118. package/dist/components/DateTimePicker/DateTimePicker.d.ts +0 -49
  119. package/dist/components/DateTimePicker/DateTimePicker.d.ts.map +0 -1
  120. package/dist/components/DateTimePicker/dateTimePicker.types.d.ts +0 -95
  121. package/dist/components/DateTimePicker/dateTimePicker.types.d.ts.map +0 -1
  122. package/dist/components/DateTimePicker/dateTimePicker.variants.d.ts +0 -165
  123. package/dist/components/DateTimePicker/dateTimePicker.variants.d.ts.map +0 -1
  124. package/dist/components/LeftNav/LeftNav.d.ts +0 -34
  125. package/dist/components/LeftNav/LeftNav.d.ts.map +0 -1
  126. package/dist/components/LeftNav/leftNav.types.d.ts +0 -136
  127. package/dist/components/LeftNav/leftNav.types.d.ts.map +0 -1
  128. package/dist/components/LeftNav/leftNav.variants.d.ts +0 -143
  129. package/dist/components/LeftNav/leftNav.variants.d.ts.map +0 -1
  130. package/dist/components/NumberField/NumberField.d.ts +0 -18
  131. package/dist/components/NumberField/NumberField.d.ts.map +0 -1
  132. package/dist/components/NumberField/numberField.types.d.ts +0 -79
  133. package/dist/components/NumberField/numberField.types.d.ts.map +0 -1
  134. package/dist/components/NumberField/numberField.variants.d.ts +0 -169
  135. package/dist/components/NumberField/numberField.variants.d.ts.map +0 -1
  136. package/dist/components/OTPField/OTPField.d.ts +0 -25
  137. package/dist/components/OTPField/OTPField.d.ts.map +0 -1
  138. package/dist/components/OTPField/otpField.types.d.ts +0 -74
  139. package/dist/components/OTPField/otpField.types.d.ts.map +0 -1
  140. package/dist/components/OTPField/otpField.variants.d.ts +0 -105
  141. package/dist/components/OTPField/otpField.variants.d.ts.map +0 -1
  142. package/dist/components/RadioGroup/RadioGroup.d.ts +0 -35
  143. package/dist/components/RadioGroup/RadioGroup.d.ts.map +0 -1
  144. package/dist/components/RadioGroup/radioGroup.types.d.ts +0 -103
  145. package/dist/components/RadioGroup/radioGroup.types.d.ts.map +0 -1
  146. package/dist/components/RadioGroup/radioGroup.variants.d.ts +0 -166
  147. package/dist/components/RadioGroup/radioGroup.variants.d.ts.map +0 -1
  148. package/dist/components/Snackbar/Snackbar.d.ts +0 -37
  149. package/dist/components/Snackbar/Snackbar.d.ts.map +0 -1
  150. package/dist/components/Snackbar/snackbar.types.d.ts +0 -86
  151. package/dist/components/Snackbar/snackbar.types.d.ts.map +0 -1
  152. package/dist/components/Snackbar/snackbar.variants.d.ts +0 -153
  153. package/dist/components/Snackbar/snackbar.variants.d.ts.map +0 -1
  154. package/dist/components/Switch/Switch.d.ts +0 -15
  155. package/dist/components/Switch/Switch.d.ts.map +0 -1
  156. package/dist/components/Switch/switch.types.d.ts +0 -47
  157. package/dist/components/Switch/switch.types.d.ts.map +0 -1
  158. package/dist/components/Switch/switch.variants.d.ts +0 -105
  159. package/dist/components/Switch/switch.variants.d.ts.map +0 -1
  160. package/dist/components/TextField/TextField.d.ts +0 -25
  161. package/dist/components/TextField/TextField.d.ts.map +0 -1
  162. package/dist/components/TextField/textField.types.d.ts +0 -72
  163. package/dist/components/TextField/textField.types.d.ts.map +0 -1
  164. package/dist/components/TextField/textField.variants.d.ts +0 -160
  165. package/dist/components/TextField/textField.variants.d.ts.map +0 -1
  166. package/dist/components/Textarea/Textarea.d.ts +0 -16
  167. package/dist/components/Textarea/Textarea.d.ts.map +0 -1
  168. package/dist/components/Textarea/textarea.types.d.ts +0 -63
  169. package/dist/components/Textarea/textarea.types.d.ts.map +0 -1
  170. package/dist/components/Textarea/textarea.variants.d.ts +0 -197
  171. package/dist/components/Textarea/textarea.variants.d.ts.map +0 -1
  172. package/dist/components/TopBar/TopBar.d.ts +0 -33
  173. package/dist/components/TopBar/TopBar.d.ts.map +0 -1
  174. package/dist/components/TopBar/topBar.types.d.ts +0 -49
  175. package/dist/components/TopBar/topBar.types.d.ts.map +0 -1
  176. package/dist/components/TopBar/topBar.variants.d.ts +0 -79
  177. package/dist/components/TopBar/topBar.variants.d.ts.map +0 -1
  178. package/dist/components/_shared/resolveValidationState.d.ts +0 -42
  179. package/dist/components/_shared/resolveValidationState.d.ts.map +0 -1
  180. package/dist/hooks/useAccessState.d.ts +0 -37
  181. package/dist/hooks/useAccessState.d.ts.map +0 -1
  182. package/dist/index.d.ts.map +0 -1
  183. package/dist/tsconfig.lib.tsbuildinfo +0 -1
  184. package/dist/utils/cn.d.ts +0 -26
  185. package/dist/utils/cn.d.ts.map +0 -1
@@ -0,0 +1,321 @@
1
+ // @vitest-environment jsdom
2
+ import { describe, it, expect } from 'vitest';
3
+ import { render } from '@testing-library/react';
4
+ import { Grid } from './Grid.js';
5
+
6
+ /**
7
+ * Suite covers:
8
+ * • Container role — display:grid + cols + spacing + autoFlow
9
+ * • Item role — col-span at xs/sm/md/lg/xl breakpoints
10
+ * • Default semantics — container without cols → 12; item without xs → 'full'
11
+ * • Polymorphism — as / asChild on both roles
12
+ * • Override — sx wins over variant defaults
13
+ *
14
+ * We don't enumerate every breakpoint × span (5 × 14 = 70 combos);
15
+ * spot-checks across xs/md/xl with span 6/auto/full cover the
16
+ * cascade. If those work, the rest works.
17
+ */
18
+ describe('<Grid>', () => {
19
+ // ─── Container role ─────────────────────────────────────────────────
20
+ describe('container', () => {
21
+ it('renders display:grid + default cols=12', () => {
22
+ const { container } = render(<Grid container>x</Grid>);
23
+ const cls = container.firstElementChild?.className ?? '';
24
+ expect(cls).toContain('grid');
25
+ expect(cls).toContain('grid-cols-12');
26
+ });
27
+
28
+ it('container with cols={6}', () => {
29
+ const { container } = render(<Grid container cols={6}>x</Grid>);
30
+ expect(container.firstElementChild?.className).toContain('grid-cols-6');
31
+ });
32
+
33
+ it('spacing={4} emits gap-4', () => {
34
+ const { container } = render(<Grid container spacing={4}>x</Grid>);
35
+ expect(container.firstElementChild?.className).toContain('gap-4');
36
+ });
37
+
38
+ it('spacingX + spacingY emit gap-x / gap-y', () => {
39
+ const { container } = render(
40
+ <Grid container spacingX={6} spacingY={2}>x</Grid>,
41
+ );
42
+ const cls = container.firstElementChild?.className ?? '';
43
+ expect(cls).toContain('gap-x-6');
44
+ expect(cls).toContain('gap-y-2');
45
+ });
46
+
47
+ it('autoFlow="dense"', () => {
48
+ const { container } = render(<Grid container autoFlow="dense">x</Grid>);
49
+ expect(container.firstElementChild?.className).toContain('grid-flow-dense');
50
+ });
51
+ });
52
+
53
+ // ─── Item role ──────────────────────────────────────────────────────
54
+ describe('item', () => {
55
+ it('item without props defaults to col-span-full (xs="full")', () => {
56
+ const { container } = render(<Grid>x</Grid>);
57
+ const cls = container.firstElementChild?.className ?? '';
58
+ expect(cls).toContain('col-span-full');
59
+ // never accidentally a container
60
+ expect(cls).not.toContain('grid-cols-12');
61
+ // confirm it's NOT display:grid (no `grid` class)
62
+ expect(cls.split(' ')).not.toContain('grid');
63
+ });
64
+
65
+ it('item xs={6}', () => {
66
+ const { container } = render(<Grid xs={6}>x</Grid>);
67
+ expect(container.firstElementChild?.className).toContain('col-span-6');
68
+ });
69
+
70
+ it('item with responsive cascade xs={12} md={6} lg={4}', () => {
71
+ const { container } = render(<Grid xs={12} md={6} lg={4}>x</Grid>);
72
+ const cls = container.firstElementChild?.className ?? '';
73
+ expect(cls).toContain('col-span-12');
74
+ expect(cls).toContain('md:col-span-6');
75
+ expect(cls).toContain('lg:col-span-4');
76
+ });
77
+
78
+ it('item xs="auto"', () => {
79
+ const { container } = render(<Grid xs="auto">x</Grid>);
80
+ expect(container.firstElementChild?.className).toContain('col-auto');
81
+ });
82
+
83
+ it('item sm="full" xl={3}', () => {
84
+ const { container } = render(<Grid sm="full" xl={3}>x</Grid>);
85
+ const cls = container.firstElementChild?.className ?? '';
86
+ expect(cls).toContain('sm:col-span-full');
87
+ expect(cls).toContain('xl:col-span-3');
88
+ });
89
+ });
90
+
91
+ // ─── Composition: container > item ──────────────────────────────────
92
+ describe('container > item composition', () => {
93
+ it('container with item children produces the canonical class chain', () => {
94
+ const { container } = render(
95
+ <Grid container spacing={4}>
96
+ <Grid xs={12} md={6}>a</Grid>
97
+ <Grid xs={12} md={6}>b</Grid>
98
+ </Grid>,
99
+ );
100
+ const root = container.firstElementChild;
101
+ expect(root?.className).toContain('grid');
102
+ expect(root?.className).toContain('gap-4');
103
+ const items = root?.querySelectorAll(':scope > div') ?? [];
104
+ expect(items.length).toBe(2);
105
+ items.forEach((item) => {
106
+ expect(item.className).toContain('col-span-12');
107
+ expect(item.className).toContain('md:col-span-6');
108
+ });
109
+ });
110
+ });
111
+
112
+ // ─── Override + sx ──────────────────────────────────────────────────
113
+ describe('override', () => {
114
+ it('sx wins over default cols on container', () => {
115
+ const { container } = render(
116
+ <Grid container sx="grid-cols-4">x</Grid>,
117
+ );
118
+ const cls = container.firstElementChild?.className ?? '';
119
+ expect(cls).toContain('grid-cols-4');
120
+ // tailwind-merge collapses the default 12 → 4
121
+ expect(cls).not.toContain('grid-cols-12');
122
+ });
123
+
124
+ it('sx adds utilities Grid does not expose', () => {
125
+ const { container } = render(<Grid container sx="min-h-screen">x</Grid>);
126
+ expect(container.firstElementChild?.className).toContain('min-h-screen');
127
+ });
128
+ });
129
+
130
+ // ─── Polymorphism ───────────────────────────────────────────────────
131
+ describe('polymorphism', () => {
132
+ it('container as="section" renders <section> + grid classes', () => {
133
+ const { container } = render(<Grid container as="section">x</Grid>);
134
+ const el = container.firstElementChild;
135
+ expect(el?.tagName).toBe('SECTION');
136
+ expect(el?.className).toContain('grid');
137
+ });
138
+
139
+ it('item asChild paints onto child element', () => {
140
+ const { container } = render(
141
+ <Grid xs={6} asChild>
142
+ <article>x</article>
143
+ </Grid>,
144
+ );
145
+ const el = container.firstElementChild;
146
+ expect(el?.tagName).toBe('ARTICLE');
147
+ expect(el?.className).toContain('col-span-6');
148
+ });
149
+ });
150
+
151
+ // ─── DOM cleanliness (no role-specific props leak as HTML attrs) ────
152
+ describe('DOM cleanliness', () => {
153
+ it('container props (cols/spacing/autoFlow) do not leak to DOM', () => {
154
+ const { container } = render(
155
+ <Grid container cols={4} spacing={2} autoFlow="dense">x</Grid>,
156
+ );
157
+ const el = container.firstElementChild as HTMLElement;
158
+ expect(el.hasAttribute('cols')).toBe(false);
159
+ expect(el.hasAttribute('spacing')).toBe(false);
160
+ expect(el.hasAttribute('autoflow')).toBe(false);
161
+ });
162
+
163
+ it('item props (xs/sm/md/lg/xl) do not leak to DOM', () => {
164
+ const { container } = render(
165
+ <Grid xs={12} md={6} lg={4}>x</Grid>,
166
+ );
167
+ const el = container.firstElementChild as HTMLElement;
168
+ expect(el.hasAttribute('xs')).toBe(false);
169
+ expect(el.hasAttribute('md')).toBe(false);
170
+ expect(el.hasAttribute('lg')).toBe(false);
171
+ });
172
+ });
173
+
174
+ // ─── F11-bis edge cases: responsive cascade across ALL breakpoints ──
175
+ // The original suite spot-checked xs/md/lg/sm/xl with a couple of
176
+ // values each. The publish-validation pass enumerates each breakpoint
177
+ // for the high-traffic span values (1, 6, 12, auto, full) so a future
178
+ // mapping-table edit can't silently drop one.
179
+ describe('responsive cascade — every breakpoint × representative span', () => {
180
+ const BREAKPOINTS = ['sm', 'md', 'lg', 'xl'] as const;
181
+
182
+ it.each(BREAKPOINTS)('breakpoint %s × span=1', (bp) => {
183
+ const props = { [bp]: 1 as const };
184
+ const { container } = render(<Grid {...props}>x</Grid>);
185
+ expect(container.firstElementChild?.className).toContain(`${bp}:col-span-1`);
186
+ });
187
+
188
+ it.each(BREAKPOINTS)('breakpoint %s × span=6', (bp) => {
189
+ const props = { [bp]: 6 as const };
190
+ const { container } = render(<Grid {...props}>x</Grid>);
191
+ expect(container.firstElementChild?.className).toContain(`${bp}:col-span-6`);
192
+ });
193
+
194
+ it.each(BREAKPOINTS)('breakpoint %s × span=12', (bp) => {
195
+ const props = { [bp]: 12 as const };
196
+ const { container } = render(<Grid {...props}>x</Grid>);
197
+ expect(container.firstElementChild?.className).toContain(`${bp}:col-span-12`);
198
+ });
199
+
200
+ it.each(BREAKPOINTS)('breakpoint %s × auto', (bp) => {
201
+ const props = { [bp]: 'auto' as const };
202
+ const { container } = render(<Grid {...props}>x</Grid>);
203
+ expect(container.firstElementChild?.className).toContain(`${bp}:col-auto`);
204
+ });
205
+
206
+ it.each(BREAKPOINTS)('breakpoint %s × full', (bp) => {
207
+ const props = { [bp]: 'full' as const };
208
+ const { container } = render(<Grid {...props}>x</Grid>);
209
+ expect(container.firstElementChild?.className).toContain(`${bp}:col-span-full`);
210
+ });
211
+
212
+ it('full cascade xs=12 sm=6 md=4 lg=3 xl=2 emits all five', () => {
213
+ const { container } = render(
214
+ <Grid xs={12} sm={6} md={4} lg={3} xl={2}>x</Grid>,
215
+ );
216
+ const cls = container.firstElementChild?.className ?? '';
217
+ expect(cls).toContain('col-span-12');
218
+ expect(cls).toContain('sm:col-span-6');
219
+ expect(cls).toContain('md:col-span-4');
220
+ expect(cls).toContain('lg:col-span-3');
221
+ expect(cls).toContain('xl:col-span-2');
222
+ });
223
+ });
224
+
225
+ // ─── F11-bis edge cases: autoFlow all five varianti ─────────────────
226
+ describe('autoFlow — every value', () => {
227
+ const FLOWS = ['row', 'col', 'dense', 'row-dense', 'col-dense'] as const;
228
+ const EXPECTED: Record<typeof FLOWS[number], string> = {
229
+ row: 'grid-flow-row',
230
+ col: 'grid-flow-col',
231
+ dense: 'grid-flow-dense',
232
+ 'row-dense': 'grid-flow-row-dense',
233
+ 'col-dense': 'grid-flow-col-dense',
234
+ };
235
+
236
+ it.each(FLOWS)('autoFlow="%s" emits the right grid-flow-* class', (flow) => {
237
+ const { container } = render(<Grid container autoFlow={flow}>x</Grid>);
238
+ expect(container.firstElementChild?.className).toContain(EXPECTED[flow]);
239
+ });
240
+ });
241
+
242
+ // ─── F11-bis edge cases: container cols all valid values ────────────
243
+ describe('cols — every valid value', () => {
244
+ const COLS = [1, 2, 3, 4, 6, 12] as const;
245
+ it.each(COLS)('container cols=%s emits grid-cols-%s', (n) => {
246
+ const { container } = render(<Grid container cols={n}>x</Grid>);
247
+ expect(container.firstElementChild?.className).toContain(`grid-cols-${n}`);
248
+ });
249
+ });
250
+
251
+ // ─── F11-bis edge cases: spacingX vs spacingY independence ──────────
252
+ describe('spacingX / spacingY independence', () => {
253
+ it('spacingX without spacingY emits only gap-x', () => {
254
+ const { container } = render(<Grid container spacingX={4}>x</Grid>);
255
+ const cls = container.firstElementChild?.className ?? '';
256
+ expect(cls).toContain('gap-x-4');
257
+ expect(cls).not.toMatch(/gap-y-/);
258
+ // standalone `gap-` shouldn't appear unless spacing was passed
259
+ expect(cls).not.toMatch(/gap-\d/);
260
+ });
261
+
262
+ it('spacingY without spacingX emits only gap-y', () => {
263
+ const { container } = render(<Grid container spacingY={2}>x</Grid>);
264
+ const cls = container.firstElementChild?.className ?? '';
265
+ expect(cls).toContain('gap-y-2');
266
+ expect(cls).not.toMatch(/gap-x-/);
267
+ });
268
+
269
+ it('spacing + spacingX: spacing applies symmetrically, spacingX overrides on X', () => {
270
+ const { container } = render(
271
+ <Grid container spacing={4} spacingX={8}>x</Grid>,
272
+ );
273
+ const cls = container.firstElementChild?.className ?? '';
274
+ expect(cls).toContain('gap-4');
275
+ expect(cls).toContain('gap-x-8');
276
+ });
277
+ });
278
+
279
+ // ─── F11-bis edge cases: empty container / orphan item ──────────────
280
+ describe('empty children + orphan item', () => {
281
+ it('container with NO children emits grid + cols, renders empty div', () => {
282
+ const { container } = render(<Grid container />);
283
+ const el = container.firstElementChild as HTMLElement;
284
+ expect(el.className).toContain('grid');
285
+ expect(el.className).toContain('grid-cols-12');
286
+ expect(el.children.length).toBe(0);
287
+ });
288
+
289
+ it('orphan item (no container parent) still emits col-span-* (consumer mistake)', () => {
290
+ // Doesn't crash — produces a col-span-* class that has no effect
291
+ // outside a CSS Grid parent. Documented behaviour: the consumer
292
+ // owns the composition.
293
+ const { container } = render(<Grid xs={6}>x</Grid>);
294
+ expect(container.firstElementChild?.className).toContain('col-span-6');
295
+ });
296
+ });
297
+
298
+ // ─── F11-bis edge cases: composition deep nesting ───────────────────
299
+ describe('deep nesting — Grid inside Grid item', () => {
300
+ it('nested Grid container inside an item works (12-col inside a 6-span)', () => {
301
+ const { container } = render(
302
+ <Grid container spacing={4}>
303
+ <Grid xs={6}>
304
+ <Grid container spacing={2}>
305
+ <Grid xs={6}>inner-a</Grid>
306
+ <Grid xs={6}>inner-b</Grid>
307
+ </Grid>
308
+ </Grid>
309
+ <Grid xs={6}>outer-b</Grid>
310
+ </Grid>,
311
+ );
312
+ // Outer: grid + 12-col + gap-4
313
+ const outer = container.firstElementChild;
314
+ expect(outer?.className).toContain('grid');
315
+ expect(outer?.className).toContain('grid-cols-12');
316
+ expect(outer?.className).toContain('gap-4');
317
+ // Inner items count: outer has 2 direct children
318
+ expect(outer?.children.length).toBe(2);
319
+ });
320
+ });
321
+ });
@@ -0,0 +1,148 @@
1
+ import { forwardRef, type ElementType, type ReactElement } from 'react';
2
+ import { Slot } from '@radix-ui/react-slot';
3
+ import { cn } from '../../utils/cn.js';
4
+ import { gridVariants } from './grid.variants.js';
5
+ import type {
6
+ GridProps,
7
+ GridContainerProps,
8
+ GridItemProps,
9
+ ColSpan,
10
+ GridSpacingStep,
11
+ } from './grid.types.js';
12
+
13
+ /**
14
+ * `<Grid>` — CSS Grid container + item, polymorphic in role.
15
+ *
16
+ * API surface mirrors MUI Grid v2:
17
+ * • <Grid container spacing={4} cols={12}> ← container
18
+ * • <Grid xs={12} md={6}> ← item
19
+ *
20
+ * Engine is REAL CSS Grid (not flexbox, unlike MUI v2 internals).
21
+ * Benefits over flexbox-based implementation:
22
+ * • Native `gap` (no negative-margin tricks)
23
+ * • `col-span-N` maps directly to `grid-column: span N`
24
+ * • Vertical alignment without manual `align-items` per item
25
+ * • Auto-flow for dense packing without DOM gymnastics
26
+ *
27
+ * TypeScript discriminated union (see grid.types.ts) makes mixing
28
+ * impossible: `<Grid container xs={6}>` won't compile. Same for the
29
+ * inverse. IntelliSense filters by role.
30
+ *
31
+ * Defaults at the component level (not at the TV level — see the
32
+ * variants file for the rationale):
33
+ * • container: cols defaults to 12 (MUI convention)
34
+ * • item: xs defaults to 'full' so a forgotten prop doesn't
35
+ * collapse the cell to 1/12th of a row
36
+ *
37
+ * `asChild` on a CONTAINER is technically allowed but rarely useful:
38
+ * `display:grid` only applies to direct children, so the slotted
39
+ * element has to already be a viable container parent. Use sparingly;
40
+ * test asserts the wrapping still emits the right class chain.
41
+ */
42
+ export const Grid = forwardRef<HTMLElement, GridProps>(
43
+ function Grid(props, ref) {
44
+ const { as, asChild = false, sx, children, ...rest } = props as GridProps & {
45
+ as?: ElementType;
46
+ asChild?: boolean;
47
+ sx?: string;
48
+ children?: React.ReactNode;
49
+ };
50
+ /*
51
+ * Discriminated union runtime branch.
52
+ *
53
+ * TS narrows GridProps to ONE of the two shapes (container or item)
54
+ * at the call site, but inside this function body we receive the
55
+ * union — so we manually narrow via a single cast per branch.
56
+ * `as GridContainerProps` / `as GridItemProps` is sound because
57
+ * `container === true` is the literal discriminator declared in
58
+ * the types file; the cast just makes TS read the right branch.
59
+ */
60
+ const isContainer = (props as { container?: boolean }).container === true;
61
+
62
+ let classes: string;
63
+ let containerPayload: GridContainerProps | null = null;
64
+ let itemPayload: GridItemProps | null = null;
65
+
66
+ if (isContainer) {
67
+ containerPayload = props as GridContainerProps;
68
+ /*
69
+ * Container branch — pass ONLY container axes to TV. Default cols
70
+ * to 12 (MUI v2 convention) so a forgotten prop doesn't collapse
71
+ * to grid-cols-1. The spacing axes are passed straight through;
72
+ * TV silently drops undefined values.
73
+ */
74
+ classes = cn(
75
+ gridVariants({
76
+ container: true,
77
+ cols: (containerPayload.cols ?? 12) as 1 | 2 | 3 | 4 | 6 | 12,
78
+ spacing: containerPayload.spacing,
79
+ spacingX: containerPayload.spacingX,
80
+ spacingY: containerPayload.spacingY,
81
+ autoFlow: containerPayload.autoFlow,
82
+ }),
83
+ sx,
84
+ );
85
+ } else {
86
+ itemPayload = props as GridItemProps;
87
+ /*
88
+ * Item branch — default `xs` to 'full' so a forgotten breakpoint
89
+ * prop doesn't collapse the cell to grid-auto's minimum width.
90
+ */
91
+ classes = cn(
92
+ gridVariants({
93
+ xs: (itemPayload.xs ?? 'full') as ColSpan,
94
+ sm: itemPayload.sm,
95
+ md: itemPayload.md,
96
+ lg: itemPayload.lg,
97
+ xl: itemPayload.xl,
98
+ }),
99
+ sx,
100
+ );
101
+ }
102
+
103
+ /*
104
+ * Strip role-specific props from `rest` before spreading on the DOM
105
+ * element. Without this, React warns:
106
+ * "React does not recognize the `cols` prop on a DOM element"
107
+ */
108
+ const domRest: Record<string, unknown> = { ...(rest as Record<string, unknown>) };
109
+ if (containerPayload) {
110
+ delete domRest.cols;
111
+ delete domRest.spacing;
112
+ delete domRest.spacingX;
113
+ delete domRest.spacingY;
114
+ delete domRest.autoFlow;
115
+ }
116
+ if (itemPayload) {
117
+ delete domRest.xs;
118
+ delete domRest.sm;
119
+ delete domRest.md;
120
+ delete domRest.lg;
121
+ delete domRest.xl;
122
+ }
123
+ // `container` discriminator itself must never reach the DOM.
124
+ delete domRest.container;
125
+ // Silence unused vars that the union typings require us to receive.
126
+ void itemPayload; void containerPayload;
127
+ // The unused-vars helper from grid.types is a type-only import,
128
+ // referenced here to keep ESM tree-shake clean — TS handles imports.
129
+ void ({} as GridSpacingStep);
130
+
131
+ if (asChild) {
132
+ return (
133
+ <Slot ref={ref} className={classes} {...domRest}>
134
+ {children as ReactElement}
135
+ </Slot>
136
+ );
137
+ }
138
+
139
+ const Tag = (as ?? 'div') as ElementType;
140
+ return (
141
+ <Tag ref={ref as never} className={classes} {...domRest}>
142
+ {children}
143
+ </Tag>
144
+ );
145
+ },
146
+ );
147
+
148
+ Grid.displayName = 'Grid';
@@ -0,0 +1,112 @@
1
+ import type { ElementType, HTMLAttributes } from 'react';
2
+
3
+ /**
4
+ * Grid types — discriminated union for container vs item role.
5
+ *
6
+ * Pattern is MUI v2: a single `<Grid>` component that switches role
7
+ * based on the `container` prop. Container exposes layout axes
8
+ * (cols, spacing, autoFlow). Item exposes per-breakpoint span axes
9
+ * (xs/sm/md/lg/xl).
10
+ *
11
+ * TypeScript-level enforcement (the key win over MUI):
12
+ * • `<Grid container xs={6}>` is a TYPE ERROR — `xs` doesn't exist
13
+ * on the container shape.
14
+ * • `<Grid xs={6} spacing={4}>` is a TYPE ERROR — `spacing` doesn't
15
+ * exist on the item shape.
16
+ * IntelliSense filters suggestions per role, so the developer never
17
+ * sees props that don't apply.
18
+ *
19
+ * Type-only file (no runtime). Lives separate from the variants so the
20
+ * union doesn't widen with the variant catalogue's enum unions.
21
+ */
22
+
23
+ /**
24
+ * Valid column-span values for a grid item, at any breakpoint.
25
+ * • 1..12 — explicit span count
26
+ * • 'auto' — content-sized (CSS Grid auto-track)
27
+ * • 'full' — `col-span-full` (spans all columns regardless of count)
28
+ */
29
+ export type ColSpan =
30
+ | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12
31
+ | 'auto'
32
+ | 'full';
33
+
34
+ /**
35
+ * Token-scale spacing step. Mirror of Box.p / Stack.gap so the value
36
+ * space across primitives is identical — `<Grid container spacing={4}>`
37
+ * and `<Stack gap={4}>` produce visually equivalent gaps.
38
+ */
39
+ export type GridSpacingStep =
40
+ | 0 | '0.5' | 1 | 2 | 3 | 4 | 6 | 8 | 12 | 16 | 24;
41
+
42
+ /**
43
+ * Container-role props. Discriminated on `container: true`.
44
+ *
45
+ * NOTE on `cols`: defaults to 12 in the component implementation
46
+ * (not in TV) — the MUI v2 convention. Override to 6/4/3/2/1 for
47
+ * dense dashboard layouts.
48
+ */
49
+ export interface GridContainerProps {
50
+ /** Discriminator — `true` makes this a grid container. */
51
+ container: true;
52
+ /** Number of columns. Default 12. */
53
+ cols?: 1 | 2 | 3 | 4 | 6 | 12;
54
+ /** Gap between cells. Shorthand for spacingX + spacingY. */
55
+ spacing?: GridSpacingStep;
56
+ /** Horizontal gap override (wins over `spacing`). */
57
+ spacingX?: GridSpacingStep;
58
+ /** Vertical gap override (wins over `spacing`). */
59
+ spacingY?: GridSpacingStep;
60
+ /** `grid-auto-flow` — useful for dense or column-major packing. */
61
+ autoFlow?: 'row' | 'col' | 'dense' | 'row-dense' | 'col-dense';
62
+ }
63
+
64
+ /**
65
+ * Item-role props. Discriminated on `container: false | undefined`.
66
+ *
67
+ * Each breakpoint accepts a `ColSpan`. The cascade is Tailwind-native
68
+ * mobile-first: `xs` is the base (no media query), `sm/md/lg/xl`
69
+ * override at the corresponding min-width.
70
+ *
71
+ * Default behaviour when no breakpoint is set: spans `full` — the
72
+ * "comfortable default" so a forgotten prop doesn't collapse the cell
73
+ * to 1/12th of a row.
74
+ */
75
+ export interface GridItemProps {
76
+ /** Discriminator — absent (or `false`) makes this a grid item. */
77
+ container?: false;
78
+ /** Base breakpoint (no media query). Default `'full'`. */
79
+ xs?: ColSpan;
80
+ /** Span at sm breakpoint and up. */
81
+ sm?: ColSpan;
82
+ /** Span at md breakpoint and up. */
83
+ md?: ColSpan;
84
+ /** Span at lg breakpoint and up. */
85
+ lg?: ColSpan;
86
+ /** Span at xl breakpoint and up. */
87
+ xl?: ColSpan;
88
+ }
89
+
90
+ /**
91
+ * Common props shared by both roles. Kept in a separate intersection
92
+ * so the discriminated union stays narrow and IntelliSense fast.
93
+ */
94
+ interface GridCommonProps extends Omit<HTMLAttributes<HTMLDivElement>, 'className'> {
95
+ /** Override the rendered HTML tag. Default `'div'`. Ignored under `asChild`. */
96
+ as?: ElementType;
97
+ /**
98
+ * Render via Radix Slot onto the single child. Wins over `as`.
99
+ * Note: container Grids using `asChild` don't make sense for most
100
+ * cases — the Slot pattern collapses our wrapper, but Grid's
101
+ * `display:grid` only applies to direct children, so the child
102
+ * needs to BE a container with the right children.
103
+ */
104
+ asChild?: boolean;
105
+ /** Utility-class override, merged via tailwind-merge. */
106
+ sx?: string;
107
+ }
108
+
109
+ /**
110
+ * `<Grid>` props — discriminated union: container OR item, never both.
111
+ */
112
+ export type GridProps = (GridContainerProps | GridItemProps) & GridCommonProps;