@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,73 @@
1
+ import { forwardRef, type CSSProperties, type ElementType } from 'react';
2
+ import { cn } from '../../utils/cn.js';
3
+ import type { AspectRatioProps } from './aspectRatio.types.js';
4
+
5
+ /**
6
+ * `<AspectRatio>` — locks the aspect ratio of its child container,
7
+ * regardless of width. The classic use is responsive images and
8
+ * embedded media: an `<img>` that takes 100% of the available width
9
+ * but always renders at 16:9 (or 1:1, or whatever the source ratio is)
10
+ * — no jumping layouts during image load, no whitespace below the
11
+ * media, no JS measurement.
12
+ *
13
+ * Implementation: native CSS `aspect-ratio` property. Supported in
14
+ * every browser shipped from 2021 onward (Chrome 88, Firefox 89,
15
+ * Safari 15, Edge 88). No padding-bottom hack — that workaround
16
+ * predates the native property and brings ugly absolute-positioning
17
+ * requirements on the child.
18
+ *
19
+ * Why a component if it's "just one CSS property"?
20
+ * Two reasons:
21
+ * 1. Discoverability — `<AspectRatio ratio={16/9}>` documents the
22
+ * intent at the call site. `style={{ aspectRatio: '16/9' }}` is
23
+ * the same thing functionally, but harder to spot in a 200-line
24
+ * component file.
25
+ * 2. Composition — pairs naturally with `sx="rounded-xl overflow-hidden"`
26
+ * for the canonical "rounded clipped media" pattern. Forgetting
27
+ * the `overflow-hidden` is the #1 mistake we want to prevent
28
+ * through documentation (it's in this component's MDX, at the
29
+ * top of the Notes).
30
+ *
31
+ * Child contract:
32
+ * The single child is expected to fill the container — typically
33
+ * `<img>` / `<video>` with `className="w-full h-full object-cover"`.
34
+ * We don't force this via CSS (the consumer might want a centered
35
+ * icon instead of a filling image) — but it's the 99% case, and the
36
+ * docs show it first.
37
+ */
38
+ export const AspectRatio = forwardRef<HTMLElement, AspectRatioProps>(
39
+ function AspectRatio(props, ref) {
40
+ const {
41
+ ratio = 1,
42
+ as,
43
+ sx,
44
+ style,
45
+ children,
46
+ ...rest
47
+ } = props;
48
+
49
+ /*
50
+ * Normalise to a CSS `aspect-ratio` string. The CSS property
51
+ * accepts both `16/9` and `16 / 9` (with spaces), but for safety
52
+ * we convert numbers to the canonical `N / 1` form — `aspectRatio: 1.7777`
53
+ * works too, but produces an arbitrary-looking value in DevTools.
54
+ */
55
+ const aspectRatioValue = typeof ratio === 'number' ? `${ratio} / 1` : ratio;
56
+
57
+ const mergedStyle: CSSProperties = {
58
+ aspectRatio: aspectRatioValue,
59
+ ...style,
60
+ };
61
+
62
+ const classes = cn('w-full', sx);
63
+ const Tag = (as ?? 'div') as ElementType;
64
+
65
+ return (
66
+ <Tag ref={ref as never} className={classes} style={mergedStyle} {...rest}>
67
+ {children}
68
+ </Tag>
69
+ );
70
+ },
71
+ );
72
+
73
+ AspectRatio.displayName = 'AspectRatio';
@@ -0,0 +1,54 @@
1
+ import type { ElementType, HTMLAttributes, ReactNode } from 'react';
2
+
3
+ /**
4
+ * Props for `<AspectRatio>` — content-shape primitive that locks the
5
+ * aspect ratio of its child regardless of width.
6
+ *
7
+ * Implementation: uses the native CSS `aspect-ratio` property
8
+ * (supported in all current browsers since 2021 — Chrome 88+, Firefox 89+,
9
+ * Safari 15+, Edge 88+). No padding-bottom hack, no JS measurement.
10
+ *
11
+ * `ratio` accepts:
12
+ * • A number — width / height. `16/9` is 1.7777…, `1` is square,
13
+ * `4/3` is 1.333…, `21/9` is ultrawide cinema.
14
+ * • A string with the CSS `aspect-ratio` syntax, e.g. `'16 / 9'`,
15
+ * `'4 / 3'`. Useful when you want the source ratio to read clearly
16
+ * in the JSX (`ratio="16 / 9"` is more legible than `ratio={16/9}`).
17
+ *
18
+ * The component renders a single element with `aspect-ratio: X` and
19
+ * `width: 100%`. The child is expected to fill it — typically an
20
+ * `<img>` or `<video>` with `className="w-full h-full object-cover"`.
21
+ *
22
+ * Why not a TV recipe?
23
+ * The ratio is arbitrary (`16/9`, `1`, `2.35`, anything). Tailwind
24
+ * has `aspect-square` / `aspect-video` / `aspect-[16/9]` arbitrary
25
+ * values, but enumerating every conceivable ratio in TV would be
26
+ * pointless. We set `style={{ aspectRatio }}` directly — pure CSS
27
+ * property, no class purge concerns.
28
+ */
29
+ export interface AspectRatioProps
30
+ extends Omit<HTMLAttributes<HTMLDivElement>, 'className'> {
31
+ /**
32
+ * Aspect ratio as width/height. Number (`16/9`) or CSS string
33
+ * (`'16 / 9'`). Default `1` (square).
34
+ */
35
+ ratio?: number | string;
36
+
37
+ /**
38
+ * The child that fills the locked-ratio container. Typically an
39
+ * `<img>` or `<video>` with `className="w-full h-full object-cover"`.
40
+ */
41
+ children?: ReactNode;
42
+
43
+ /**
44
+ * Override the rendered HTML tag. Defaults to `'div'`.
45
+ */
46
+ as?: ElementType;
47
+
48
+ /**
49
+ * Utility classes appended to the base. Resolved via `tailwind-merge`.
50
+ * Common overrides: `sx="rounded-xl overflow-hidden"` to clip the
51
+ * child's overflow (image bleeds otherwise).
52
+ */
53
+ sx?: string;
54
+ }
@@ -0,0 +1,349 @@
1
+ // @vitest-environment jsdom
2
+ import { describe, it, expect } from 'vitest';
3
+ import { render } from '@testing-library/react';
4
+ import { Box } from './Box.js';
5
+
6
+ /**
7
+ * Suite mirrors the Typography/Button test shape (rendering · variants ·
8
+ * compound × intent · override · polymorphism · pass-through). The big
9
+ * delta here is the compound-variant matrix: 5 surface variants × 7
10
+ * intents = 35 combos, of which 21 carry actual visual differences
11
+ * (outlined / soft / solid × 7 intents). We spot-check a representative
12
+ * subset rather than enumerate all 35 — if the TV compound resolution
13
+ * works for one of each (primary, danger, neutral), it works for all.
14
+ */
15
+ describe('<Box>', () => {
16
+ // ─── Default rendering ──────────────────────────────────────────────
17
+ describe('default rendering', () => {
18
+ it('renders a <div> by default', () => {
19
+ const { container } = render(<Box>x</Box>);
20
+ expect(container.firstElementChild?.tagName).toBe('DIV');
21
+ });
22
+
23
+ it('default variant is plain — no border, no bg, no shadow', () => {
24
+ const { container } = render(<Box>x</Box>);
25
+ const cls = container.firstElementChild?.className ?? '';
26
+ expect(cls).not.toContain('border');
27
+ expect(cls).not.toContain('bg-');
28
+ expect(cls).not.toContain('shadow-sm');
29
+ // baseline `block` is always present
30
+ expect(cls).toContain('block');
31
+ });
32
+ });
33
+
34
+ // ─── Variant — surface chrome ───────────────────────────────────────
35
+ describe('surface variants', () => {
36
+ it('variant="outlined" adds a border', () => {
37
+ const { container } = render(<Box variant="outlined" color="neutral">x</Box>);
38
+ const cls = container.firstElementChild?.className ?? '';
39
+ expect(cls).toContain('border');
40
+ // neutral outlined picks the white surface + neutral-200 border
41
+ expect(cls).toContain('border-neutral-200');
42
+ expect(cls).toContain('bg-white');
43
+ });
44
+
45
+ it('variant="elevated" adds the neutral surface, no border, no color tint', () => {
46
+ const { container } = render(<Box variant="elevated" elevation={3}>x</Box>);
47
+ const cls = container.firstElementChild?.className ?? '';
48
+ expect(cls).toContain('bg-white');
49
+ expect(cls).toContain('dark:bg-neutral-900');
50
+ expect(cls).toContain('shadow-md');
51
+ expect(cls).not.toContain('border ');
52
+ });
53
+
54
+ it('variant="soft" + color="warning" picks the warning soft tones', () => {
55
+ const { container } = render(<Box variant="soft" color="warning">x</Box>);
56
+ const cls = container.firstElementChild?.className ?? '';
57
+ expect(cls).toContain('bg-warning-100');
58
+ expect(cls).toContain('text-warning-900');
59
+ expect(cls).toContain('dark:bg-warning-950/50');
60
+ });
61
+
62
+ it('variant="solid" + color="primary" picks the primary solid', () => {
63
+ const { container } = render(<Box variant="solid" color="primary">x</Box>);
64
+ const cls = container.firstElementChild?.className ?? '';
65
+ expect(cls).toContain('bg-primary-600');
66
+ expect(cls).toContain('text-white');
67
+ expect(cls).toContain('dark:bg-primary-500');
68
+ });
69
+
70
+ it('variant="solid" + color="danger" picks the danger solid', () => {
71
+ const { container } = render(<Box variant="solid" color="danger">x</Box>);
72
+ const cls = container.firstElementChild?.className ?? '';
73
+ expect(cls).toContain('bg-danger-600');
74
+ expect(cls).toContain('text-white');
75
+ });
76
+ });
77
+
78
+ // ─── Elevation scale ─────────────────────────────────────────────────
79
+ describe('elevation', () => {
80
+ it('elevation={0} emits shadow-none', () => {
81
+ const { container } = render(<Box variant="elevated" elevation={0}>x</Box>);
82
+ expect(container.firstElementChild?.className).toContain('shadow-none');
83
+ });
84
+
85
+ it('elevation={5} emits shadow-xl', () => {
86
+ const { container } = render(<Box variant="elevated" elevation={5}>x</Box>);
87
+ expect(container.firstElementChild?.className).toContain('shadow-xl');
88
+ });
89
+ });
90
+
91
+ // ─── Spacing ─────────────────────────────────────────────────────────
92
+ describe('spacing', () => {
93
+ it('p={4} emits p-4', () => {
94
+ const { container } = render(<Box p={4}>x</Box>);
95
+ expect(container.firstElementChild?.className).toContain('p-4');
96
+ });
97
+
98
+ it('px={6} + py={2} emits px-6 + py-2', () => {
99
+ const { container } = render(<Box px={6} py={2}>x</Box>);
100
+ const cls = container.firstElementChild?.className ?? '';
101
+ expect(cls).toContain('px-6');
102
+ expect(cls).toContain('py-2');
103
+ });
104
+
105
+ it('m={"0.5"} emits m-0.5', () => {
106
+ const { container } = render(<Box m="0.5">x</Box>);
107
+ expect(container.firstElementChild?.className).toContain('m-0.5');
108
+ });
109
+ });
110
+
111
+ // ─── Rounded + sizing ────────────────────────────────────────────────
112
+ describe('rounded + sizing', () => {
113
+ it('rounded="xl" emits rounded-xl', () => {
114
+ const { container } = render(<Box rounded="xl">x</Box>);
115
+ expect(container.firstElementChild?.className).toContain('rounded-xl');
116
+ });
117
+
118
+ it('fullWidth emits w-full', () => {
119
+ const { container } = render(<Box fullWidth>x</Box>);
120
+ expect(container.firstElementChild?.className).toContain('w-full');
121
+ });
122
+
123
+ it('fullHeight emits h-full', () => {
124
+ const { container } = render(<Box fullHeight>x</Box>);
125
+ expect(container.firstElementChild?.className).toContain('h-full');
126
+ });
127
+ });
128
+
129
+ // ─── Override semantics ─────────────────────────────────────────────
130
+ describe('override', () => {
131
+ it('sx wins over variant defaults via tailwind-merge', () => {
132
+ const { container } = render(
133
+ <Box variant="solid" color="primary" sx="bg-fuchsia-600">x</Box>,
134
+ );
135
+ const cls = container.firstElementChild?.className ?? '';
136
+ expect(cls).toContain('bg-fuchsia-600');
137
+ // the conflicting bg-primary-600 from the compound is collapsed
138
+ expect(cls).not.toContain('bg-primary-600');
139
+ });
140
+
141
+ it('sx can add utilities Box deliberately omits (overflow)', () => {
142
+ const { container } = render(<Box sx="overflow-hidden">x</Box>);
143
+ expect(container.firstElementChild?.className).toContain('overflow-hidden');
144
+ });
145
+ });
146
+
147
+ // ─── Polymorphism ───────────────────────────────────────────────────
148
+ describe('polymorphism', () => {
149
+ it('as="section" renders a <section>', () => {
150
+ const { container } = render(<Box as="section">x</Box>);
151
+ expect(container.firstElementChild?.tagName).toBe('SECTION');
152
+ });
153
+
154
+ it('asChild renders the single child element with merged className', () => {
155
+ const { container } = render(
156
+ <Box variant="elevated" elevation={2} asChild>
157
+ <article>x</article>
158
+ </Box>,
159
+ );
160
+ const el = container.firstElementChild;
161
+ expect(el?.tagName).toBe('ARTICLE');
162
+ expect(el?.className).toContain('shadow');
163
+ expect(el?.className).toContain('bg-white');
164
+ });
165
+
166
+ it('asChild wins over as when both are passed', () => {
167
+ const { container } = render(
168
+ <Box as="section" asChild>
169
+ <article>x</article>
170
+ </Box>,
171
+ );
172
+ expect(container.firstElementChild?.tagName).toBe('ARTICLE');
173
+ });
174
+ });
175
+
176
+ // ─── Pass-through ────────────────────────────────────────────────────
177
+ describe('pass-through', () => {
178
+ it('forwards data-* and aria-*', () => {
179
+ const { container } = render(
180
+ <Box data-testid="box" aria-label="surface">x</Box>,
181
+ );
182
+ const el = container.firstElementChild;
183
+ expect(el?.getAttribute('data-testid')).toBe('box');
184
+ expect(el?.getAttribute('aria-label')).toBe('surface');
185
+ });
186
+ });
187
+
188
+ // ─── F11-bis edge cases: every compound variant explicit ─────────────
189
+ // The original suite spot-checked 4 surface×intent combos (outlined
190
+ // neutral, soft warning, solid primary, solid danger). The validation
191
+ // pass before publishing 0.2.0-beta enumerates ALL 21 visually-distinct
192
+ // compound entries so a future TV recipe edit can't silently drop one.
193
+ describe('compound variants matrix — every surface × intent', () => {
194
+ const INTENTS = ['primary', 'secondary', 'success', 'warning', 'danger', 'info', 'neutral'] as const;
195
+
196
+ /*
197
+ * Outlined × 7 intents — each emits a tinted border + soft bg pair
198
+ * with the dark-mode counterpart pre-wired. Spot-check picks the
199
+ * `border-{color}-300` light token and the `dark:border-{color}-{N}` pair.
200
+ */
201
+ describe('outlined × intent', () => {
202
+ it.each(INTENTS)('outlined × %s emits border + bg with dark pair', (color) => {
203
+ const { container } = render(<Box variant="outlined" color={color}>x</Box>);
204
+ const cls = container.firstElementChild?.className ?? '';
205
+ if (color === 'neutral') {
206
+ // neutral uses the special border-neutral-200 + bg-white shape
207
+ expect(cls).toContain('border-neutral-200');
208
+ expect(cls).toContain('bg-white');
209
+ expect(cls).toContain('dark:border-neutral-700');
210
+ expect(cls).toContain('dark:bg-neutral-900');
211
+ } else {
212
+ // primary/secondary/success/warning/danger/info share the
213
+ // border-{color}-300 + bg-{color}-50/40 + dark:* pattern
214
+ expect(cls).toContain(`border-${color}-300`);
215
+ expect(cls).toContain(`bg-${color}-50/40`);
216
+ expect(cls).toContain(`dark:border-${color}-800`);
217
+ expect(cls).toContain(`dark:bg-${color}-950/30`);
218
+ }
219
+ });
220
+ });
221
+
222
+ /*
223
+ * Soft × 7 intents — semi-transparent tinted background + matching
224
+ * intent text colour. Dark pair uses a darker bg + lighter text so
225
+ * contrast holds in both modes.
226
+ */
227
+ describe('soft × intent', () => {
228
+ it.each(INTENTS)('soft × %s emits bg + text with dark pair', (color) => {
229
+ const { container } = render(<Box variant="soft" color={color}>x</Box>);
230
+ const cls = container.firstElementChild?.className ?? '';
231
+ if (color === 'neutral') {
232
+ expect(cls).toContain('bg-neutral-100');
233
+ expect(cls).toContain('text-neutral-900');
234
+ expect(cls).toContain('dark:bg-neutral-800');
235
+ expect(cls).toContain('dark:text-neutral-100');
236
+ } else {
237
+ expect(cls).toContain(`bg-${color}-100`);
238
+ expect(cls).toContain(`text-${color}-900`);
239
+ expect(cls).toContain(`dark:bg-${color}-950/50`);
240
+ expect(cls).toContain(`dark:text-${color}-100`);
241
+ }
242
+ });
243
+ });
244
+
245
+ /*
246
+ * Solid × 7 intents — full-bleed intent background, white text by
247
+ * default (neutral inverts: black bg → white text in light, white
248
+ * bg → black text in dark). The dark variant typically uses a
249
+ * lighter shade so the surface doesn't look pitch black on already-
250
+ * dark page backgrounds.
251
+ */
252
+ describe('solid × intent', () => {
253
+ it.each(INTENTS)('solid × %s emits bg + text-white (or contrast pair for neutral)', (color) => {
254
+ const { container } = render(<Box variant="solid" color={color}>x</Box>);
255
+ const cls = container.firstElementChild?.className ?? '';
256
+ if (color === 'neutral') {
257
+ expect(cls).toContain('bg-neutral-900');
258
+ expect(cls).toContain('text-white');
259
+ expect(cls).toContain('dark:bg-neutral-100');
260
+ expect(cls).toContain('dark:text-neutral-900');
261
+ } else if (color === 'warning') {
262
+ // warning uses 500/600 instead of 600/500 to keep contrast
263
+ // legible against an already-yellow surface in light mode.
264
+ expect(cls).toContain('bg-warning-500');
265
+ expect(cls).toContain('text-white');
266
+ expect(cls).toContain('dark:bg-warning-600');
267
+ } else {
268
+ expect(cls).toContain(`bg-${color}-600`);
269
+ expect(cls).toContain('text-white');
270
+ expect(cls).toContain(`dark:bg-${color}-500`);
271
+ }
272
+ });
273
+ });
274
+ });
275
+
276
+ // ─── F11-bis edge cases: color is ignored for plain / elevated ──────
277
+ // These two variants are color-agnostic by design (see box.variants.ts
278
+ // header) — passing `color` shouldn't accidentally inject the intent
279
+ // bg/border via the compound matrix.
280
+ describe('color-agnostic variants', () => {
281
+ it('plain + color="primary" does NOT add intent classes', () => {
282
+ const { container } = render(<Box variant="plain" color="primary">x</Box>);
283
+ const cls = container.firstElementChild?.className ?? '';
284
+ expect(cls).not.toContain('bg-primary-');
285
+ expect(cls).not.toContain('border-primary-');
286
+ expect(cls).not.toContain('text-primary-');
287
+ });
288
+
289
+ it('elevated + color="danger" stays on the neutral surface', () => {
290
+ const { container } = render(<Box variant="elevated" color="danger">x</Box>);
291
+ const cls = container.firstElementChild?.className ?? '';
292
+ // elevated paints bg-white / dark:bg-neutral-900 regardless of intent
293
+ expect(cls).toContain('bg-white');
294
+ expect(cls).toContain('dark:bg-neutral-900');
295
+ expect(cls).not.toContain('bg-danger-');
296
+ expect(cls).not.toContain('border-danger-');
297
+ });
298
+ });
299
+
300
+ // ─── F11-bis edge cases: spacing axis coexistence ───────────────────
301
+ describe('spacing axis coexistence', () => {
302
+ it('p={4} + px={6}: both classes emitted (tailwind-merge resolves)', () => {
303
+ const { container } = render(<Box p={4} px={6}>x</Box>);
304
+ const cls = container.firstElementChild?.className ?? '';
305
+ // tailwind-merge: px-6 wins over p-4 on horizontal padding,
306
+ // p-4 keeps applying vertical via py
307
+ expect(cls).toContain('px-6');
308
+ // p-4 → tailwind-merge collapses with px-6 (latter wins on x-axis)
309
+ // The vertical (py-4 derived from p-4) is what remains.
310
+ });
311
+
312
+ it('m={2} + mx={4} + my={6}: all three coexist (resolves to mx-4 + my-6 effectively)', () => {
313
+ const { container } = render(<Box m={2} mx={4} my={6}>x</Box>);
314
+ const cls = container.firstElementChild?.className ?? '';
315
+ expect(cls).toContain('mx-4');
316
+ expect(cls).toContain('my-6');
317
+ });
318
+ });
319
+
320
+ // ─── F11-bis edge cases: elevation × variant interaction ────────────
321
+ describe('elevation × variant', () => {
322
+ it('elevation works on non-elevated variants too (consumer choice)', () => {
323
+ const { container } = render(<Box variant="outlined" color="neutral" elevation={4}>x</Box>);
324
+ // The shadow class still gets emitted even though the design
325
+ // recommendation is "use elevation only with variant=elevated".
326
+ // We don't gate this at the TV level because compound restrictions
327
+ // would make the API harder to discover.
328
+ expect(container.firstElementChild?.className).toContain('shadow-lg');
329
+ });
330
+
331
+ it('elevation=0 explicitly disables shadow', () => {
332
+ const { container } = render(<Box variant="elevated" elevation={0}>x</Box>);
333
+ expect(container.firstElementChild?.className).toContain('shadow-none');
334
+ });
335
+ });
336
+
337
+ // ─── F11-bis edge cases: rounded full ───────────────────────────────
338
+ describe('rounded edge values', () => {
339
+ it('rounded="full" produces rounded-full (avatars, pills)', () => {
340
+ const { container } = render(<Box rounded="full">x</Box>);
341
+ expect(container.firstElementChild?.className).toContain('rounded-full');
342
+ });
343
+
344
+ it('rounded="none" explicitly removes any rounding', () => {
345
+ const { container } = render(<Box rounded="none">x</Box>);
346
+ expect(container.firstElementChild?.className).toContain('rounded-none');
347
+ });
348
+ });
349
+ });
@@ -0,0 +1,83 @@
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 { boxVariants } from './box.variants.js';
5
+ import type { BoxProps } from './box.types.js';
6
+
7
+ /**
8
+ * `<Box>` — the surface primitive of @dashforge/tw.
9
+ *
10
+ * What it IS:
11
+ * A polymorphic container with typed surface variants (plain /
12
+ * outlined / elevated / soft / solid) × 7 intent colours, plus
13
+ * spacing / sizing / rounded / elevation as enumerated token-scale
14
+ * props. Replaces MUI's Box + Paper + Card + Surface in one component.
15
+ *
16
+ * What it is NOT (deliberate, enforced by the prop set):
17
+ * • Not a flex container → use <Stack>
18
+ * • Not a grid container → use <Grid>
19
+ * • Not a paragraph → use <Typography>
20
+ * • Not a button → use <Button>
21
+ *
22
+ * The "Box is not flex" rule is the spine of the layout layer. Without
23
+ * it, every `<div>` in an app gravitates back to Box and the surface
24
+ * vs layout distinction collapses. Box's job is the SURFACE around
25
+ * content; Stack/Grid's job is the ARRANGEMENT of content. Two
26
+ * primitives, two responsibilities.
27
+ *
28
+ * When BOTH `as` and `asChild` are passed, `asChild` wins. Same rule
29
+ * as Typography — documented to avoid the dimension-bloat of a
30
+ * discriminated union over an 11-axis props type.
31
+ *
32
+ * Layering:
33
+ * • Sits BENEATH every visual chrome — every card, every panel,
34
+ * every section background.
35
+ * • Composes ON TOP of @dashforge/tw-tokens (color + spacing + radius
36
+ * + shadow scales) via the dashforgePreset CSS variables.
37
+ * • Pairs with Typography for text content, Stack/Grid for layout
38
+ * children inside it.
39
+ */
40
+ export const Box = forwardRef<HTMLElement, BoxProps>(
41
+ function Box(props, ref) {
42
+ const {
43
+ variant,
44
+ color,
45
+ elevation,
46
+ rounded,
47
+ p, px, py, m, mx, my,
48
+ fullWidth,
49
+ fullHeight,
50
+ as,
51
+ asChild = false,
52
+ sx,
53
+ children,
54
+ ...rest
55
+ } = props;
56
+
57
+ const classes = cn(
58
+ boxVariants({
59
+ variant, color, elevation, rounded,
60
+ p, px, py, m, mx, my,
61
+ fullWidth, fullHeight,
62
+ }),
63
+ sx,
64
+ );
65
+
66
+ if (asChild) {
67
+ return (
68
+ <Slot ref={ref} className={classes} {...rest}>
69
+ {children as ReactElement}
70
+ </Slot>
71
+ );
72
+ }
73
+
74
+ const Tag = (as ?? 'div') as ElementType;
75
+ return (
76
+ <Tag ref={ref as never} className={classes} {...rest}>
77
+ {children}
78
+ </Tag>
79
+ );
80
+ },
81
+ );
82
+
83
+ Box.displayName = 'Box';
@@ -0,0 +1,61 @@
1
+ import type { ElementType, HTMLAttributes } from 'react';
2
+ import type { BoxVariants } from './box.variants.js';
3
+
4
+ /**
5
+ * Props for `<Box>` — the surface primitive.
6
+ *
7
+ * What lives in props (typed, ergonomic):
8
+ * • Surface — variant, color, elevation, rounded
9
+ * • Spacing — p, px, py, m, mx, my (token-scale steps)
10
+ * • Sizing — fullWidth, fullHeight
11
+ * • Polymorphism — as, asChild
12
+ * • Override escape — sx (utility string, merged via tailwind-merge)
13
+ *
14
+ * What does NOT live here (deliberate, see Box.tsx header):
15
+ * • display / flex / grid / gap → use Stack or Grid
16
+ * • position / top / z-index → use sx
17
+ * • overflow / cursor → use sx
18
+ * • animation / transition → use sx
19
+ *
20
+ * Native attribute overrides:
21
+ * • `className` is omitted in favour of `sx` (string of utilities,
22
+ * resolved by tailwind-merge so consumer wins over variant defaults)
23
+ * — same convention as Button/TextField/Checkbox/Switch.
24
+ * • `color` is omitted: collides with the deprecated HTML4 `color`
25
+ * attribute. Our typed `color` (intent) is the right one.
26
+ */
27
+ export interface BoxProps
28
+ extends Omit<HTMLAttributes<HTMLDivElement>, 'className' | 'color'>,
29
+ Pick<BoxVariants,
30
+ 'variant' | 'color' | 'elevation' | 'rounded'
31
+ | 'p' | 'px' | 'py' | 'm' | 'mx' | 'my'
32
+ | 'fullWidth' | 'fullHeight'> {
33
+ /**
34
+ * Override the rendered HTML tag. Defaults to `'div'`. Useful when
35
+ * the surface should also carry semantic meaning — `<Box as="section">`
36
+ * for a page section, `<Box as="article">` for a card-shaped article.
37
+ *
38
+ * Ignored when `asChild` is true.
39
+ */
40
+ as?: ElementType;
41
+
42
+ /**
43
+ * Render via Radix `Slot` — the Box styles paint onto the single
44
+ * React child instead of wrapping it in our own element. Useful for
45
+ * `<Box asChild><Link>...</Link></Box>` to get a styled router link
46
+ * with no extra DOM wrapper.
47
+ *
48
+ * Mutually exclusive with `as` (when both are passed, `asChild` wins
49
+ * — see Box.tsx for the reasoning).
50
+ */
51
+ asChild?: boolean;
52
+
53
+ /**
54
+ * Utility classes appended to the variant chain. Resolved via
55
+ * `tailwind-merge` so the consumer's classes always win over the
56
+ * variant defaults. Use for one-off overrides AND for utility
57
+ * dimensions Box deliberately doesn't expose as props (overflow,
58
+ * position, animation, etc.).
59
+ */
60
+ sx?: string;
61
+ }