@object-ui/components 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/.turbo/turbo-build.log +12 -12
  2. package/CHANGELOG.md +19 -0
  3. package/dist/index.css +1 -1
  4. package/dist/index.js +19610 -19344
  5. package/dist/index.umd.cjs +29 -29
  6. package/dist/src/custom/index.d.ts +2 -0
  7. package/dist/src/custom/view-skeleton.d.ts +37 -0
  8. package/dist/src/custom/view-states.d.ts +33 -0
  9. package/package.json +17 -17
  10. package/src/__tests__/__snapshots__/snapshot-critical.test.tsx.snap +811 -0
  11. package/src/__tests__/__snapshots__/snapshot.test.tsx.snap +327 -0
  12. package/src/__tests__/accessibility.test.tsx +137 -0
  13. package/src/__tests__/api-consistency.test.tsx +596 -0
  14. package/src/__tests__/color-contrast.test.tsx +212 -0
  15. package/src/__tests__/edge-cases.test.tsx +285 -0
  16. package/src/__tests__/snapshot-critical.test.tsx +317 -0
  17. package/src/__tests__/snapshot.test.tsx +205 -0
  18. package/src/__tests__/wcag-audit.test.tsx +493 -0
  19. package/src/custom/index.ts +2 -0
  20. package/src/custom/view-skeleton.tsx +243 -0
  21. package/src/custom/view-states.tsx +153 -0
  22. package/src/renderers/complex/data-table.tsx +28 -13
  23. package/src/renderers/complex/resizable.tsx +20 -17
  24. package/src/renderers/data-display/list.tsx +1 -1
  25. package/src/renderers/data-display/table.tsx +1 -1
  26. package/src/renderers/data-display/tree-view.tsx +2 -1
  27. package/src/renderers/form/form.tsx +10 -6
  28. package/src/renderers/layout/aspect-ratio.tsx +1 -1
  29. package/src/stories-json/Accessibility.mdx +297 -0
  30. package/src/stories-json/EdgeCases.stories.tsx +160 -0
  31. package/src/stories-json/GettingStarted.mdx +89 -0
  32. package/src/stories-json/Introduction.mdx +127 -0
  33. package/src/ui/slider.tsx +6 -2
  34. package/src/stories/Introduction.mdx +0 -61
@@ -0,0 +1,212 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ /**
10
+ * WCAG 2.1 AA Color Contrast Tests.
11
+ *
12
+ * Verifies that key color combinations used in ObjectUI meet WCAG AA
13
+ * contrast ratio requirements:
14
+ * - 4.5:1 for normal text (< 18pt or < 14pt bold)
15
+ * - 3:1 for large text (≥ 18pt or ≥ 14pt bold)
16
+ *
17
+ * Tests both light and dark theme color values.
18
+ * Part of P2.3 Accessibility & Inclusive Design roadmap.
19
+ */
20
+
21
+ import { describe, it, expect } from 'vitest';
22
+
23
+ /**
24
+ * Calculate relative luminance per WCAG 2.1.
25
+ * https://www.w3.org/TR/WCAG21/#dfn-relative-luminance
26
+ */
27
+ function relativeLuminance(r: number, g: number, b: number): number {
28
+ const [rs, gs, bs] = [r, g, b].map((c) => {
29
+ const sRGB = c / 255;
30
+ return sRGB <= 0.03928 ? sRGB / 12.92 : Math.pow((sRGB + 0.055) / 1.055, 2.4);
31
+ });
32
+ return 0.2126 * rs + 0.7152 * gs + 0.0722 * bs;
33
+ }
34
+
35
+ /**
36
+ * Calculate contrast ratio between two colors.
37
+ * https://www.w3.org/TR/WCAG21/#dfn-contrast-ratio
38
+ */
39
+ function contrastRatio(
40
+ fg: [number, number, number],
41
+ bg: [number, number, number]
42
+ ): number {
43
+ const l1 = relativeLuminance(...fg);
44
+ const l2 = relativeLuminance(...bg);
45
+ const lighter = Math.max(l1, l2);
46
+ const darker = Math.min(l1, l2);
47
+ return (lighter + 0.05) / (darker + 0.05);
48
+ }
49
+
50
+ // WCAG AA thresholds
51
+ const AA_NORMAL_TEXT = 4.5;
52
+ const AA_LARGE_TEXT = 3.0;
53
+
54
+ // ── Light Theme Colors (based on Shadcn/Tailwind defaults) ──
55
+
56
+ const light = {
57
+ background: [255, 255, 255] as [number, number, number], // hsl(0 0% 100%)
58
+ foreground: [10, 10, 10] as [number, number, number], // hsl(0 0% 3.9%)
59
+ muted: [245, 245, 245] as [number, number, number], // hsl(0 0% 96.1%)
60
+ mutedForeground: [115, 115, 115] as [number, number, number], // hsl(0 0% 45.1%)
61
+ primary: [24, 24, 27] as [number, number, number], // hsl(240 5.9% 10%)
62
+ primaryForeground: [250, 250, 250] as [number, number, number], // hsl(0 0% 98%)
63
+ destructive: [239, 68, 68] as [number, number, number], // hsl(0 84.2% 60.2%) — red-500
64
+ destructiveForeground: [255, 255, 255] as [number, number, number],
65
+ card: [255, 255, 255] as [number, number, number],
66
+ cardForeground: [10, 10, 10] as [number, number, number],
67
+ border: [229, 229, 229] as [number, number, number], // hsl(0 0% 89.8%)
68
+ accent: [245, 245, 245] as [number, number, number],
69
+ accentForeground: [24, 24, 27] as [number, number, number],
70
+ };
71
+
72
+ // ── Dark Theme Colors (based on Shadcn/Tailwind defaults) ──
73
+
74
+ const dark = {
75
+ background: [10, 10, 10] as [number, number, number], // hsl(0 0% 3.9%)
76
+ foreground: [250, 250, 250] as [number, number, number], // hsl(0 0% 98%)
77
+ muted: [38, 38, 38] as [number, number, number], // hsl(0 0% 14.9%)
78
+ mutedForeground: [163, 163, 163] as [number, number, number], // hsl(0 0% 63.9%)
79
+ primary: [250, 250, 250] as [number, number, number], // hsl(0 0% 98%)
80
+ primaryForeground: [24, 24, 27] as [number, number, number], // hsl(240 5.9% 10%)
81
+ destructive: [239, 68, 68] as [number, number, number], // hsl(0 84.2% 60.2%) — red-500 (same in dark)
82
+ destructiveForeground: [250, 250, 250] as [number, number, number],
83
+ card: [10, 10, 10] as [number, number, number],
84
+ cardForeground: [250, 250, 250] as [number, number, number],
85
+ border: [38, 38, 38] as [number, number, number],
86
+ accent: [38, 38, 38] as [number, number, number],
87
+ accentForeground: [250, 250, 250] as [number, number, number],
88
+ };
89
+
90
+ describe('WCAG 2.1 AA Color Contrast — Light Theme', () => {
91
+ it('foreground on background meets AA for normal text (4.5:1)', () => {
92
+ const ratio = contrastRatio(light.foreground, light.background);
93
+ expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT);
94
+ });
95
+
96
+ it('primary foreground on primary meets AA for normal text', () => {
97
+ const ratio = contrastRatio(light.primaryForeground, light.primary);
98
+ expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT);
99
+ });
100
+
101
+ it('destructive foreground on destructive meets AA for large text (3:1)', () => {
102
+ const ratio = contrastRatio(light.destructiveForeground, light.destructive);
103
+ expect(ratio).toBeGreaterThanOrEqual(AA_LARGE_TEXT);
104
+ });
105
+
106
+ it('muted foreground on background meets AA for large text (3:1)', () => {
107
+ const ratio = contrastRatio(light.mutedForeground, light.background);
108
+ expect(ratio).toBeGreaterThanOrEqual(AA_LARGE_TEXT);
109
+ });
110
+
111
+ it('muted foreground on muted background meets AA for large text (3:1)', () => {
112
+ const ratio = contrastRatio(light.mutedForeground, light.muted);
113
+ expect(ratio).toBeGreaterThanOrEqual(AA_LARGE_TEXT);
114
+ });
115
+
116
+ it('card foreground on card background meets AA for normal text', () => {
117
+ const ratio = contrastRatio(light.cardForeground, light.card);
118
+ expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT);
119
+ });
120
+
121
+ it('accent foreground on accent background meets AA for normal text', () => {
122
+ const ratio = contrastRatio(light.accentForeground, light.accent);
123
+ expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT);
124
+ });
125
+
126
+ it('foreground on muted background meets AA for normal text', () => {
127
+ const ratio = contrastRatio(light.foreground, light.muted);
128
+ expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT);
129
+ });
130
+
131
+ it('primary on background meets AA for normal text', () => {
132
+ const ratio = contrastRatio(light.primary, light.background);
133
+ expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT);
134
+ });
135
+
136
+ it('destructive on background meets AA for large text', () => {
137
+ const ratio = contrastRatio(light.destructive, light.background);
138
+ expect(ratio).toBeGreaterThanOrEqual(AA_LARGE_TEXT);
139
+ });
140
+ });
141
+
142
+ describe('WCAG 2.1 AA Color Contrast — Dark Theme', () => {
143
+ it('foreground on background meets AA for normal text (4.5:1)', () => {
144
+ const ratio = contrastRatio(dark.foreground, dark.background);
145
+ expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT);
146
+ });
147
+
148
+ it('primary foreground on primary meets AA for normal text', () => {
149
+ const ratio = contrastRatio(dark.primaryForeground, dark.primary);
150
+ expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT);
151
+ });
152
+
153
+ it('destructive foreground on destructive meets AA for large text (3:1)', () => {
154
+ const ratio = contrastRatio(dark.destructiveForeground, dark.destructive);
155
+ expect(ratio).toBeGreaterThanOrEqual(AA_LARGE_TEXT);
156
+ });
157
+
158
+ it('muted foreground on background meets AA for large text (3:1)', () => {
159
+ const ratio = contrastRatio(dark.mutedForeground, dark.background);
160
+ expect(ratio).toBeGreaterThanOrEqual(AA_LARGE_TEXT);
161
+ });
162
+
163
+ it('muted foreground on muted background meets AA for large text (3:1)', () => {
164
+ const ratio = contrastRatio(dark.mutedForeground, dark.muted);
165
+ expect(ratio).toBeGreaterThanOrEqual(AA_LARGE_TEXT);
166
+ });
167
+
168
+ it('card foreground on card background meets AA for normal text', () => {
169
+ const ratio = contrastRatio(dark.cardForeground, dark.card);
170
+ expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT);
171
+ });
172
+
173
+ it('accent foreground on accent background meets AA for normal text', () => {
174
+ const ratio = contrastRatio(dark.accentForeground, dark.accent);
175
+ expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT);
176
+ });
177
+
178
+ it('foreground on muted background meets AA for normal text', () => {
179
+ const ratio = contrastRatio(dark.foreground, dark.muted);
180
+ expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT);
181
+ });
182
+
183
+ it('primary on background meets AA for normal text', () => {
184
+ const ratio = contrastRatio(dark.primary, dark.background);
185
+ expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT);
186
+ });
187
+
188
+ it('destructive on background meets AA for large text', () => {
189
+ const ratio = contrastRatio(dark.destructive, dark.background);
190
+ expect(ratio).toBeGreaterThanOrEqual(AA_LARGE_TEXT);
191
+ });
192
+ });
193
+
194
+ describe('WCAG 2.1 AA Color Contrast — Utility Validation', () => {
195
+ it('contrastRatio returns 21:1 for black on white', () => {
196
+ const ratio = contrastRatio([0, 0, 0], [255, 255, 255]);
197
+ expect(ratio).toBeCloseTo(21, 0);
198
+ });
199
+
200
+ it('contrastRatio returns 1:1 for same color', () => {
201
+ const ratio = contrastRatio([128, 128, 128], [128, 128, 128]);
202
+ expect(ratio).toBeCloseTo(1, 1);
203
+ });
204
+
205
+ it('relativeLuminance returns 0 for black', () => {
206
+ expect(relativeLuminance(0, 0, 0)).toBe(0);
207
+ });
208
+
209
+ it('relativeLuminance returns 1 for white', () => {
210
+ expect(relativeLuminance(255, 255, 255)).toBeCloseTo(1, 4);
211
+ });
212
+ });
@@ -0,0 +1,285 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ /**
10
+ * P3.1 Component Quality Audit - Edge Cases
11
+ *
12
+ * Tests key components with edge-case data: null/undefined children,
13
+ * overflow text, empty content, large datasets, and special characters.
14
+ */
15
+
16
+ import { describe, it, expect } from 'vitest';
17
+ import React from 'react';
18
+ import { render, screen } from '@testing-library/react';
19
+ import '@testing-library/jest-dom';
20
+
21
+ import {
22
+ Badge,
23
+ Button,
24
+ Card,
25
+ CardHeader,
26
+ CardTitle,
27
+ CardContent,
28
+ Input,
29
+ Separator,
30
+ Skeleton,
31
+ Progress,
32
+ Alert,
33
+ AlertTitle,
34
+ AlertDescription,
35
+ Label,
36
+ } from '../index';
37
+
38
+ describe('P3.1 Edge Cases', () => {
39
+ // ---------------------------------------------------------------
40
+ // Null / undefined / empty children
41
+ // ---------------------------------------------------------------
42
+ describe('null and empty children', () => {
43
+ it('Badge renders with empty string', () => {
44
+ const { container } = render(<Badge>{''}</Badge>);
45
+ expect(container.firstElementChild).toBeInTheDocument();
46
+ });
47
+
48
+ it('Badge renders with null child', () => {
49
+ const { container } = render(<Badge>{null}</Badge>);
50
+ expect(container.firstElementChild).toBeInTheDocument();
51
+ });
52
+
53
+ it('Badge renders with undefined child', () => {
54
+ const { container } = render(<Badge>{undefined}</Badge>);
55
+ expect(container.firstElementChild).toBeInTheDocument();
56
+ });
57
+
58
+ it('Button renders with empty string', () => {
59
+ render(<Button>{''}</Button>);
60
+ expect(screen.getByRole('button')).toBeInTheDocument();
61
+ });
62
+
63
+ it('Card renders with no children', () => {
64
+ const { container } = render(<Card />);
65
+ expect(container.firstElementChild).toBeInTheDocument();
66
+ });
67
+
68
+ it('CardTitle renders empty', () => {
69
+ const { container } = render(<CardTitle />);
70
+ expect(container.firstElementChild).toBeInTheDocument();
71
+ });
72
+
73
+ it('Alert renders with no children', () => {
74
+ render(<Alert />);
75
+ expect(screen.getByRole('alert')).toBeInTheDocument();
76
+ });
77
+
78
+ it('AlertTitle renders with empty string', () => {
79
+ const { container } = render(<AlertTitle>{''}</AlertTitle>);
80
+ expect(container.firstElementChild).toBeInTheDocument();
81
+ });
82
+
83
+ it('AlertDescription renders with no children', () => {
84
+ const { container } = render(<AlertDescription />);
85
+ expect(container.firstElementChild).toBeInTheDocument();
86
+ });
87
+ });
88
+
89
+ // ---------------------------------------------------------------
90
+ // Very long text / overflow
91
+ // ---------------------------------------------------------------
92
+ describe('overflow and long text', () => {
93
+ const longText = 'A'.repeat(10000);
94
+
95
+ it('Badge handles very long text without crashing', () => {
96
+ const { container } = render(<Badge>{longText}</Badge>);
97
+ expect(container.textContent).toHaveLength(10000);
98
+ });
99
+
100
+ it('Button handles very long text without crashing', () => {
101
+ render(<Button>{longText}</Button>);
102
+ expect(screen.getByRole('button').textContent).toHaveLength(10000);
103
+ });
104
+
105
+ it('CardTitle handles very long text', () => {
106
+ const { container } = render(<CardTitle>{longText}</CardTitle>);
107
+ expect(container.textContent).toHaveLength(10000);
108
+ });
109
+
110
+ it('Input handles very long value', () => {
111
+ render(<Input defaultValue={longText} data-testid="inp" />);
112
+ expect(screen.getByTestId('inp')).toHaveValue(longText);
113
+ });
114
+
115
+ it('Label handles very long text', () => {
116
+ const { container } = render(<Label>{longText}</Label>);
117
+ expect(container.textContent).toHaveLength(10000);
118
+ });
119
+ });
120
+
121
+ // ---------------------------------------------------------------
122
+ // Special characters / unicode / emoji
123
+ // ---------------------------------------------------------------
124
+ describe('special characters and unicode', () => {
125
+ it('Badge renders emoji', () => {
126
+ const { container } = render(<Badge>🚀🎉✨</Badge>);
127
+ expect(container.textContent).toBe('🚀🎉✨');
128
+ });
129
+
130
+ it('Button renders RTL text', () => {
131
+ render(<Button>مرحبا</Button>);
132
+ expect(screen.getByRole('button').textContent).toBe('مرحبا');
133
+ });
134
+
135
+ it('CardTitle renders HTML entities as text', () => {
136
+ const { container } = render(<CardTitle>{'<script>alert("xss")</script>'}</CardTitle>);
137
+ expect(container.textContent).toBe('<script>alert("xss")</script>');
138
+ expect(container.querySelector('script')).toBeNull();
139
+ });
140
+
141
+ it('Input handles emoji value', () => {
142
+ render(<Input defaultValue="Hello 🌍" data-testid="inp" />);
143
+ expect(screen.getByTestId('inp')).toHaveValue('Hello 🌍');
144
+ });
145
+
146
+ it('Alert handles multi-language text', () => {
147
+ render(
148
+ <Alert>
149
+ <AlertTitle>日本語タイトル</AlertTitle>
150
+ <AlertDescription>中文描述 и русский текст</AlertDescription>
151
+ </Alert>
152
+ );
153
+ expect(screen.getByText('日本語タイトル')).toBeInTheDocument();
154
+ expect(screen.getByText('中文描述 и русский текст')).toBeInTheDocument();
155
+ });
156
+ });
157
+
158
+ // ---------------------------------------------------------------
159
+ // Numeric edge cases
160
+ // ---------------------------------------------------------------
161
+ describe('numeric edge cases', () => {
162
+ it('Progress handles value of 0', () => {
163
+ render(<Progress value={0} data-testid="prog" />);
164
+ expect(screen.getByTestId('prog')).toBeInTheDocument();
165
+ });
166
+
167
+ it('Progress handles value of 100', () => {
168
+ render(<Progress value={100} data-testid="prog" />);
169
+ expect(screen.getByTestId('prog')).toBeInTheDocument();
170
+ });
171
+
172
+ it('Progress handles negative value gracefully', () => {
173
+ render(<Progress value={-10} data-testid="prog" />);
174
+ expect(screen.getByTestId('prog')).toBeInTheDocument();
175
+ });
176
+
177
+ it('Progress handles value > 100 gracefully', () => {
178
+ render(<Progress value={200} data-testid="prog" />);
179
+ expect(screen.getByTestId('prog')).toBeInTheDocument();
180
+ });
181
+
182
+ it('Progress handles undefined value', () => {
183
+ render(<Progress value={undefined} data-testid="prog" />);
184
+ expect(screen.getByTestId('prog')).toBeInTheDocument();
185
+ });
186
+ });
187
+
188
+ // ---------------------------------------------------------------
189
+ // Multiple instances
190
+ // ---------------------------------------------------------------
191
+ describe('multiple component instances', () => {
192
+ it('renders many Badges without interference', () => {
193
+ const { container } = render(
194
+ <div>
195
+ {Array.from({ length: 100 }, (_, i) => (
196
+ <Badge key={i}>Badge {i}</Badge>
197
+ ))}
198
+ </div>
199
+ );
200
+ const badges = container.querySelectorAll('[class*="inline-flex"]');
201
+ expect(badges.length).toBe(100);
202
+ });
203
+
204
+ it('renders many Buttons without interference', () => {
205
+ render(
206
+ <div>
207
+ {Array.from({ length: 50 }, (_, i) => (
208
+ <Button key={i}>Btn {i}</Button>
209
+ ))}
210
+ </div>
211
+ );
212
+ expect(screen.getAllByRole('button')).toHaveLength(50);
213
+ });
214
+
215
+ it('renders many Inputs without interference', () => {
216
+ render(
217
+ <div>
218
+ {Array.from({ length: 50 }, (_, i) => (
219
+ <Input key={i} data-testid={`inp-${i}`} defaultValue={`val-${i}`} />
220
+ ))}
221
+ </div>
222
+ );
223
+ expect(screen.getByTestId('inp-0')).toHaveValue('val-0');
224
+ expect(screen.getByTestId('inp-49')).toHaveValue('val-49');
225
+ });
226
+ });
227
+
228
+ // ---------------------------------------------------------------
229
+ // Separator edge cases
230
+ // ---------------------------------------------------------------
231
+ describe('Separator edge cases', () => {
232
+ it('renders multiple separators', () => {
233
+ const { container } = render(
234
+ <div>
235
+ <Separator />
236
+ <Separator />
237
+ <Separator />
238
+ </div>
239
+ );
240
+ expect(container.querySelectorAll('[data-orientation]')).toHaveLength(3);
241
+ });
242
+ });
243
+
244
+ // ---------------------------------------------------------------
245
+ // Skeleton edge cases
246
+ // ---------------------------------------------------------------
247
+ describe('Skeleton edge cases', () => {
248
+ it('renders with custom dimensions via className', () => {
249
+ const { container } = render(<Skeleton className="w-[200px] h-[20px]" />);
250
+ expect(container.firstElementChild!.className).toContain('w-[200px]');
251
+ expect(container.firstElementChild!.className).toContain('h-[20px]');
252
+ });
253
+
254
+ it('renders with children', () => {
255
+ const { container } = render(<Skeleton>Loading...</Skeleton>);
256
+ expect(container.textContent).toBe('Loading...');
257
+ });
258
+ });
259
+
260
+ // ---------------------------------------------------------------
261
+ // Card with complex nested content
262
+ // ---------------------------------------------------------------
263
+ describe('Card with complex nested content', () => {
264
+ it('renders deeply nested structure', () => {
265
+ const { container } = render(
266
+ <Card>
267
+ <CardHeader>
268
+ <CardTitle>
269
+ <Badge>New</Badge> Dashboard
270
+ </CardTitle>
271
+ </CardHeader>
272
+ <CardContent>
273
+ <div>
274
+ <Button>Action 1</Button>
275
+ <Button>Action 2</Button>
276
+ </div>
277
+ </CardContent>
278
+ </Card>
279
+ );
280
+ expect(container.textContent).toContain('New');
281
+ expect(container.textContent).toContain('Dashboard');
282
+ expect(screen.getAllByRole('button')).toHaveLength(2);
283
+ });
284
+ });
285
+ });