@fragments-sdk/viewer 0.2.1

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 (141) hide show
  1. package/LICENSE +84 -0
  2. package/index.html +28 -0
  3. package/package.json +71 -0
  4. package/src/__tests__/a11y-fixes.test.ts +358 -0
  5. package/src/__tests__/jsx-parser.test.ts +502 -0
  6. package/src/__tests__/render-utils.test.ts +232 -0
  7. package/src/__tests__/style-utils.test.ts +404 -0
  8. package/src/app/index.ts +1 -0
  9. package/src/assets/fragments-logo.ts +4 -0
  10. package/src/assets/fragments_logo.png +0 -0
  11. package/src/components/AccessibilityPanel.tsx +1457 -0
  12. package/src/components/ActionCapture.tsx +172 -0
  13. package/src/components/ActionsPanel.tsx +332 -0
  14. package/src/components/AllVariantsPreview.tsx +78 -0
  15. package/src/components/App.tsx +604 -0
  16. package/src/components/BottomPanel.tsx +288 -0
  17. package/src/components/CodePanel.naming.test.tsx +59 -0
  18. package/src/components/CodePanel.tsx +118 -0
  19. package/src/components/CommandPalette.tsx +392 -0
  20. package/src/components/ComponentDocView.tsx +164 -0
  21. package/src/components/ComponentGraph.tsx +380 -0
  22. package/src/components/ComponentHeader.tsx +88 -0
  23. package/src/components/ContractPanel.tsx +241 -0
  24. package/src/components/DeviceMockup.tsx +156 -0
  25. package/src/components/EmptyVariantMessage.tsx +54 -0
  26. package/src/components/ErrorBoundary.tsx +97 -0
  27. package/src/components/FigmaEmbed.tsx +238 -0
  28. package/src/components/FragmentEditor.tsx +525 -0
  29. package/src/components/FragmentRenderer.tsx +61 -0
  30. package/src/components/HeaderSearch.tsx +24 -0
  31. package/src/components/HealthDashboard.tsx +441 -0
  32. package/src/components/HmrStatusIndicator.tsx +61 -0
  33. package/src/components/Icons.tsx +479 -0
  34. package/src/components/InteractionsPanel.tsx +757 -0
  35. package/src/components/IsolatedPreviewFrame.tsx +390 -0
  36. package/src/components/IsolatedRender.tsx +113 -0
  37. package/src/components/KeyboardShortcutsHelp.tsx +53 -0
  38. package/src/components/LandingPage.tsx +420 -0
  39. package/src/components/Layout.tsx +27 -0
  40. package/src/components/LeftSidebar.tsx +472 -0
  41. package/src/components/LoadErrorMessage.tsx +102 -0
  42. package/src/components/MultiViewportPreview.tsx +527 -0
  43. package/src/components/NoVariantsMessage.tsx +59 -0
  44. package/src/components/PanelShell.tsx +161 -0
  45. package/src/components/PerformancePanel.tsx +304 -0
  46. package/src/components/PreviewArea.tsx +254 -0
  47. package/src/components/PreviewAside.tsx +168 -0
  48. package/src/components/PreviewFrameHost.tsx +304 -0
  49. package/src/components/PreviewToolbar.tsx +80 -0
  50. package/src/components/PropsEditor.tsx +506 -0
  51. package/src/components/PropsTable.tsx +111 -0
  52. package/src/components/RelationsSection.tsx +88 -0
  53. package/src/components/ResizablePanel.tsx +271 -0
  54. package/src/components/RightSidebar.tsx +102 -0
  55. package/src/components/RuntimeToolsRegistrar.tsx +17 -0
  56. package/src/components/ScreenshotButton.tsx +90 -0
  57. package/src/components/ShadowPreview.tsx +204 -0
  58. package/src/components/Sidebar.tsx +169 -0
  59. package/src/components/SkeletonLoader.tsx +161 -0
  60. package/src/components/ThemeProvider.tsx +42 -0
  61. package/src/components/Toast.tsx +3 -0
  62. package/src/components/TokenStylePanel.tsx +699 -0
  63. package/src/components/TopToolbar.tsx +159 -0
  64. package/src/components/Untitled +1 -0
  65. package/src/components/UsageSection.tsx +95 -0
  66. package/src/components/VariantMatrix.tsx +391 -0
  67. package/src/components/VariantRenderer.tsx +131 -0
  68. package/src/components/VariantTabs.tsx +40 -0
  69. package/src/components/ViewerHeader.tsx +69 -0
  70. package/src/components/ViewerStateSync.tsx +52 -0
  71. package/src/components/ViewportSelector.tsx +172 -0
  72. package/src/components/WebMCPDevTools.tsx +503 -0
  73. package/src/components/WebMCPIntegration.tsx +47 -0
  74. package/src/components/WebMCPStatusIndicator.tsx +60 -0
  75. package/src/components/_future/CreatePage.tsx +835 -0
  76. package/src/components/viewer-utils.ts +16 -0
  77. package/src/composition-renderer.ts +381 -0
  78. package/src/constants/index.ts +1 -0
  79. package/src/constants/ui.ts +166 -0
  80. package/src/entry.tsx +335 -0
  81. package/src/hooks/index.ts +2 -0
  82. package/src/hooks/useA11yCache.ts +383 -0
  83. package/src/hooks/useA11yService.ts +364 -0
  84. package/src/hooks/useActions.ts +138 -0
  85. package/src/hooks/useAppState.ts +147 -0
  86. package/src/hooks/useCompiledFragments.ts +42 -0
  87. package/src/hooks/useFigmaIntegration.ts +132 -0
  88. package/src/hooks/useHmrStatus.ts +109 -0
  89. package/src/hooks/useKeyboardShortcuts.ts +270 -0
  90. package/src/hooks/usePreviewBridge.ts +347 -0
  91. package/src/hooks/useScrollSpy.ts +78 -0
  92. package/src/hooks/useShadowStyles.ts +221 -0
  93. package/src/hooks/useUrlState.ts +318 -0
  94. package/src/hooks/useViewSettings.ts +111 -0
  95. package/src/intelligence/healthReport.ts +505 -0
  96. package/src/intelligence/styleDrift.ts +340 -0
  97. package/src/intelligence/usageScanner.ts +309 -0
  98. package/src/jsx-parser.ts +486 -0
  99. package/src/preview-frame-entry.tsx +25 -0
  100. package/src/preview-frame.html +148 -0
  101. package/src/render-template.html +68 -0
  102. package/src/render-utils.ts +311 -0
  103. package/src/shared/ComponentDocContent.module.scss +10 -0
  104. package/src/shared/ComponentDocContent.module.scss.d.ts +2 -0
  105. package/src/shared/ComponentDocContent.tsx +274 -0
  106. package/src/shared/DocsHeaderBar.tsx +129 -0
  107. package/src/shared/DocsPageAsideHost.tsx +89 -0
  108. package/src/shared/DocsPageShell.tsx +124 -0
  109. package/src/shared/DocsSearchCommand.tsx +99 -0
  110. package/src/shared/DocsSidebarNav.tsx +66 -0
  111. package/src/shared/PropsTable.module.scss +68 -0
  112. package/src/shared/PropsTable.module.scss.d.ts +2 -0
  113. package/src/shared/PropsTable.tsx +76 -0
  114. package/src/shared/VariantPreviewCard.module.scss +114 -0
  115. package/src/shared/VariantPreviewCard.module.scss.d.ts +2 -0
  116. package/src/shared/VariantPreviewCard.tsx +137 -0
  117. package/src/shared/docs-data/index.ts +32 -0
  118. package/src/shared/docs-data/mcp-configs.ts +72 -0
  119. package/src/shared/docs-data/palettes.ts +75 -0
  120. package/src/shared/docs-data/setup-examples.ts +55 -0
  121. package/src/shared/docs-layout.scss +28 -0
  122. package/src/shared/docs-layout.scss.d.ts +2 -0
  123. package/src/shared/index.ts +34 -0
  124. package/src/shared/types.ts +53 -0
  125. package/src/style-utils.ts +414 -0
  126. package/src/styles/globals.css +278 -0
  127. package/src/types/a11y.ts +197 -0
  128. package/src/utils/a11y-fixes.ts +509 -0
  129. package/src/utils/actionExport.ts +372 -0
  130. package/src/utils/colorSchemes.ts +201 -0
  131. package/src/utils/contrast.ts +246 -0
  132. package/src/utils/detectRelationships.ts +256 -0
  133. package/src/webmcp/__tests__/analytics.test.ts +108 -0
  134. package/src/webmcp/analytics.ts +165 -0
  135. package/src/webmcp/index.ts +3 -0
  136. package/src/webmcp/posthog-bridge.ts +39 -0
  137. package/src/webmcp/runtime-tools.ts +152 -0
  138. package/src/webmcp/scan-utils.ts +135 -0
  139. package/src/webmcp/use-tool-analytics.ts +69 -0
  140. package/src/webmcp/viewer-state.ts +45 -0
  141. package/tsconfig.json +20 -0
@@ -0,0 +1,441 @@
1
+ /**
2
+ * Dashboard Component
3
+ * Minimalist overview of design system coverage and components
4
+ * with enhanced accessibility insights and top issues aggregation
5
+ */
6
+
7
+ import { useMemo, useState, useCallback, useEffect } from 'react';
8
+ import type { FragmentDefinition } from '@fragments-sdk/core';
9
+ import type { ImpactValue } from 'axe-core';
10
+ import { Badge, Progress, Stack, Text, Card, EmptyState } from '@fragments-sdk/ui';
11
+ import {
12
+ getAllA11yData,
13
+ getA11ySummary,
14
+ getAllA11yResults,
15
+ type ComponentA11yData,
16
+ } from '../hooks/useA11yCache.js';
17
+ import type { A11ySummary, CachedA11yResult } from '../types/a11y.js';
18
+
19
+ /** Normalize category to Title Case for display */
20
+ function titleCase(str: string): string {
21
+ return str.replace(/\b\w/g, (c) => c.toUpperCase());
22
+ }
23
+
24
+ /** Normalize category to a canonical key so "Form" and "Forms" merge into one group */
25
+ function categoryKey(raw: string): string {
26
+ const tc = titleCase(raw.trim());
27
+ if (tc.length > 4 && tc.endsWith('s') && !tc.endsWith('ss')) {
28
+ return tc.slice(0, -1);
29
+ }
30
+ return tc;
31
+ }
32
+
33
+ interface HealthDashboardProps {
34
+ fragments: Array<{ path: string; fragment: FragmentDefinition }>;
35
+ onNavigate?: (componentName: string) => void;
36
+ }
37
+
38
+ interface CoverageMetric {
39
+ label: string;
40
+ count: number;
41
+ total: number;
42
+ }
43
+
44
+ interface A11yResults {
45
+ accessibleComponents: number;
46
+ totalComponents: number;
47
+ totalViolations: number;
48
+ totalCritical: number;
49
+ totalSerious: number;
50
+ }
51
+
52
+ interface ComponentA11yResult {
53
+ violations: number;
54
+ critical: number;
55
+ serious: number;
56
+ status: 'pending' | 'scanning' | 'pass' | 'warn' | 'fail';
57
+ }
58
+
59
+ interface ComponentRow {
60
+ name: string;
61
+ category: string;
62
+ variantCount: number;
63
+ status: string;
64
+ }
65
+
66
+ function calculateCoverage(
67
+ fragments: Array<{ path: string; fragment: FragmentDefinition }>
68
+ ): { metrics: CoverageMetric[]; components: ComponentRow[]; categoryCount: number } {
69
+ const total = fragments.length;
70
+
71
+ if (total === 0) {
72
+ return { metrics: [], components: [], categoryCount: 0 };
73
+ }
74
+
75
+ const categories = new Set<string>();
76
+ const components: ComponentRow[] = [];
77
+
78
+ let documented = 0;
79
+ let withVariants = 0;
80
+ let withUsage = 0;
81
+ let figmaLinked = 0;
82
+
83
+ for (const { fragment } of fragments) {
84
+ const cat = fragment.meta.category || 'uncategorized';
85
+ categories.add(categoryKey(cat));
86
+
87
+ if (fragment.meta.description && fragment.meta.description.trim().length > 10) {
88
+ documented++;
89
+ }
90
+
91
+ const variantCount = fragment.variants?.length || 0;
92
+ if (variantCount > 0) {
93
+ withVariants++;
94
+ }
95
+
96
+ if (fragment.usage && (fragment.usage.when.length > 0 || fragment.usage.whenNot.length > 0)) {
97
+ withUsage++;
98
+ }
99
+
100
+ if (fragment.meta.figma || fragment.variants?.some((v) => v.figma)) {
101
+ figmaLinked++;
102
+ }
103
+
104
+ components.push({
105
+ name: fragment.meta.name,
106
+ category: titleCase(cat),
107
+ variantCount,
108
+ status: fragment.meta.status || 'stable',
109
+ });
110
+ }
111
+
112
+ components.sort((a, b) => {
113
+ if (a.category !== b.category) return a.category.localeCompare(b.category);
114
+ return a.name.localeCompare(b.name);
115
+ });
116
+
117
+ const metrics: CoverageMetric[] = [
118
+ { label: 'Documented', count: documented, total },
119
+ { label: 'Variants', count: withVariants, total },
120
+ { label: 'Usage', count: withUsage, total },
121
+ { label: 'Figma', count: figmaLinked, total },
122
+ ];
123
+
124
+ return { metrics, components, categoryCount: categories.size };
125
+ }
126
+
127
+ function impactToBadgeVariant(impact: ImpactValue | undefined): 'error' | 'warning' | 'info' | 'default' {
128
+ switch (impact) {
129
+ case 'critical': return 'error';
130
+ case 'serious': return 'error';
131
+ case 'moderate': return 'warning';
132
+ case 'minor': return 'info';
133
+ default: return 'default';
134
+ }
135
+ }
136
+
137
+ export function HealthDashboard({ fragments, onNavigate }: HealthDashboardProps) {
138
+ const { metrics, components, categoryCount } = useMemo(
139
+ () => calculateCoverage(fragments),
140
+ [fragments]
141
+ );
142
+
143
+ const [componentA11y, setComponentA11y] = useState<Record<string, ComponentA11yResult>>({});
144
+ const [scanningComponents, setScanningComponents] = useState<Set<string>>(new Set());
145
+ const [a11ySummary, setA11ySummary] = useState<A11ySummary | null>(null);
146
+
147
+ const convertCacheToA11y = useCallback((cached: Record<string, ComponentA11yData>): Record<string, ComponentA11yResult> => {
148
+ const result: Record<string, ComponentA11yResult> = {};
149
+ for (const [name, data] of Object.entries(cached)) {
150
+ let status: ComponentA11yResult['status'] = 'pass';
151
+ if (data.critical > 0 || data.serious > 0) {
152
+ status = 'fail';
153
+ } else if (data.violations > 0) {
154
+ status = 'warn';
155
+ }
156
+ result[name] = {
157
+ violations: data.violations,
158
+ critical: data.critical,
159
+ serious: data.serious,
160
+ status,
161
+ };
162
+ }
163
+ return result;
164
+ }, []);
165
+
166
+ useEffect(() => {
167
+ const cached = getAllA11yData();
168
+ if (Object.keys(cached).length > 0) {
169
+ setComponentA11y(convertCacheToA11y(cached));
170
+ setA11ySummary(getA11ySummary());
171
+ }
172
+
173
+ const handleCacheUpdate = () => {
174
+ const updatedCache = getAllA11yData();
175
+ setComponentA11y(convertCacheToA11y(updatedCache));
176
+ setA11ySummary(getA11ySummary());
177
+ };
178
+
179
+ const handleCacheCleared = () => {
180
+ setComponentA11y({});
181
+ setA11ySummary(null);
182
+ };
183
+
184
+ const handleScanStarted = (event: CustomEvent<{ componentName: string }>) => {
185
+ setScanningComponents(prev => new Set(prev).add(event.detail.componentName));
186
+ };
187
+
188
+ const handleScanCompleted = (event: CustomEvent<{ componentName: string }>) => {
189
+ setScanningComponents(prev => {
190
+ const next = new Set(prev);
191
+ next.delete(event.detail.componentName);
192
+ return next;
193
+ });
194
+ };
195
+
196
+ window.addEventListener('a11y-cache-updated', handleCacheUpdate);
197
+ window.addEventListener('a11y-cache-cleared', handleCacheCleared);
198
+ window.addEventListener('a11y-scan-started', handleScanStarted as EventListener);
199
+ window.addEventListener('a11y-scan-completed', handleScanCompleted as EventListener);
200
+
201
+ return () => {
202
+ window.removeEventListener('a11y-cache-updated', handleCacheUpdate);
203
+ window.removeEventListener('a11y-cache-cleared', handleCacheCleared);
204
+ window.removeEventListener('a11y-scan-started', handleScanStarted as EventListener);
205
+ window.removeEventListener('a11y-scan-completed', handleScanCompleted as EventListener);
206
+ };
207
+ }, [convertCacheToA11y]);
208
+
209
+ const a11yResults = useMemo((): A11yResults | null => {
210
+ const scannedComponents = Object.keys(componentA11y).length;
211
+ if (scannedComponents === 0) {
212
+ return null;
213
+ }
214
+
215
+ const summary = a11ySummary || getA11ySummary();
216
+ return {
217
+ accessibleComponents: summary.accessibleComponents,
218
+ totalComponents: summary.totalComponents,
219
+ totalViolations:
220
+ summary.violationsByImpact.critical +
221
+ summary.violationsByImpact.serious +
222
+ summary.violationsByImpact.moderate +
223
+ summary.violationsByImpact.minor,
224
+ totalCritical: summary.violationsByImpact.critical,
225
+ totalSerious: summary.violationsByImpact.serious,
226
+ };
227
+ }, [componentA11y, a11ySummary]);
228
+
229
+ if (fragments.length === 0) {
230
+ return (
231
+ <EmptyState>
232
+ <EmptyState.Description>No components loaded</EmptyState.Description>
233
+ </EmptyState>
234
+ );
235
+ }
236
+
237
+ const a11yMetric: CoverageMetric | null = a11yResults
238
+ ? {
239
+ label: 'Accessible',
240
+ count: a11yResults.accessibleComponents,
241
+ total: a11yResults.totalComponents,
242
+ }
243
+ : null;
244
+
245
+ return (
246
+ <Stack direction="column" gap="lg" style={{ maxWidth: '672px' }}>
247
+ {/* Header */}
248
+ <div>
249
+ <Text as="h1" size="lg" weight="semibold">Fragments</Text>
250
+ <Text size="sm" color="tertiary" style={{ marginTop: '2px' }}>
251
+ {fragments.length} component{fragments.length !== 1 ? 's' : ''} · {categoryCount} categor{categoryCount !== 1 ? 'ies' : 'y'}
252
+ </Text>
253
+ </div>
254
+
255
+ {/* Coverage */}
256
+ <Card>
257
+ <Card.Body>
258
+ <Stack direction="column" gap="sm">
259
+ <Text as="h2" size="sm" weight="medium">Coverage</Text>
260
+ <Stack direction="column" gap="sm">
261
+ {metrics.map((metric) => (
262
+ <CoverageRow key={metric.label} metric={metric} />
263
+ ))}
264
+ {a11yMetric ? (
265
+ <CoverageRow metric={a11yMetric} />
266
+ ) : (
267
+ <Stack direction="row" align="center" gap="sm">
268
+ <Text size="sm" color="secondary" style={{ width: '96px', flexShrink: 0 }}>Accessible</Text>
269
+ <div style={{ flex: 1 }}>
270
+ <Progress value={0} />
271
+ </div>
272
+ <Text size="xs" color="tertiary" style={{ width: '40px', textAlign: 'right', flexShrink: 0 }}>-</Text>
273
+ </Stack>
274
+ )}
275
+ </Stack>
276
+ <div style={{ paddingTop: '8px', borderTop: '1px solid var(--border-subtle)' }}>
277
+ {a11yResults ? (
278
+ a11yResults.totalViolations > 0 ? (
279
+ <Text size="xs" color="tertiary">
280
+ {a11yResults.totalViolations} violation{a11yResults.totalViolations !== 1 ? 's' : ''} found
281
+ ({a11yResults.totalCritical} critical, {a11yResults.totalSerious} serious)
282
+ </Text>
283
+ ) : (
284
+ <Text size="xs" style={{ color: 'var(--color-success)' }}>
285
+ All scanned components pass accessibility checks
286
+ </Text>
287
+ )
288
+ ) : (
289
+ <Text size="xs" color="tertiary">
290
+ Visit components to scan for accessibility issues
291
+ </Text>
292
+ )}
293
+ </div>
294
+ </Stack>
295
+ </Card.Body>
296
+ </Card>
297
+
298
+ {/* Top Issues Section */}
299
+ {a11ySummary && a11ySummary.topViolations.length > 0 && (
300
+ <Card>
301
+ <Card.Body>
302
+ <Stack direction="column" gap="sm">
303
+ <Text as="h2" size="sm" weight="medium">Top Issues</Text>
304
+ <Text size="xs" color="tertiary">
305
+ Common accessibility violations across your components
306
+ </Text>
307
+ <Stack direction="column" gap="sm">
308
+ {a11ySummary.topViolations.map((violation) => (
309
+ <Stack
310
+ key={violation.ruleId}
311
+ direction="row"
312
+ align="start"
313
+ gap="sm"
314
+ style={{
315
+ padding: '8px',
316
+ borderRadius: '4px',
317
+ backgroundColor: 'var(--bg-secondary)',
318
+ border: '1px solid var(--border-subtle)',
319
+ }}
320
+ >
321
+ {violation.impact && (
322
+ <Badge variant={impactToBadgeVariant(violation.impact)} size="sm">
323
+ {violation.impact}
324
+ </Badge>
325
+ )}
326
+ <div style={{ flex: 1, minWidth: 0 }}>
327
+ <Text size="xs" style={{ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
328
+ {violation.description}
329
+ </Text>
330
+ <Text size="xs" color="tertiary" style={{ marginTop: '2px' }}>
331
+ <Text as="span" size="xs" font="mono">{violation.ruleId}</Text>
332
+ {' · '}
333
+ {violation.affectedComponents.length} component{violation.affectedComponents.length !== 1 ? 's' : ''}
334
+ </Text>
335
+ </div>
336
+ <Text size="xs" color="tertiary" style={{ flexShrink: 0 }}>
337
+ {violation.affectedComponents.length}
338
+ </Text>
339
+ </Stack>
340
+ ))}
341
+ </Stack>
342
+ {a11ySummary.topViolations.length >= 5 && (
343
+ <Text size="xs" color="tertiary" style={{ textAlign: 'center' }}>
344
+ Showing top 5 issues
345
+ </Text>
346
+ )}
347
+ </Stack>
348
+ </Card.Body>
349
+ </Card>
350
+ )}
351
+
352
+ {/* Components Table */}
353
+ <div>
354
+ <Text as="h2" size="sm" weight="medium" style={{ marginBottom: '8px' }}>Components</Text>
355
+ <div style={{ borderRadius: '8px', border: '1px solid var(--border-subtle)', overflow: 'hidden' }}>
356
+ <table style={{ width: '100%', fontSize: '14px', borderCollapse: 'collapse' }}>
357
+ <thead>
358
+ <tr style={{ borderBottom: '1px solid var(--border-subtle)', backgroundColor: 'var(--bg-secondary)' }}>
359
+ <th style={{ textAlign: 'left', padding: '8px 12px', fontSize: '12px', fontWeight: 500, color: 'var(--text-tertiary)' }}>Name</th>
360
+ <th style={{ textAlign: 'left', padding: '8px 12px', fontSize: '12px', fontWeight: 500, color: 'var(--text-tertiary)' }}>Category</th>
361
+ <th style={{ textAlign: 'left', padding: '8px 12px', fontSize: '12px', fontWeight: 500, color: 'var(--text-tertiary)' }}>Variants</th>
362
+ <th style={{ textAlign: 'left', padding: '8px 12px', fontSize: '12px', fontWeight: 500, color: 'var(--text-tertiary)' }}>A11y</th>
363
+ <th style={{ textAlign: 'left', padding: '8px 12px', fontSize: '12px', fontWeight: 500, color: 'var(--text-tertiary)' }}>Status</th>
364
+ </tr>
365
+ </thead>
366
+ <tbody>
367
+ {components.map((component, index) => {
368
+ const a11yStatus = componentA11y[component.name];
369
+ const isScanning = scanningComponents.has(component.name);
370
+ return (
371
+ <tr
372
+ key={component.name}
373
+ onClick={() => onNavigate?.(component.name)}
374
+ style={{
375
+ borderBottom: index < components.length - 1 ? '1px solid var(--border-subtle)' : 'none',
376
+ cursor: 'pointer',
377
+ transition: 'background-color 150ms',
378
+ }}
379
+ onMouseEnter={(e) => { (e.currentTarget as HTMLElement).style.backgroundColor = 'var(--bg-hover)'; }}
380
+ onMouseLeave={(e) => { (e.currentTarget as HTMLElement).style.backgroundColor = ''; }}
381
+ >
382
+ <td style={{ padding: '8px 12px' }}><Text weight="medium" size="sm">{component.name}</Text></td>
383
+ <td style={{ padding: '8px 12px' }}><Text size="sm" color="tertiary">{component.category}</Text></td>
384
+ <td style={{ padding: '8px 12px' }}><Text size="sm" color="tertiary">{component.variantCount}</Text></td>
385
+ <td style={{ padding: '8px 12px' }}>
386
+ <A11yBadge result={a11yStatus} isScanning={isScanning} />
387
+ </td>
388
+ <td style={{ padding: '8px 12px' }}><Text size="sm" color="tertiary">{component.status}</Text></td>
389
+ </tr>
390
+ );
391
+ })}
392
+ </tbody>
393
+ </table>
394
+ </div>
395
+ </div>
396
+ </Stack>
397
+ );
398
+ }
399
+
400
+ function CoverageRow({ metric }: { metric: CoverageMetric }) {
401
+ const percentage = metric.total > 0 ? Math.round((metric.count / metric.total) * 100) : 0;
402
+
403
+ return (
404
+ <Stack direction="row" align="center" gap="sm">
405
+ <Text size="sm" color="secondary" style={{ width: '96px', flexShrink: 0 }}>{metric.label}</Text>
406
+ <div style={{ flex: 1 }}>
407
+ <Progress value={percentage} />
408
+ </div>
409
+ <Text size="xs" color="tertiary" style={{ width: '40px', textAlign: 'right', flexShrink: 0 }}>
410
+ {metric.count}/{metric.total}
411
+ </Text>
412
+ </Stack>
413
+ );
414
+ }
415
+
416
+ function A11yBadge({ result, isScanning }: { result?: ComponentA11yResult; isScanning?: boolean }) {
417
+ if (isScanning) {
418
+ return <Badge variant="warning" size="sm">Scanning</Badge>;
419
+ }
420
+
421
+ if (!result || result.status === 'pending') {
422
+ return <Text size="xs" color="tertiary">-</Text>;
423
+ }
424
+
425
+ if (result.status === 'scanning') {
426
+ return <Badge variant="default" size="sm">...</Badge>;
427
+ }
428
+
429
+ if (result.status === 'pass') {
430
+ return <Badge variant="success" size="sm">Pass</Badge>;
431
+ }
432
+
433
+ if (result.status === 'fail') {
434
+ return <Badge variant="error" size="sm">{result.violations}</Badge>;
435
+ }
436
+
437
+ // warn status
438
+ return <Badge variant="warning" size="sm">{result.violations}</Badge>;
439
+ }
440
+
441
+ export default HealthDashboard;
@@ -0,0 +1,61 @@
1
+ import { Badge, Stack, Text } from '@fragments-sdk/ui';
2
+ import { HMR_STATUS } from '../constants/ui.js';
3
+ import { useHmrStatus } from '../hooks/useHmrStatus.js';
4
+ import { WifiIcon, WifiOffIcon } from './Icons.js';
5
+
6
+ interface HmrStatusIndicatorProps {
7
+ className?: string;
8
+ }
9
+
10
+ export function HmrStatusIndicator({ className }: HmrStatusIndicatorProps) {
11
+ const { status, lastUpdate } = useHmrStatus();
12
+ const config = HMR_STATUS[status];
13
+
14
+ const variant = status === 'connected' ? 'success' as const
15
+ : status === 'disconnected' ? 'error' as const
16
+ : 'warning' as const;
17
+
18
+ return (
19
+ <Stack direction="row" gap="xs" align="center" className={className}>
20
+ <Badge variant={variant} size="sm" dot>
21
+ <span style={{ display: 'flex', alignItems: 'center', gap: '4px' }}>
22
+ {status === 'disconnected' ? (
23
+ <WifiOffIcon style={{ width: '12px', height: '12px' }} />
24
+ ) : (
25
+ <WifiIcon style={{ width: '12px', height: '12px' }} />
26
+ )}
27
+ </span>
28
+ </Badge>
29
+
30
+ {lastUpdate && (
31
+ <Text
32
+ size="2xs"
33
+ color="tertiary"
34
+ truncate
35
+ style={{ maxWidth: '100px' }}
36
+ title={lastUpdate}
37
+ >
38
+ Updated: {lastUpdate.split('/').pop()}
39
+ </Text>
40
+ )}
41
+ </Stack>
42
+ );
43
+ }
44
+
45
+ /**
46
+ * Compact version that just shows the status dot.
47
+ */
48
+ export function HmrStatusDot() {
49
+ const { status } = useHmrStatus();
50
+ const config = HMR_STATUS[status];
51
+
52
+ const variant = status === 'connected' ? 'success' as const
53
+ : status === 'disconnected' ? 'error' as const
54
+ : 'warning' as const;
55
+
56
+ return (
57
+ <Badge variant={variant} size="sm" dot title={config.label}>
58
+ <span />
59
+ </Badge>
60
+ );
61
+ }