@dashforge/tw 0.1.0-beta → 0.2.1-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.
- package/A11Y.md +130 -0
- package/CHANGELOG.md +231 -0
- package/dist/index.d.ts +1 -82
- package/dist/index.esm.js +1608 -11
- package/dist/src/components/AspectRatio/AspectRatio.d.ts +36 -0
- package/dist/src/components/AspectRatio/AspectRatio.d.ts.map +1 -0
- package/dist/src/components/AspectRatio/aspectRatio.types.d.ts +50 -0
- package/dist/src/components/AspectRatio/aspectRatio.types.d.ts.map +1 -0
- package/dist/src/components/Box/Box.d.ts +36 -0
- package/dist/src/components/Box/Box.d.ts.map +1 -0
- package/dist/src/components/Box/box.types.d.ts +54 -0
- package/dist/src/components/Box/box.types.d.ts.map +1 -0
- package/dist/src/components/Box/box.variants.d.ts +402 -0
- package/dist/src/components/Box/box.variants.d.ts.map +1 -0
- package/dist/src/components/Button/Button.d.ts.map +1 -1
- package/dist/src/components/Checkbox/Checkbox.d.ts.map +1 -1
- package/dist/src/components/Container/Container.d.ts +35 -0
- package/dist/src/components/Container/Container.d.ts.map +1 -0
- package/dist/src/components/Container/container.types.d.ts +41 -0
- package/dist/src/components/Container/container.types.d.ts.map +1 -0
- package/dist/src/components/Container/container.variants.d.ts +93 -0
- package/dist/src/components/Container/container.variants.d.ts.map +1 -0
- package/dist/src/components/Divider/Divider.d.ts +50 -0
- package/dist/src/components/Divider/Divider.d.ts.map +1 -0
- package/dist/src/components/Divider/divider.types.d.ts +47 -0
- package/dist/src/components/Divider/divider.types.d.ts.map +1 -0
- package/dist/src/components/Divider/divider.variants.d.ts +129 -0
- package/dist/src/components/Divider/divider.variants.d.ts.map +1 -0
- package/dist/src/components/Grid/Grid.d.ts +32 -0
- package/dist/src/components/Grid/Grid.d.ts.map +1 -0
- package/dist/src/components/Grid/grid.types.d.ts +103 -0
- package/dist/src/components/Grid/grid.types.d.ts.map +1 -0
- package/dist/src/components/Grid/grid.variants.d.ts +453 -0
- package/dist/src/components/Grid/grid.variants.d.ts.map +1 -0
- package/dist/src/components/NumberField/NumberField.d.ts.map +1 -1
- package/dist/src/components/RadioGroup/RadioGroup.d.ts.map +1 -1
- package/dist/src/components/Stack/Stack.d.ts +24 -0
- package/dist/src/components/Stack/Stack.d.ts.map +1 -0
- package/dist/src/components/Stack/stack.types.d.ts +61 -0
- package/dist/src/components/Stack/stack.types.d.ts.map +1 -0
- package/dist/src/components/Stack/stack.variants.d.ts +163 -0
- package/dist/src/components/Stack/stack.variants.d.ts.map +1 -0
- package/dist/src/components/Typography/Typography.d.ts +42 -0
- package/dist/src/components/Typography/Typography.d.ts.map +1 -0
- package/dist/src/components/Typography/typography.types.d.ts +61 -0
- package/dist/src/components/Typography/typography.types.d.ts.map +1 -0
- package/dist/src/components/Typography/typography.variants.d.ts +167 -0
- package/dist/src/components/Typography/typography.variants.d.ts.map +1 -0
- package/dist/src/components/VisuallyHidden/VisuallyHidden.d.ts +42 -0
- package/dist/src/components/VisuallyHidden/VisuallyHidden.d.ts.map +1 -0
- package/dist/src/components/VisuallyHidden/visuallyHidden.types.d.ts +42 -0
- package/dist/src/components/VisuallyHidden/visuallyHidden.types.d.ts.map +1 -0
- package/dist/src/index.d.ts +23 -1
- package/dist/src/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/components/AspectRatio/AspectRatio.test.tsx +173 -0
- package/src/components/AspectRatio/AspectRatio.tsx +73 -0
- package/src/components/AspectRatio/aspectRatio.types.ts +54 -0
- package/src/components/Box/Box.test.tsx +349 -0
- package/src/components/Box/Box.tsx +83 -0
- package/src/components/Box/box.types.ts +61 -0
- package/src/components/Box/box.variants.ts +211 -0
- package/src/components/Button/Button.tsx +11 -0
- package/src/components/Checkbox/Checkbox.tsx +26 -2
- package/src/components/Container/Container.test.tsx +209 -0
- package/src/components/Container/Container.tsx +74 -0
- package/src/components/Container/container.types.ts +45 -0
- package/src/components/Container/container.variants.ts +81 -0
- package/src/components/Divider/Divider.test.tsx +241 -0
- package/src/components/Divider/Divider.tsx +140 -0
- package/src/components/Divider/divider.types.ts +52 -0
- package/src/components/Divider/divider.variants.ts +115 -0
- package/src/components/Grid/Grid.test.tsx +321 -0
- package/src/components/Grid/Grid.tsx +148 -0
- package/src/components/Grid/grid.types.ts +112 -0
- package/src/components/Grid/grid.variants.ts +133 -0
- package/src/components/NumberField/NumberField.tsx +30 -2
- package/src/components/RadioGroup/RadioGroup.tsx +23 -1
- package/src/components/Stack/Stack.test.tsx +309 -0
- package/src/components/Stack/Stack.tsx +115 -0
- package/src/components/Stack/stack.types.ts +68 -0
- package/src/components/Stack/stack.variants.ts +80 -0
- package/src/components/Typography/Typography.test.tsx +230 -0
- package/src/components/Typography/Typography.tsx +112 -0
- package/src/components/Typography/typography.types.ts +65 -0
- package/src/components/Typography/typography.variants.ts +113 -0
- package/src/components/VisuallyHidden/VisuallyHidden.test.tsx +86 -0
- package/src/components/VisuallyHidden/VisuallyHidden.tsx +59 -0
- package/src/components/VisuallyHidden/visuallyHidden.types.ts +45 -0
- package/src/index.ts +50 -1
- package/LICENSE +0 -21
- package/dist/components/AppShell/AppShell.d.ts +0 -32
- package/dist/components/AppShell/AppShell.d.ts.map +0 -1
- package/dist/components/AppShell/appShell.types.d.ts +0 -62
- package/dist/components/AppShell/appShell.types.d.ts.map +0 -1
- package/dist/components/AppShell/appShell.variants.d.ts +0 -65
- package/dist/components/AppShell/appShell.variants.d.ts.map +0 -1
- package/dist/components/Autocomplete/Autocomplete.d.ts +0 -32
- package/dist/components/Autocomplete/Autocomplete.d.ts.map +0 -1
- package/dist/components/Autocomplete/autocomplete.types.d.ts +0 -214
- package/dist/components/Autocomplete/autocomplete.types.d.ts.map +0 -1
- package/dist/components/Autocomplete/autocomplete.variants.d.ts +0 -214
- package/dist/components/Autocomplete/autocomplete.variants.d.ts.map +0 -1
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +0 -23
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts.map +0 -1
- package/dist/components/Breadcrumbs/breadcrumbs.types.d.ts +0 -98
- package/dist/components/Breadcrumbs/breadcrumbs.types.d.ts.map +0 -1
- package/dist/components/Breadcrumbs/breadcrumbs.variants.d.ts +0 -85
- package/dist/components/Breadcrumbs/breadcrumbs.variants.d.ts.map +0 -1
- package/dist/components/Button/Button.d.ts +0 -44
- package/dist/components/Button/Button.d.ts.map +0 -1
- package/dist/components/Button/button.types.d.ts +0 -66
- package/dist/components/Button/button.types.d.ts.map +0 -1
- package/dist/components/Button/button.variants.d.ts +0 -104
- package/dist/components/Button/button.variants.d.ts.map +0 -1
- package/dist/components/Checkbox/Checkbox.d.ts +0 -31
- package/dist/components/Checkbox/Checkbox.d.ts.map +0 -1
- package/dist/components/Checkbox/checkbox.types.d.ts +0 -86
- package/dist/components/Checkbox/checkbox.types.d.ts.map +0 -1
- package/dist/components/Checkbox/checkbox.variants.d.ts +0 -109
- package/dist/components/Checkbox/checkbox.variants.d.ts.map +0 -1
- package/dist/components/ConfirmDialog/ConfirmDialog.d.ts +0 -38
- package/dist/components/ConfirmDialog/ConfirmDialog.d.ts.map +0 -1
- package/dist/components/ConfirmDialog/confirmDialog.types.d.ts +0 -80
- package/dist/components/ConfirmDialog/confirmDialog.types.d.ts.map +0 -1
- package/dist/components/ConfirmDialog/confirmDialog.variants.d.ts +0 -90
- package/dist/components/ConfirmDialog/confirmDialog.variants.d.ts.map +0 -1
- package/dist/components/DateTimePicker/DateTimePicker.d.ts +0 -49
- package/dist/components/DateTimePicker/DateTimePicker.d.ts.map +0 -1
- package/dist/components/DateTimePicker/dateTimePicker.types.d.ts +0 -95
- package/dist/components/DateTimePicker/dateTimePicker.types.d.ts.map +0 -1
- package/dist/components/DateTimePicker/dateTimePicker.variants.d.ts +0 -165
- package/dist/components/DateTimePicker/dateTimePicker.variants.d.ts.map +0 -1
- package/dist/components/LeftNav/LeftNav.d.ts +0 -34
- package/dist/components/LeftNav/LeftNav.d.ts.map +0 -1
- package/dist/components/LeftNav/leftNav.types.d.ts +0 -136
- package/dist/components/LeftNav/leftNav.types.d.ts.map +0 -1
- package/dist/components/LeftNav/leftNav.variants.d.ts +0 -143
- package/dist/components/LeftNav/leftNav.variants.d.ts.map +0 -1
- package/dist/components/NumberField/NumberField.d.ts +0 -18
- package/dist/components/NumberField/NumberField.d.ts.map +0 -1
- package/dist/components/NumberField/numberField.types.d.ts +0 -79
- package/dist/components/NumberField/numberField.types.d.ts.map +0 -1
- package/dist/components/NumberField/numberField.variants.d.ts +0 -169
- package/dist/components/NumberField/numberField.variants.d.ts.map +0 -1
- package/dist/components/OTPField/OTPField.d.ts +0 -25
- package/dist/components/OTPField/OTPField.d.ts.map +0 -1
- package/dist/components/OTPField/otpField.types.d.ts +0 -74
- package/dist/components/OTPField/otpField.types.d.ts.map +0 -1
- package/dist/components/OTPField/otpField.variants.d.ts +0 -105
- package/dist/components/OTPField/otpField.variants.d.ts.map +0 -1
- package/dist/components/RadioGroup/RadioGroup.d.ts +0 -35
- package/dist/components/RadioGroup/RadioGroup.d.ts.map +0 -1
- package/dist/components/RadioGroup/radioGroup.types.d.ts +0 -103
- package/dist/components/RadioGroup/radioGroup.types.d.ts.map +0 -1
- package/dist/components/RadioGroup/radioGroup.variants.d.ts +0 -166
- package/dist/components/RadioGroup/radioGroup.variants.d.ts.map +0 -1
- package/dist/components/Snackbar/Snackbar.d.ts +0 -37
- package/dist/components/Snackbar/Snackbar.d.ts.map +0 -1
- package/dist/components/Snackbar/snackbar.types.d.ts +0 -86
- package/dist/components/Snackbar/snackbar.types.d.ts.map +0 -1
- package/dist/components/Snackbar/snackbar.variants.d.ts +0 -153
- package/dist/components/Snackbar/snackbar.variants.d.ts.map +0 -1
- package/dist/components/Switch/Switch.d.ts +0 -15
- package/dist/components/Switch/Switch.d.ts.map +0 -1
- package/dist/components/Switch/switch.types.d.ts +0 -47
- package/dist/components/Switch/switch.types.d.ts.map +0 -1
- package/dist/components/Switch/switch.variants.d.ts +0 -105
- package/dist/components/Switch/switch.variants.d.ts.map +0 -1
- package/dist/components/TextField/TextField.d.ts +0 -25
- package/dist/components/TextField/TextField.d.ts.map +0 -1
- package/dist/components/TextField/textField.types.d.ts +0 -72
- package/dist/components/TextField/textField.types.d.ts.map +0 -1
- package/dist/components/TextField/textField.variants.d.ts +0 -160
- package/dist/components/TextField/textField.variants.d.ts.map +0 -1
- package/dist/components/Textarea/Textarea.d.ts +0 -16
- package/dist/components/Textarea/Textarea.d.ts.map +0 -1
- package/dist/components/Textarea/textarea.types.d.ts +0 -63
- package/dist/components/Textarea/textarea.types.d.ts.map +0 -1
- package/dist/components/Textarea/textarea.variants.d.ts +0 -197
- package/dist/components/Textarea/textarea.variants.d.ts.map +0 -1
- package/dist/components/TopBar/TopBar.d.ts +0 -33
- package/dist/components/TopBar/TopBar.d.ts.map +0 -1
- package/dist/components/TopBar/topBar.types.d.ts +0 -49
- package/dist/components/TopBar/topBar.types.d.ts.map +0 -1
- package/dist/components/TopBar/topBar.variants.d.ts +0 -79
- package/dist/components/TopBar/topBar.variants.d.ts.map +0 -1
- package/dist/components/_shared/resolveValidationState.d.ts +0 -42
- package/dist/components/_shared/resolveValidationState.d.ts.map +0 -1
- package/dist/hooks/useAccessState.d.ts +0 -37
- package/dist/hooks/useAccessState.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/tsconfig.lib.tsbuildinfo +0 -1
- package/dist/utils/cn.d.ts +0 -26
- package/dist/utils/cn.d.ts.map +0 -1
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { describe, it, expect } from 'vitest';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
import { AspectRatio } from './AspectRatio.js';
|
|
5
|
+
|
|
6
|
+
describe('<AspectRatio>', () => {
|
|
7
|
+
// ─── Default rendering ──────────────────────────────────────────────
|
|
8
|
+
describe('default rendering', () => {
|
|
9
|
+
it('renders a <div> by default', () => {
|
|
10
|
+
const { container } = render(<AspectRatio>x</AspectRatio>);
|
|
11
|
+
expect(container.firstElementChild?.tagName).toBe('DIV');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('default ratio is 1 (square)', () => {
|
|
15
|
+
const { container } = render(<AspectRatio>x</AspectRatio>);
|
|
16
|
+
const el = container.firstElementChild as HTMLElement;
|
|
17
|
+
expect(el.style.aspectRatio).toBe('1 / 1');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('always has w-full baseline', () => {
|
|
21
|
+
const { container } = render(<AspectRatio>x</AspectRatio>);
|
|
22
|
+
expect(container.firstElementChild?.className).toContain('w-full');
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// ─── ratio prop ─────────────────────────────────────────────────────
|
|
27
|
+
describe('ratio', () => {
|
|
28
|
+
it('numeric ratio 16/9 → "1.7777… / 1"', () => {
|
|
29
|
+
const { container } = render(<AspectRatio ratio={16 / 9}>x</AspectRatio>);
|
|
30
|
+
const el = container.firstElementChild as HTMLElement;
|
|
31
|
+
// 16/9 ≈ 1.7777, formatted as "<number> / 1"
|
|
32
|
+
expect(el.style.aspectRatio).toMatch(/^1\.\d+ \/ 1$/);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('numeric ratio 4/3', () => {
|
|
36
|
+
const { container } = render(<AspectRatio ratio={4 / 3}>x</AspectRatio>);
|
|
37
|
+
const el = container.firstElementChild as HTMLElement;
|
|
38
|
+
expect(el.style.aspectRatio).toMatch(/^1\.\d+ \/ 1$/);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('string ratio "16 / 9" passes through', () => {
|
|
42
|
+
const { container } = render(<AspectRatio ratio="16 / 9">x</AspectRatio>);
|
|
43
|
+
const el = container.firstElementChild as HTMLElement;
|
|
44
|
+
expect(el.style.aspectRatio).toBe('16 / 9');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('string ratio "21/9" passes through (ultrawide)', () => {
|
|
48
|
+
const { container } = render(<AspectRatio ratio="21/9">x</AspectRatio>);
|
|
49
|
+
const el = container.firstElementChild as HTMLElement;
|
|
50
|
+
expect(el.style.aspectRatio).toBe('21/9');
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// ─── Override ───────────────────────────────────────────────────────
|
|
55
|
+
describe('override', () => {
|
|
56
|
+
it('sx adds utility classes', () => {
|
|
57
|
+
const { container } = render(
|
|
58
|
+
<AspectRatio ratio={16 / 9} sx="rounded-xl overflow-hidden">
|
|
59
|
+
x
|
|
60
|
+
</AspectRatio>,
|
|
61
|
+
);
|
|
62
|
+
const cls = container.firstElementChild?.className ?? '';
|
|
63
|
+
expect(cls).toContain('rounded-xl');
|
|
64
|
+
expect(cls).toContain('overflow-hidden');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('user style merges with aspect-ratio', () => {
|
|
68
|
+
const { container } = render(
|
|
69
|
+
<AspectRatio ratio={1} style={{ backgroundColor: 'red' }}>x</AspectRatio>,
|
|
70
|
+
);
|
|
71
|
+
const el = container.firstElementChild as HTMLElement;
|
|
72
|
+
expect(el.style.backgroundColor).toBe('red');
|
|
73
|
+
expect(el.style.aspectRatio).toBe('1 / 1');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('user style aspect-ratio overrides the prop (last wins)', () => {
|
|
77
|
+
const { container } = render(
|
|
78
|
+
<AspectRatio ratio={1} style={{ aspectRatio: '2 / 1' }}>x</AspectRatio>,
|
|
79
|
+
);
|
|
80
|
+
const el = container.firstElementChild as HTMLElement;
|
|
81
|
+
// Inline style merge — user's later spread wins
|
|
82
|
+
expect(el.style.aspectRatio).toBe('2 / 1');
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// ─── Polymorphism ───────────────────────────────────────────────────
|
|
87
|
+
describe('polymorphism', () => {
|
|
88
|
+
it('as="figure" renders <figure>', () => {
|
|
89
|
+
const { container } = render(
|
|
90
|
+
<AspectRatio as="figure" ratio={1}>x</AspectRatio>,
|
|
91
|
+
);
|
|
92
|
+
expect(container.firstElementChild?.tagName).toBe('FIGURE');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('as="picture" works for responsive image markup', () => {
|
|
96
|
+
const { container } = render(
|
|
97
|
+
<AspectRatio as="picture" ratio={16 / 9}>
|
|
98
|
+
<img src="x.jpg" alt="" />
|
|
99
|
+
</AspectRatio>,
|
|
100
|
+
);
|
|
101
|
+
expect(container.firstElementChild?.tagName).toBe('PICTURE');
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// ─── Child rendering ────────────────────────────────────────────────
|
|
106
|
+
describe('child rendering', () => {
|
|
107
|
+
it('renders an <img> child', () => {
|
|
108
|
+
const { container } = render(
|
|
109
|
+
<AspectRatio ratio={16 / 9}>
|
|
110
|
+
<img src="hero.jpg" alt="hero" className="w-full h-full object-cover" />
|
|
111
|
+
</AspectRatio>,
|
|
112
|
+
);
|
|
113
|
+
const img = container.querySelector('img');
|
|
114
|
+
expect(img?.getAttribute('src')).toBe('hero.jpg');
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('renders multiple children (e.g. overlay pattern)', () => {
|
|
118
|
+
const { container } = render(
|
|
119
|
+
<AspectRatio ratio={16 / 9}>
|
|
120
|
+
<img src="hero.jpg" alt="hero" />
|
|
121
|
+
<div className="absolute inset-0 bg-black/40" />
|
|
122
|
+
</AspectRatio>,
|
|
123
|
+
);
|
|
124
|
+
expect(container.firstElementChild?.children.length).toBe(2);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// ─── Pass-through ───────────────────────────────────────────────────
|
|
129
|
+
it('forwards data-* + aria-*', () => {
|
|
130
|
+
const { container } = render(
|
|
131
|
+
<AspectRatio data-testid="ar" aria-label="hero">x</AspectRatio>,
|
|
132
|
+
);
|
|
133
|
+
const el = container.firstElementChild;
|
|
134
|
+
expect(el?.getAttribute('data-testid')).toBe('ar');
|
|
135
|
+
expect(el?.getAttribute('aria-label')).toBe('hero');
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// ─── F11-bis edge cases ─────────────────────────────────────────────
|
|
139
|
+
describe('extreme ratio values', () => {
|
|
140
|
+
it('ratio="21 / 9" (ultrawide cinema) passes through verbatim', () => {
|
|
141
|
+
const { container } = render(<AspectRatio ratio="21 / 9">x</AspectRatio>);
|
|
142
|
+
expect((container.firstElementChild as HTMLElement).style.aspectRatio).toBe('21 / 9');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('ratio="9 / 16" (portrait video) passes through verbatim', () => {
|
|
146
|
+
const { container } = render(<AspectRatio ratio="9 / 16">x</AspectRatio>);
|
|
147
|
+
expect((container.firstElementChild as HTMLElement).style.aspectRatio).toBe('9 / 16');
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('numeric tiny ratio (0.5) formats as "0.5 / 1"', () => {
|
|
151
|
+
const { container } = render(<AspectRatio ratio={0.5}>x</AspectRatio>);
|
|
152
|
+
expect((container.firstElementChild as HTMLElement).style.aspectRatio).toBe('0.5 / 1');
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('numeric large ratio (3) formats as "3 / 1"', () => {
|
|
156
|
+
const { container } = render(<AspectRatio ratio={3}>x</AspectRatio>);
|
|
157
|
+
expect((container.firstElementChild as HTMLElement).style.aspectRatio).toBe('3 / 1');
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
describe('rounded clipped media pattern (the #1 doc gotcha)', () => {
|
|
162
|
+
it('rounded + overflow-hidden both end up on the className', () => {
|
|
163
|
+
const { container } = render(
|
|
164
|
+
<AspectRatio ratio={16 / 9} sx="rounded-2xl overflow-hidden">
|
|
165
|
+
<img src="x.jpg" alt="" className="w-full h-full object-cover" />
|
|
166
|
+
</AspectRatio>,
|
|
167
|
+
);
|
|
168
|
+
const cls = container.firstElementChild?.className ?? '';
|
|
169
|
+
expect(cls).toContain('rounded-2xl');
|
|
170
|
+
expect(cls).toContain('overflow-hidden');
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
});
|
|
@@ -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
|
+
});
|