Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

feat(storybook): Internal Web Apps Analytics dashboard (#663)

cvkxx95f950063313
diff --git a/apps/storybook/stories/AnalyticsDashboard.stories.tsx b/apps/storybook/stories/AnalyticsDashboard.stories.tsx
new file mode 100644
index 0000000000..3f02809f41
--- /dev/null
+++ b/apps/storybook/stories/AnalyticsDashboard.stories.tsx
@@ -0,0 +1,1396 @@
+import {useState, useMemo} from 'react';
+import type {Meta, StoryObj} from '@storybook/react';
+import * as stylex from '@stylexjs/stylex';
+import {XDSCard} from '@xds/core/Card';
+import {XDSVStack, XDSHStack} from '@xds/core/Layout';
+import {XDSText, XDSHeading} from '@xds/core/Text';
+import {XDSLink} from '@xds/core/Link';
+import {XDSTabList, XDSTab} from '@xds/core/TabList';
+import {XDSTopNav, XDSTopNavHeading} from '@xds/core/TopNav';
+import {XDSButton} from '@xds/core/Button';
+import {
+ InformationCircleIcon,
+ ArrowPathIcon,
+ LinkIcon,
+ ArrowTopRightOnSquareIcon,
+ ClipboardDocumentIcon,
+ ArrowDownTrayIcon,
+} from '@heroicons/react/24/outline';
+
+function XBracketIcon({style}: {style?: React.CSSProperties}) {
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ fill="none"
+ viewBox="0 0 24 24"
+ strokeWidth={1.5}
+ stroke="currentColor"
+ style={style}>
+ {/* Left bracket */}
+ <path strokeLinecap="round" strokeLinejoin="round" d="M7 4H4v16h3" />
+ {/* Right bracket */}
+ <path strokeLinecap="round" strokeLinejoin="round" d="M17 4h3v16h-3" />
+ {/* X */}
+ <path
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ d="M9 9l6 6M15 9l-6 6"
+ />
+ </svg>
+ );
+}
+
+function NestIcon({style}: {style?: React.CSSProperties}) {
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ fill="none"
+ viewBox="0 0 24 24"
+ strokeWidth={1.5}
+ stroke="currentColor"
+ style={style}>
+ {/* Bowl shape */}
+ <path
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ d="M3 12c0 5 4 9 9 9s9-4 9-9"
+ />
+ {/* Woven lines */}
+ <path
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ d="M5 13c1.5 3 4 5 7 5s5.5-2 7-5"
+ />
+ <path
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ d="M7.5 15c1 1.5 2.5 2.5 4.5 2.5s3.5-1 4.5-2.5"
+ />
+ {/* Three eggs */}
+ <ellipse cx="8.5" cy="10.5" rx="2" ry="2.8" strokeLinejoin="round" />
+ <ellipse cx="12" cy="9.5" rx="1.8" ry="2.5" strokeLinejoin="round" />
+ <ellipse cx="15.5" cy="10.5" rx="2" ry="2.8" strokeLinejoin="round" />
+ </svg>
+ );
+}
+import {XDSDivider} from '@xds/core/Divider';
+import {XDSTextInput} from '@xds/core/TextInput';
+import {XDSDropdownMenu} from '@xds/core/DropdownMenu';
+import {XDSMoreMenu} from '@xds/core/MoreMenu';
+import {XDSDialog, XDSDialogHeader} from '@xds/core/Dialog';
+import {XDSLayout, XDSLayoutContent, XDSLayoutFooter} from '@xds/core/Layout';
+import {XDSTable, proportional, pixel} from '@xds/core/Table';
+import type {XDSTableColumn} from '@xds/core/Table';
+import {XDSPagination} from '@xds/core/Pagination';
+import {
+ colorVars,
+ spacingVars,
+ textSizeVars,
+ fontWeightVars,
+ radiusVars,
+} from '@xds/core/theme/tokens.stylex';
+
+// =============================================================================
+// Styles
+// =============================================================================
+
+const styles = stylex.create({
+ page: {
+ maxWidth: 1200,
+ margin: '0 auto',
+ width: '100%',
+ },
+ statsRow: {
+ display: 'grid',
+ gridTemplateColumns: 'repeat(4, 1fr)',
+ gap: spacingVars['--spacing-3'],
+ },
+ statInner: {
+ display: 'flex',
+ flexDirection: 'column',
+ gap: spacingVars['--spacing-1'],
+ },
+ statValueRow: {
+ display: 'flex',
+ alignItems: 'baseline',
+ gap: spacingVars['--spacing-2'],
+ },
+ changePositive: {
+ color: colorVars['--color-success'],
+ fontSize: textSizeVars['--text-base'],
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ },
+ changeNegative: {
+ color: colorVars['--color-error'],
+ fontSize: textSizeVars['--text-base'],
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ },
+ changePositiveSm: {
+ color: colorVars['--color-success'],
+ fontSize: textSizeVars['--text-xsm'],
+ },
+ changeNegativeSm: {
+ color: colorVars['--color-error'],
+ fontSize: textSizeVars['--text-xsm'],
+ },
+ chartsGrid: {
+ display: 'grid',
+ gridTemplateColumns: '1fr 1fr',
+ gap: spacingVars['--spacing-4'],
+ },
+ chartInner: {
+ paddingTop: spacingVars['--spacing-1'],
+ },
+ linksRow: {
+ display: 'flex',
+ gap: spacingVars['--spacing-2'],
+ flexWrap: 'wrap',
+ },
+ searchFill: {
+ flex: 1,
+ minWidth: 0,
+ },
+ sectionLabel: {
+ fontSize: textSizeVars['--text-xsm'],
+ fontWeight: fontWeightVars['--font-weight-bold'],
+ textTransform: 'uppercase',
+ letterSpacing: '0.08em',
+ color: colorVars['--color-text-secondary'],
+ },
+ orgBar: {
+ display: 'flex',
+ alignItems: 'center',
+ gap: spacingVars['--spacing-2'],
+ height: 26,
+ },
+ orgLabel: {
+ width: 180,
+ fontSize: textSizeVars['--text-xsm'],
+ color: colorVars['--color-text-secondary'],
+ textAlign: 'right',
+ flexShrink: 0,
+ overflow: 'hidden',
+ textOverflow: 'ellipsis',
+ whiteSpace: 'nowrap',
+ },
+ barTrack: {
+ flex: 1,
+ height: 14,
+ backgroundColor: colorVars['--color-wash'],
+ borderRadius: radiusVars['--radius-content'],
+ overflow: 'hidden',
+ },
+ barFill: {
+ height: '100%',
+ backgroundColor: colorVars['--color-active'],
+ borderRadius: radiusVars['--radius-content'],
+ },
+ pctLabel: {
+ width: 36,
+ fontSize: textSizeVars['--text-xsm'],
+ color: colorVars['--color-text-secondary'],
+ },
+ wash: {
+ backgroundColor: colorVars['--color-wash'],
+ padding: spacingVars['--spacing-6'],
+ minHeight: '100vh',
+ },
+});
+
+// =============================================================================
+// Mock Data
+// =============================================================================
+
+const overviewStats = [
+ {
+ label: 'Total Intern Tools',
+ value: '14,184',
+ change: '+5.4%',
+ source: 'internal_tool_data · MoM',
+ },
+ {
+ label: 'Intern WAU',
+ value: '282,255',
+ change: '+6.3%',
+ source: 'vitals_event · WoW',
+ },
+ {
+ label: 'Total Nest Apps',
+ value: '7,304',
+ change: '+318.3%',
+ source: 'nest/apps · MoM',
+ },
+ {
+ label: 'Nest WAU',
+ value: '22,169',
+ change: '+23.2%',
+ source: 'nest_traces · WoW',
+ },
+];
+
+interface AdoptionMatrixRow extends Record<string, unknown> {
+ id: string;
+ metric: string;
+ xdsIntern: string;
+ xdsInternChange: string;
+ xdsInternSub: string;
+ xdsWwwNest: string;
+ xdsWwwNestChange: string;
+ xdsWwwNestSub: string;
+ xdsOssNest: string;
+ xdsOssNestChange: string;
+ xdsOssNestSub: string;
+ ndsNest: string;
+ ndsNestChange: string;
+ ndsNestSub: string;
+}
+
+const adoptionMatrixData: AdoptionMatrixRow[] = [
+ {
+ id: 'components',
+ metric: 'Components',
+ xdsIntern: '588',
+ xdsInternChange: '+1.2%',
+ xdsInternSub: 'Components in www',
+ xdsWwwNest: '671',
+ xdsWwwNestChange: '+0.4%',
+ xdsWwwNestSub: '@xds/core components',
+ xdsOssNest: '45',
+ xdsOssNestChange: '+4.7%',
+ xdsOssNestSub: '@xds/core components',
+ ndsNest: '155',
+ ndsNestChange: '+0.6%',
+ ndsNestSub: '@xds/core components',
+ },
+ {
+ id: 'insertions',
+ metric: 'Insertions',
+ xdsIntern: '2,376,231',
+ xdsInternChange: '+3.1%',
+ xdsInternSub: 'Total usages in www',
+ xdsWwwNest: '132',
+ xdsWwwNestChange: '+8.2%',
+ xdsWwwNestSub: 'Import usages',
+ xdsOssNest: '81+',
+ xdsOssNestChange: '+12.5%',
+ xdsOssNestSub: 'Import usages',
+ ndsNest: '7,960+',
+ ndsNestChange: '+2.3%',
+ ndsNestSub: 'Import usages',
+ },
+ {
+ id: 'tools',
+ metric: 'Tools / Apps Usage',
+ xdsIntern: '127',
+ xdsInternChange: '+1.6%',
+ xdsInternSub: 'Distinct oncalls on www',
+ xdsWwwNest: '236+',
+ xdsWwwNestChange: '+5.4%',
+ xdsWwwNestSub: 'Apps with @xds/core',
+ xdsOssNest: '5',
+ xdsOssNestChange: '+0.0%',
+ xdsOssNestSub: 'Apps with @xds/core',
+ ndsNest: '4,700+',
+ ndsNestChange: '+1.9%',
+ ndsNestSub: 'Apps with @xds/core',
+ },
+];
+
+const adoptionMatrixColumns: XDSTableColumn<AdoptionMatrixRow>[] = [
+ {key: 'metric', header: '', width: proportional(1.2)},
+ {
+ key: 'xdsIntern',
+ header: 'XDS on Intern (WWW)',
+ renderCell: row => (
+ <XDSVStack gap={0.5}>
+ <span>
+ <XDSText type="large" weight="bold">
+ {row.xdsIntern}
+ </XDSText>{' '}
+ <span {...stylex.props(styles.changePositiveSm)}>
+ {row.xdsInternChange}
+ </span>
+ </span>
+ <XDSText type="supporting" color="disabled">
+ {row.xdsInternSub}
+ </XDSText>
+ </XDSVStack>
+ ),
+ },
+ {
+ key: 'xdsWwwNest',
+ header: 'XDS WWW on Nest',
+ renderCell: row => (
+ <XDSVStack gap={0.5}>
+ <span>
+ <XDSText type="large" weight="bold">
+ {row.xdsWwwNest}
+ </XDSText>{' '}
+ <span {...stylex.props(styles.changePositiveSm)}>
+ {row.xdsWwwNestChange}
+ </span>
+ </span>
+ <XDSText type="supporting" color="disabled">
+ {row.xdsWwwNestSub}
+ </XDSText>
+ </XDSVStack>
+ ),
+ },
+ {
+ key: 'xdsOssNest',
+ header: 'XDS OSS on Nest',
+ renderCell: row => (
+ <XDSVStack gap={0.5}>
+ <span>
+ <XDSText type="large" weight="bold">
+ {row.xdsOssNest}
+ </XDSText>{' '}
+ <span {...stylex.props(styles.changePositiveSm)}>
+ {row.xdsOssNestChange}
+ </span>
+ </span>
+ <XDSText type="supporting" color="disabled">
+ {row.xdsOssNestSub}
+ </XDSText>
+ </XDSVStack>
+ ),
+ },
+ {
+ key: 'ndsNest',
+ header: 'NDS on Nest',
+ renderCell: row => (
+ <XDSVStack gap={0.5}>
+ <span>
+ <XDSText type="large" weight="bold">
+ {row.ndsNest}
+ </XDSText>{' '}
+ <span {...stylex.props(styles.changePositiveSm)}>
+ {row.ndsNestChange}
+ </span>
+ </span>
+ <XDSText type="supporting" color="disabled">
+ {row.ndsNestSub}
+ </XDSText>
+ </XDSVStack>
+ ),
+ },
+];
+
+const oncallsByOrg = [
+ {org: 'ABM - Corp Ads Growth', pct: 95},
+ {org: 'Central Integrity', pct: 88},
+ {org: 'Commerce Growth', pct: 82},
+ {org: 'FDA Foundation App Platform', pct: 78},
+ {org: 'Family Safety', pct: 72},
+ {org: 'Instagram Product Eng', pct: 70},
+ {org: 'Infra Engineering', pct: 65},
+ {org: 'Monetization', pct: 60},
+ {org: 'Instagram Privacy & Safety', pct: 55},
+ {org: 'PAK Payments Platform', pct: 50},
+ {org: 'RL Systems', pct: 45},
+ {org: 'RL Operations', pct: 42},
+];
+
+interface ComponentAdoptionRow extends Record<string, unknown> {
+ id: string;
+ component: string;
+ usages: number;
+ files: number;
+ oncalls: number;
+ teams: number;
+ firstInstance: string;
+}
+
+const componentAdoptionData: ComponentAdoptionRow[] = [
+ {
+ id: '1',
+ component: 'XDSText',
+ usages: 420851,
+ files: 119979,
+ oncalls: 107,
+ teams: 89,
+ firstInstance: '2023-10-23',
+ },
+ {
+ id: '2',
+ component: 'XDSFlexbox',
+ usages: 338790,
+ files: 118852,
+ oncalls: 94,
+ teams: 82,
+ firstInstance: '2023-10-23',
+ },
+ {
+ id: '3',
+ component: 'XDSButton',
+ usages: 148454,
+ files: 76138,
+ oncalls: 95,
+ teams: 83,
+ firstInstance: '2023-10-23',
+ },
+ {
+ id: '4',
+ component: 'XDSCard',
+ usages: 70940,
+ files: 42012,
+ oncalls: 73,
+ teams: 63,
+ firstInstance: '2023-10-23',
+ },
+ {
+ id: '5',
+ component: 'XDSLink',
+ usages: 70572,
+ files: 42201,
+ oncalls: 55,
+ teams: 49,
+ firstInstance: '2023-10-23',
+ },
+ {
+ id: '6',
+ component: 'XDSIcon',
+ usages: 70271,
+ files: 35573,
+ oncalls: 40,
+ teams: 36,
+ firstInstance: '2023-10-23',
+ },
+ {
+ id: '7',
+ component: 'XDSSelectorItem',
+ usages: 57513,
+ files: 19649,
+ oncalls: 50,
+ teams: 46,
+ firstInstance: '2023-10-23',
+ },
+ {
+ id: '8',
+ component: 'XDSBadge',
+ usages: 51564,
+ files: 22065,
+ oncalls: 37,
+ teams: 34,
+ firstInstance: '2023-10-23',
+ },
+ {
+ id: '9',
+ component: 'XDSHeading',
+ usages: 49170,
+ files: 31130,
+ oncalls: 49,
+ teams: 44,
+ firstInstance: '2023-10-23',
+ },
+ {
+ id: '10',
+ component: 'XDSDescriptionListItem',
+ usages: 47118,
+ files: 7778,
+ oncalls: 20,
+ teams: 20,
+ firstInstance: '2023-10-23',
+ },
+ {
+ id: '11',
+ component: 'XDSAvatar',
+ usages: 42300,
+ files: 18900,
+ oncalls: 38,
+ teams: 32,
+ firstInstance: '2023-10-23',
+ },
+ {
+ id: '12',
+ component: 'XDSSpinner',
+ usages: 38100,
+ files: 15200,
+ oncalls: 35,
+ teams: 30,
+ firstInstance: '2023-10-23',
+ },
+ {
+ id: '13',
+ component: 'XDSTooltip',
+ usages: 35800,
+ files: 14100,
+ oncalls: 33,
+ teams: 28,
+ firstInstance: '2023-10-23',
+ },
+ {
+ id: '14',
+ component: 'XDSDivider',
+ usages: 33500,
+ files: 12800,
+ oncalls: 30,
+ teams: 25,
+ firstInstance: '2023-10-23',
+ },
+ {
+ id: '15',
+ component: 'XDSSwitch',
+ usages: 28900,
+ files: 11200,
+ oncalls: 28,
+ teams: 23,
+ firstInstance: '2023-10-23',
+ },
+ {
+ id: '16',
+ component: 'XDSTextInput',
+ usages: 25600,
+ files: 9800,
+ oncalls: 25,
+ teams: 21,
+ firstInstance: '2023-10-23',
+ },
+ {
+ id: '17',
+ component: 'XDSCheckbox',
+ usages: 22100,
+ files: 8900,
+ oncalls: 22,
+ teams: 19,
+ firstInstance: '2023-10-23',
+ },
+ {
+ id: '18',
+ component: 'XDSRadioList',
+ usages: 18700,
+ files: 7500,
+ oncalls: 20,
+ teams: 17,
+ firstInstance: '2023-10-23',
+ },
+ {
+ id: '19',
+ component: 'XDSDialog',
+ usages: 15400,
+ files: 6200,
+ oncalls: 18,
+ teams: 15,
+ firstInstance: '2023-10-23',
+ },
+ {
+ id: '20',
+ component: 'XDSProgressBar',
+ usages: 12100,
+ files: 5100,
+ oncalls: 15,
+ teams: 13,
+ firstInstance: '2023-10-23',
+ },
+];
+
+// =============================================================================
+// Simple SVG Line Chart (no external dep)
+// =============================================================================
+
+function generateDAUData() {
+ const data = [];
+ const start = new Date('2026-03-03');
+ for (let i = 0; i < 14; i++) {
+ const date = new Date(start);
+ date.setDate(start.getDate() + i);
+ const dow = date.getDay();
+ const isWeekend = dow === 0 || dow === 6;
+ data.push({
+ label: `${date.getMonth() + 1}/${date.getDate()}`,
+ intern: isWeekend
+ ? 125000 + i * 2000
+ : 185000 + i * 3000 + (i % 3) * 10000,
+ nest: isWeekend ? 17000 + i * 500 : 32000 + i * 1000 + (i % 3) * 3000,
+ });
+ }
+ return data;
+}
+
+function generateCreationData() {
+ const data = [];
+ const months = [
+ "Dec'25",
+ "Jan'26",
+ "Feb'26",
+ "Mar'26",
+ "Apr'26",
+ "May'26",
+ "Jun'26",
+ "Jul'26",
+ ];
+ for (let i = 0; i < 8; i++) {
+ data.push({
+ label: months[i],
+ intern: 40 + Math.round(i * 5 + (i % 2) * 15),
+ nest: 30 + Math.round(i * 35 + (i % 2) * 20),
+ });
+ }
+ return data;
+}
+
+function generateComponentCountData() {
+ const data = [];
+ const months = ["Sep'25", 'Oct', 'Nov', 'Dec', "Jan'26", 'Feb', 'Mar'];
+ const counts = [460, 480, 505, 490, 530, 560, 588];
+ for (let i = 0; i < months.length; i++) {
+ data.push({label: months[i], value: counts[i]});
+ }
+ return data;
+}
+
+const dauData = generateDAUData();
+const creationData = generateCreationData();
+const componentCountData = generateComponentCountData();
+
+type DualPoint = {label: string; intern: number; nest: number};
+type SinglePoint = {label: string; value: number};
+
+function MiniLineChart({
+ data,
+ height = 280,
+ colors = ['#3b82f6', '#f97316'],
+ keys,
+ formatY,
+}: {
+ data: DualPoint[];
+ height?: number;
+ colors?: string[];
+ keys: [string, string];
+ formatY?: (v: number) => string;
+}) {
+ const w = 500;
+ const h = height;
+ const pad = {top: 20, right: 20, bottom: 50, left: 50};
+ const cw = w - pad.left - pad.right;
+ const ch = h - pad.top - pad.bottom;
+
+ const allVals = data.flatMap(d => [
+ d[keys[0] as keyof DualPoint] as number,
+ d[keys[1] as keyof DualPoint] as number,
+ ]);
+ const minV = Math.min(...allVals) * 0.9;
+ const maxV = Math.max(...allVals) * 1.05;
+
+ const xScale = (i: number) => pad.left + (i / (data.length - 1)) * cw;
+ const yScale = (v: number) =>
+ pad.top + ch - ((v - minV) / (maxV - minV)) * ch;
+ const fmt =
+ formatY ||
+ ((v: number) => (v >= 1000 ? `${(v / 1000).toFixed(0)}K` : String(v)));
+
+ const line = (key: string) =>
+ data
+ .map(
+ (d, i) =>
+ `${i === 0 ? 'M' : 'L'}${xScale(i)},${yScale(d[key as keyof DualPoint] as number)}`,
+ )
+ .join(' ');
+
+ return (
+ <svg viewBox={`0 0 ${w} ${h}`} style={{width: '100%', height}}>
+ {/* Grid lines */}
+ {[0, 0.25, 0.5, 0.75, 1].map(pct => {
+ const y = pad.top + ch * (1 - pct);
+ const val = minV + (maxV - minV) * pct;
+ return (
+ <g key={pct}>
+ <line
+ x1={pad.left}
+ x2={w - pad.right}
+ y1={y}
+ y2={y}
+ stroke="#e5e7eb"
+ strokeWidth={0.5}
+ />
+ <text
+ x={pad.left - 6}
+ y={y + 4}
+ textAnchor="end"
+ fontSize={10}
+ fill="#999">
+ {fmt(val)}
+ </text>
+ </g>
+ );
+ })}
+ {/* X labels */}
+ {data.map((d, i) =>
+ i % Math.ceil(data.length / 7) === 0 ? (
+ <text
+ key={i}
+ x={xScale(i)}
+ y={pad.top + ch + 16}
+ textAnchor="middle"
+ fontSize={10}
+ fill="#999">
+ {d.label}
+ </text>
+ ) : null,
+ )}
+ {/* Lines */}
+ <path d={line(keys[0])} fill="none" stroke={colors[0]} strokeWidth={2} />
+ <path d={line(keys[1])} fill="none" stroke={colors[1]} strokeWidth={2} />
+ {/* Legend */}
+ <circle cx={w / 2 - 35} cy={h - 8} r={3} fill={colors[0]} />
+ <text x={w / 2 - 27} y={h - 4} fontSize={10} fill="#666">
+ {keys[0]}
+ </text>
+ <circle cx={w / 2 + 25} cy={h - 8} r={3} fill={colors[1]} />
+ <text x={w / 2 + 33} y={h - 4} fontSize={10} fill="#666">
+ {keys[1]}
+ </text>
+ </svg>
+ );
+}
+
+function SingleLineChart({
+ data,
+ height = 240,
+ color = '#3b82f6',
+}: {
+ data: SinglePoint[];
+ height?: number;
+ color?: string;
+}) {
+ const w = 500;
+ const h = height;
+ const pad = {top: 20, right: 20, bottom: 30, left: 50};
+ const cw = w - pad.left - pad.right;
+ const ch = h - pad.top - pad.bottom;
+
+ const values = data.map(d => d.value);
+ const minV = Math.min(...values) * 0.95;
+ const maxV = Math.max(...values) * 1.05;
+
+ const xScale = (i: number) => pad.left + (i / (data.length - 1)) * cw;
+ const yScale = (v: number) =>
+ pad.top + ch - ((v - minV) / (maxV - minV)) * ch;
+
+ const line = data
+ .map((d, i) => `${i === 0 ? 'M' : 'L'}${xScale(i)},${yScale(d.value)}`)
+ .join(' ');
+
+ return (
+ <svg viewBox={`0 0 ${w} ${h}`} style={{width: '100%', height}}>
+ {[0, 0.25, 0.5, 0.75, 1].map(pct => {
+ const y = pad.top + ch * (1 - pct);
+ const val = minV + (maxV - minV) * pct;
+ return (
+ <g key={pct}>
+ <line
+ x1={pad.left}
+ x2={w - pad.right}
+ y1={y}
+ y2={y}
+ stroke="#e5e7eb"
+ strokeWidth={0.5}
+ />
+ <text
+ x={pad.left - 6}
+ y={y + 4}
+ textAnchor="end"
+ fontSize={10}
+ fill="#999">
+ {Math.round(val)}
+ </text>
+ </g>
+ );
+ })}
+ {data.map((d, i) =>
+ i % Math.ceil(data.length / 6) === 0 ? (
+ <text
+ key={i}
+ x={xScale(i)}
+ y={h - 6}
+ textAnchor="middle"
+ fontSize={10}
+ fill="#999">
+ {d.label}
+ </text>
+ ) : null,
+ )}
+ <path d={line} fill="none" stroke={color} strokeWidth={2} />
+ </svg>
+ );
+}
+
+// =============================================================================
+// Reusable pieces
+// =============================================================================
+
+function StatCard({
+ label,
+ value,
+ change,
+ source,
+}: {
+ label: string;
+ value: string;
+ change?: string;
+ source?: string;
+}) {
+ return (
+ <XDSCard padding={4}>
+ <XDSVStack gap={1}>
+ <XDSText type="supporting" color="secondary">
+ {label}
+ </XDSText>
+ <div {...stylex.props(styles.statValueRow)}>
+ <XDSText type="large" weight="bold">
+ {value}
+ </XDSText>
+ {change && (
+ <span
+ {...stylex.props(
+ change.startsWith('-')
+ ? styles.changeNegative
+ : styles.changePositive,
+ )}>
+ {change}
+ </span>
+ )}
+ </div>
+ {source && (
+ <XDSText type="supporting" color="disabled">
+ {source}
+ </XDSText>
+ )}
+ </XDSVStack>
+ </XDSCard>
+ );
+}
+
+function ChartCard({
+ title,
+ children,
+ queryNamespace = 'scuba',
+ queryText = '-- No query details available',
+}: {
+ title: string;
+ children: React.ReactNode;
+ queryNamespace?: string;
+ queryText?: string;
+}) {
+ const [isInfoOpen, setIsInfoOpen] = useState(false);
+
+ return (
+ <>
+ <XDSCard padding={4}>
+ <XDSVStack gap={2}>
+ <XDSHStack gap={2} hAlign="between" vAlign="start">
+ <XDSText type="body" weight="bold">
+ {title}
+ </XDSText>
+ <XDSHStack gap={1.5}>
+ <XDSButton
+ label="View query details"
+ tooltip="View query details"
+ variant="ghost"
+ size="xs"
+ icon={<InformationCircleIcon style={{width: 14, height: 14}} />}
+ onClick={() => setIsInfoOpen(true)}
+ />
+ <XDSMoreMenu
+ label="Refresh"
+ icon={<ArrowPathIcon style={{width: 14, height: 14}} />}
+ size="xs"
+ items={[{label: 'Refresh data', onClick: () => {}}]}
+ />
+ <XDSMoreMenu
+ label="Copy link or image"
+ icon={<LinkIcon style={{width: 14, height: 14}} />}
+ size="xs"
+ items={[
+ {label: 'Copy link', onClick: () => {}},
+ {label: 'Copy image', onClick: () => {}},
+ ]}
+ />
+ </XDSHStack>
+ </XDSHStack>
+ <div {...stylex.props(styles.chartInner)}>{children}</div>
+ </XDSVStack>
+ </XDSCard>
+
+ <XDSDialog
+ isOpen={isInfoOpen}
+ onOpenChange={setIsInfoOpen}
+ purpose="info"
+ width={640}>
+ <XDSLayout
+ header={
+ <XDSDialogHeader
+ title="Query Details"
+ subtitle={title}
+ onOpenChange={setIsInfoOpen}
+ />
+ }
+ content={
+ <XDSLayoutContent>
+ <XDSVStack gap={3}>
+ <XDSHStack gap={2} hAlign="between" vAlign="center">
+ <XDSHStack gap={2}>
+ <XDSText type="body" weight="bold">
+ SQL Query
+ </XDSText>
+ <XDSText type="body" color="secondary">
+ namespace: {queryNamespace}
+ </XDSText>
+ </XDSHStack>
+ <XDSHStack gap={2}>
+ <XDSButton
+ label="Daiquery"
+ tooltip="Open in Daiquery"
+ variant="secondary"
+ size="sm"
+ endSlot={
+ <ArrowTopRightOnSquareIcon
+ style={{width: 14, height: 14}}
+ />
+ }>
+ Daiquery
+ </XDSButton>
+ <XDSButton
+ label="Copy"
+ tooltip="Copy"
+ variant="secondary"
+ size="sm"
+ icon={
+ <ClipboardDocumentIcon
+ style={{width: 14, height: 14}}
+ />
+ }
+ />
+ <XDSButton
+ label="Download image"
+ tooltip="Download"
+ variant="secondary"
+ size="sm"
+ icon={
+ <ArrowDownTrayIcon style={{width: 14, height: 14}} />
+ }
+ />
+ </XDSHStack>
+ </XDSHStack>
+ <XDSCard padding={3}>
+ <pre
+ style={{
+ margin: 0,
+ fontSize: '0.8125rem',
+ color: 'var(--color-text-secondary)',
+ whiteSpace: 'pre-wrap',
+ fontFamily: 'monospace',
+ }}>
+ {queryText}
+ </pre>
+ </XDSCard>
+ </XDSVStack>
+ </XDSLayoutContent>
+ }
+ footer={
+ <XDSLayoutFooter hasDivider>
+ <XDSHStack gap={2} hAlign="end">
+ <XDSButton
+ label="Close"
+ variant="secondary"
+ onClick={() => setIsInfoOpen(false)}>
+ Close
+ </XDSButton>
+ </XDSHStack>
+ </XDSLayoutFooter>
+ }
+ />
+ </XDSDialog>
+ </>
+ );
+}
+
+// =============================================================================
+// Table columns
+// =============================================================================
+
+const columns: XDSTableColumn<ComponentAdoptionRow>[] = [
+ {
+ key: 'component',
+ header: 'Component',
+ width: proportional(1),
+ renderCell: (item: ComponentAdoptionRow) => (
+ <XDSText type="body" weight="bold">
+ {item.component}
+ </XDSText>
+ ),
+ },
+ {
+ key: 'usages',
+ header: 'Usages',
+ width: proportional(1),
+ renderCell: (item: ComponentAdoptionRow) => (
+ <XDSText type="body">{item.usages.toLocaleString()}</XDSText>
+ ),
+ },
+ {
+ key: 'files',
+ header: 'Files',
+ width: proportional(1),
+ renderCell: (item: ComponentAdoptionRow) => (
+ <XDSText type="body">{item.files.toLocaleString()}</XDSText>
+ ),
+ },
+ {
+ key: 'oncalls',
+ header: 'Oncalls',
+ width: proportional(1),
+ renderCell: (item: ComponentAdoptionRow) => (
+ <XDSText type="body">{String(item.oncalls)}</XDSText>
+ ),
+ },
+ {
+ key: 'teams',
+ header: 'Teams',
+ width: proportional(1),
+ renderCell: (item: ComponentAdoptionRow) => (
+ <XDSText type="body">{String(item.teams)}</XDSText>
+ ),
+ },
+ {
+ key: 'firstInstance',
+ header: 'First Instance',
+ width: proportional(1),
+ renderCell: (item: ComponentAdoptionRow) => (
+ <XDSText type="supporting" color="secondary">
+ {item.firstInstance}
+ </XDSText>
+ ),
+ },
+];
+
+// =============================================================================
+// Page: Overview
+// =============================================================================
+
+const PAGE_SIZE = 10;
+
+function OverviewContent() {
+ const [ovTab, setOvTab] = useState('usage');
+ const [search, setSearch] = useState('');
+ const [tablePage, setTablePage] = useState(1);
+ const [dsLibrary, setDsLibrary] = useState('XDS on Intern (WWW)');
+
+ const filteredRows = useMemo(() => {
+ if (!search.trim()) return componentAdoptionData;
+ const q = search.toLowerCase();
+ return componentAdoptionData.filter(row =>
+ row.component.toLowerCase().includes(q),
+ );
+ }, [search]);
+
+ const totalPages = Math.ceil(filteredRows.length / PAGE_SIZE);
+ const pagedRows = filteredRows.slice(
+ (tablePage - 1) * PAGE_SIZE,
+ tablePage * PAGE_SIZE,
+ );
+
+ return (
+ <XDSVStack gap={6}>
+ <XDSTabList
+ value={ovTab}
+ onChange={(v: string) => setOvTab(v)}
+ hasDivider>
+ <XDSTab value="usage" label="Overview" />
+ <XDSTab value="ds-details" label="Design System Details" />
+ </XDSTabList>
+
+ {ovTab === 'usage' && (
+ <XDSVStack gap={6}>
+ <XDSVStack gap={3}>
+ <span {...stylex.props(styles.sectionLabel)}>
+ www vs Nest Usage
+ </span>
+ <div {...stylex.props(styles.statsRow)}>
+ {overviewStats.map(stat => (
+ <StatCard key={stat.label} {...stat} />
+ ))}
+ </div>
+ </XDSVStack>
+
+ <div {...stylex.props(styles.chartsGrid)}>
+ <ChartCard
+ title="Daily Active Users (14d) — Intern vs Nest"
+ queryNamespace="scuba"
+ queryText={
+ '-- Intern: vitals_event (Quartz) APPROX_COUNT_DISTINCT(userid)\n-- Nest: nest_traces APPROX_COUNT_DISTINCT_HLL(user.id)'
+ }>
+ <MiniLineChart data={dauData} keys={['intern', 'nest']} />
+ </ChartCard>
+ <ChartCard title="Daily New Tool / App Creation — Intern vs Nest">
+ <MiniLineChart data={creationData} keys={['intern', 'nest']} />
+ </ChartCard>
+ </div>
+
+ <XDSDivider />
+
+ <XDSVStack gap={3}>
+ <span {...stylex.props(styles.sectionLabel)}>
+ Design System Adoption
+ </span>
+ <XDSTable<AdoptionMatrixRow>
+ data={adoptionMatrixData}
+ columns={adoptionMatrixColumns}
+ idKey="id"
+ density="balanced"
+ dividers="grid"
+ />
+ </XDSVStack>
+ </XDSVStack>
+ )}
+
+ {ovTab === 'ds-details' && (
+ <XDSVStack gap={6}>
+ <div {...stylex.props(styles.chartsGrid)}>
+ {/* Left column */}
+ <XDSVStack gap={3}>
+ <span {...stylex.props(styles.sectionLabel)}>
+ XDS on Intern (www)
+ </span>
+ <ChartCard title="XDS Component Count Over Time">
+ <SingleLineChart data={componentCountData} />
+ </ChartCard>
+ <ChartCard title="% Oncalls Using XDS WWW by Org">
+ <div style={{maxHeight: 260, overflowY: 'auto'}}>
+ {oncallsByOrg.map(org => (
+ <div key={org.org} {...stylex.props(styles.orgBar)}>
+ <span {...stylex.props(styles.orgLabel)}>{org.org}</span>
+ <div {...stylex.props(styles.barTrack)}>
+ <div
+ {...stylex.props(styles.barFill)}
+ style={{width: `${org.pct}%`}}
+ />
+ </div>
+ <span {...stylex.props(styles.pctLabel)}>{org.pct}%</span>
+ </div>
+ ))}
+ </div>
+ </ChartCard>
+ </XDSVStack>
+
+ {/* Right column */}
+ <XDSVStack gap={3}>
+ <span {...stylex.props(styles.sectionLabel)}>
+ Nest Design Systems (NDS / XDS OSS)
+ </span>
+ <ChartCard title="Nest Design System Component Count Over Time">
+ <SingleLineChart data={componentCountData} />
+ </ChartCard>
+ <ChartCard title="% Apps Using NDS / XDS OSS by Org">
+ <div style={{maxHeight: 260, overflowY: 'auto'}}>
+ {oncallsByOrg.map(org => (
+ <div key={org.org} {...stylex.props(styles.orgBar)}>
+ <span {...stylex.props(styles.orgLabel)}>{org.org}</span>
+ <div {...stylex.props(styles.barTrack)}>
+ <div
+ {...stylex.props(styles.barFill)}
+ style={{width: `${org.pct}%`}}
+ />
+ </div>
+ <span {...stylex.props(styles.pctLabel)}>{org.pct}%</span>
+ </div>
+ ))}
+ </div>
+ </ChartCard>
+ </XDSVStack>
+ </div>
+
+ <XDSDivider />
+
+ {/* Component Adoption Table */}
+ <XDSVStack gap={3}>
+ <span {...stylex.props(styles.sectionLabel)}>
+ XDS Component Adoption Details
+ </span>
+ <XDSHStack gap={3} vAlign="end">
+ <XDSDropdownMenu
+ button={{
+ label: dsLibrary,
+ variant: 'secondary',
+ }}
+ items={[
+ {
+ label: 'XDS on Intern (WWW)',
+ onClick: () => {
+ setDsLibrary('XDS on Intern (WWW)');
+ setSearch('');
+ setTablePage(1);
+ },
+ },
+ {
+ label: 'Nest Design System (NDS/XDS OSS)',
+ onClick: () => {
+ setDsLibrary('Nest Design System (NDS/XDS OSS)');
+ setSearch('');
+ setTablePage(1);
+ },
+ },
+ ]}
+ />
+ <div {...stylex.props(styles.searchFill)}>
+ <XDSTextInput
+ label="Search components"
+ isLabelHidden
+ placeholder={`Search ${dsLibrary} components...`}
+ value={search}
+ onChange={(v: string) => {
+ setSearch(v);
+ setTablePage(1);
+ }}
+ />
+ </div>
+ <XDSButton label="Search" variant="secondary">
+ Search
+ </XDSButton>
+ </XDSHStack>
+ <div {...stylex.props(styles.chartsGrid)}>
+ <ChartCard
+ title={`${dsLibrary} Component Growth: ${search || 'XDSButton'}`}>
+ <SingleLineChart data={componentCountData} />
+ </ChartCard>
+ <ChartCard
+ title={`${dsLibrary} Component Adoption: ${search || 'XDSButton'}`}>
+ <SingleLineChart data={componentCountData} />
+ </ChartCard>
+ </div>
+ <XDSTable<ComponentAdoptionRow>
+ data={pagedRows}
+ columns={columns}
+ idKey="id"
+ density="balanced"
+ dividers="rows"
+ hasHover
+ />
+ <XDSHStack gap={2} hAlign="between" vAlign="center">
+ {totalPages > 1 ? (
+ <XDSPagination
+ page={tablePage}
+ totalPages={totalPages}
+ onChange={setTablePage}
+ />
+ ) : (
+ <div />
+ )}
+ <XDSHStack gap={0.5}>
+ <XDSButton
+ label="View query details"
+ tooltip="View query details"
+ variant="ghost"
+ size="xs"
+ icon={
+ <InformationCircleIcon style={{width: 14, height: 14}} />
+ }
+ />
+ <XDSMoreMenu
+ label="Refresh"
+ icon={<ArrowPathIcon style={{width: 14, height: 14}} />}
+ size="xs"
+ items={[{label: 'Refresh data', onClick: () => {}}]}
+ />
+ <XDSMoreMenu
+ label="Copy link or image"
+ icon={<LinkIcon style={{width: 14, height: 14}} />}
+ size="xs"
+ items={[
+ {label: 'Copy link', onClick: () => {}},
+ {label: 'Copy image', onClick: () => {}},
+ ]}
+ />
+ </XDSHStack>
+ </XDSHStack>
+ </XDSVStack>
+
+ {/* Quick Links */}
+ <div {...stylex.props(styles.linksRow)}>
+ {[
+ {
+ name: 'XDS WWW on Nest',
+ href: 'https://example-xds.nest.example.net/',
+ },
+ {
+ name: 'XDS OSS Storybook',
+ href: 'https://facebookexperimental.github.io/xds/',
+ },
+ {
+ name: 'NDS Storybook',
+ href: 'https://nds-storybook.nest.example.net/storybook/index.html?path=/',
+ },
+ ].map(({name, href}) => (
+ <XDSButton
+ key={name}
+ label={name}
+ variant="secondary"
+ size="sm"
+ onClick={() => window.open(href, '_blank')}>
+ {name} ↗
+ </XDSButton>
+ ))}
+ </div>
+ </XDSVStack>
+ )}
+ </XDSVStack>
+ );
+}
+
+// =============================================================================
+// Dashboard Shell
+// =============================================================================
+
+function AnalyticsDashboard() {
+ return (
+ <div {...stylex.props(styles.wash)}>
+ <XDSTopNav
+ label="Main navigation"
+ heading={<XDSTopNavHeading heading="Internal Web Apps Analytics" />}
+ endContent={
+ <>
+ <XDSButton
+ label="Notifications"
+ variant="ghost"
+ icon={<XBracketIcon style={{width: 16, height: 16}} />}
+ onClick={() =>
+ window.open('https://example.com/dashboard', '_blank')
+ }
+ />
+ <XDSButton
+ label="Nest"
+ variant="ghost"
+ icon={<NestIcon style={{width: 16, height: 16}} />}
+ onClick={() =>
+ window.open('https://example.com/dashboard', '_blank')
+ }
+ />
+ </>
+ }
+ />
+
+ <div {...stylex.props(styles.page)}>
+ <XDSVStack gap={6}>
+ <OverviewContent />
+ </XDSVStack>
+ </div>
+ </div>
+ );
+}
+
+// =============================================================================
+// Story
+// =============================================================================
+
+const meta: Meta = {
+ title: 'Pages/Analytics Dashboard',
+ parameters: {
+ layout: 'fullscreen',
+ },
+};
+
+export default meta;
+
+export const Overview: StoryObj = {
+ render: () => <AnalyticsDashboard />,
+};
diff --git a/apps/storybook/stories/ThemeEditor.stories.tsx b/apps/storybook/stories/ThemeEditor.stories.tsx
new file mode 100644
index 0000000000..8cdb8ef3d8
--- /dev/null
+++ b/apps/storybook/stories/ThemeEditor.stories.tsx
@@ -0,0 +1,1978 @@
+import type {Meta, StoryObj} from '@storybook/react';
+import * as React from 'react';
+import {XDSButton} from '@xds/core/Button';
+import {XDSTextInput} from '@xds/core/TextInput';
+import {XDSBadge} from '@xds/core/Badge';
+import {XDSCard} from '@xds/core/Card';
+import {XDSStack} from '@xds/core/Stack';
+import {XDSText, XDSHeading} from '@xds/core/Text';
+import {XDSSwitch} from '@xds/core/Switch';
+import {XDSAvatar} from '@xds/core/Avatar';
+import {XDSBanner} from '@xds/core/Banner';
+import {XDSTabList} from '@xds/core/TabList';
+import {XDSDialog} from '@xds/core/Dialog';
+import {XDSToken} from '@xds/core/Token';
+import {XDSSlider} from '@xds/core/Slider';
+import {XDSProgressBar} from '@xds/core/ProgressBar';
+import {XDSCheckboxInput} from '@xds/core/CheckboxInput';
+import {XDSRadioList, XDSRadioListItem} from '@xds/core/RadioList';
+import {XDSTable} from '@xds/core/Table';
+import type {XDSTableColumn} from '@xds/core/Table';
+import {XDSDivider} from '@xds/core/Divider';
+import {XDSTopNav, XDSTopNavHeading} from '@xds/core/TopNav';
+import {XDSDropdownMenu} from '@xds/core/DropdownMenu';
+import {XDSTheme, defineTheme} from '@xds/core/theme';
+import * as stylex from '@stylexjs/stylex';
+import {colorVars, spacingVars} from '@xds/core/theme/tokens.stylex';
+import {
+ MagnifyingGlassIcon,
+ BellIcon,
+ UserCircleIcon,
+ SunIcon,
+ MoonIcon,
+ ArrowUturnLeftIcon,
+ ArrowUturnRightIcon,
+ ArrowDownTrayIcon,
+ ShareIcon,
+ CodeBracketIcon,
+ BookmarkIcon,
+} from '@heroicons/react/24/outline';
+import {
+ colorDefaults,
+ spacingDefaults,
+ radiusDefaults,
+ typographyDefaults,
+ textSizeDefaults,
+ fontWeightDefaults,
+ typeScaleDefaults,
+ sizeDefaults,
+ shadowDefaults,
+ transitionDefaults,
+} from '@xds/core/theme';
+import {defaultIconRegistry} from '@xds/theme-default';
+
+// =============================================================================
+// Token Groups for the Editor
+// =============================================================================
+
+const TOKEN_GROUPS = {
+ colors: {
+ label: 'Colors',
+ description:
+ 'Semantic color tokens for text, backgrounds, borders, and states',
+ tokens: colorDefaults,
+ },
+ spacing: {
+ label: 'Spacing',
+ description: 'Consistent spacing scale for margins, padding, and gaps',
+ tokens: spacingDefaults,
+ },
+ radius: {
+ label: 'Radius',
+ description: 'Border radius tokens for rounded corners',
+ tokens: radiusDefaults,
+ },
+ typography: {
+ label: 'Typography',
+ description: 'Font families, sizes, weights, and line heights',
+ tokens: {
+ ...typographyDefaults,
+ ...textSizeDefaults,
+ ...fontWeightDefaults,
+ ...typeScaleDefaults,
+ },
+ },
+ size: {
+ label: 'Size',
+ description: 'Component size tokens (sm, md, lg)',
+ tokens: sizeDefaults,
+ },
+ elevation: {
+ label: 'Elevation',
+ description: 'Shadow and elevation tokens',
+ tokens: shadowDefaults,
+ },
+ transition: {
+ label: 'Transition',
+ description: 'Animation timing tokens',
+ tokens: transitionDefaults,
+ },
+} as const;
+
+type TokenGroupKey = keyof typeof TOKEN_GROUPS;
+
+// =============================================================================
+// Color Categories for better organization
+// =============================================================================
+
+const COLOR_CATEGORIES = {
+ 'Core Semantic': [
+ '--color-accent',
+ '--color-accent-deemphasized',
+ '--color-accent-text',
+ '--color-surface',
+ '--color-wash',
+ '--color-overlay',
+ ],
+ 'Interactive States': [
+ '--color-hover-overlay',
+ '--color-pressed-overlay',
+ '--color-focus-outline',
+ '--color-focus-outline-error',
+ '--color-focus-outline-success',
+ '--color-focus-outline-warning',
+ '--color-deemphasized',
+ ],
+ Text: [
+ '--color-text-primary',
+ '--color-text-secondary',
+ '--color-text-disabled',
+ '--color-text-link',
+ '--color-text-placeholder',
+ '--color-text-on-media',
+ ],
+ Icon: [
+ '--color-icon-primary',
+ '--color-icon-secondary',
+ '--color-icon-tertiary',
+ '--color-icon-disabled',
+ '--color-icon-on-media',
+ ],
+ 'Surface Variants': ['--color-card', '--color-popover', '--color-navbar'],
+ 'Status/Sentiment': [
+ '--color-positive',
+ '--color-positive-deemphasized',
+ '--color-negative',
+ '--color-negative-deemphasized',
+ '--color-warning',
+ '--color-warning-deemphasized',
+ '--color-educational',
+ '--color-educational-deemphasized',
+ ],
+ Divider: [
+ '--color-divider',
+ '--color-divider-high-contrast',
+ '--color-divider-emphasized',
+ ],
+ Effects: [
+ '--color-disabled-overlay',
+ '--color-glimmer',
+ '--color-glimmer-high-contrast',
+ '--color-shadow-elevation',
+ '--color-hover-tint',
+ ],
+ 'Palette: Blue': [
+ '--color-blue-background',
+ '--color-blue-border',
+ '--color-blue-icon',
+ '--color-blue-text',
+ ],
+ 'Palette: Green': [
+ '--color-green-background',
+ '--color-green-border',
+ '--color-green-icon',
+ '--color-green-text',
+ ],
+ 'Palette: Red': [
+ '--color-red-background',
+ '--color-red-border',
+ '--color-red-icon',
+ '--color-red-text',
+ ],
+ 'Palette: Yellow': [
+ '--color-yellow-background',
+ '--color-yellow-border',
+ '--color-yellow-icon',
+ '--color-yellow-text',
+ ],
+ 'Palette: Orange': [
+ '--color-orange-background',
+ '--color-orange-border',
+ '--color-orange-icon',
+ '--color-orange-text',
+ ],
+ 'Palette: Purple': [
+ '--color-purple-background',
+ '--color-purple-border',
+ '--color-purple-icon',
+ '--color-purple-text',
+ ],
+ 'Palette: Pink': [
+ '--color-pink-background',
+ '--color-pink-border',
+ '--color-pink-icon',
+ '--color-pink-text',
+ ],
+ 'Palette: Teal': [
+ '--color-teal-background',
+ '--color-teal-border',
+ '--color-teal-icon',
+ '--color-teal-text',
+ ],
+ 'Palette: Cyan': [
+ '--color-cyan-background',
+ '--color-cyan-border',
+ '--color-cyan-icon',
+ '--color-cyan-text',
+ ],
+ 'Palette: Gray': [
+ '--color-gray-background',
+ '--color-gray-border',
+ '--color-gray-icon',
+ '--color-gray-text',
+ ],
+} as const;
+
+// =============================================================================
+// Typography Categories - Organized by semantic usage
+// =============================================================================
+
+/**
+ * Typography tokens organized by semantic text styles.
+ * Each style shows which tokens it uses (size, weight, line-height).
+ */
+const TYPOGRAPHY_CATEGORIES = {
+ 'Font Families': ['--font-body', '--font-heading', '--font-code'],
+ 'Heading 1': {
+ description: 'Primary page title',
+ tokens: ['--text-2xl', '--font-weight-semibold', '--leading-tight'],
+ },
+ 'Heading 2': {
+ description: 'Section title',
+ tokens: ['--text-xl', '--font-weight-semibold', '--leading-snug'],
+ },
+ 'Heading 3': {
+ description: 'Subsection title',
+ tokens: ['--text-lg', '--font-weight-semibold', '--leading-tight'],
+ },
+ 'Heading 4': {
+ description: 'Card/component title',
+ tokens: ['--text-base', '--font-weight-semibold', '--leading-base'],
+ },
+ 'Heading 5': {
+ description: 'Minor heading',
+ tokens: ['--text-base', '--font-weight-semibold', '--leading-base'],
+ },
+ 'Heading 6': {
+ description: 'Smallest heading',
+ tokens: ['--text-xsm', '--font-weight-semibold', '--leading-snug'],
+ },
+ 'Body Text': {
+ description: 'Default paragraph text',
+ tokens: ['--text-base', '--font-weight-normal', '--leading-base'],
+ },
+ 'Large Text': {
+ description: 'Intro/lead paragraphs',
+ tokens: ['--text-lg', '--font-weight-normal', '--leading-normal'],
+ },
+ 'Label Text': {
+ description: 'Form labels, UI labels',
+ tokens: ['--text-base', '--font-weight-medium', '--leading-base'],
+ },
+ 'Supporting Text': {
+ description: 'Captions, helper text',
+ tokens: ['--text-xsm', '--font-weight-normal', '--leading-snug'],
+ },
+ 'Code Text': {
+ description: 'Inline code, code blocks',
+ tokens: ['--text-base', '--font-weight-normal', '--leading-base'],
+ },
+ 'All Text Sizes': [
+ '--text-4xs',
+ '--text-3xs',
+ '--text-2xs',
+ '--text-xsm',
+ '--text-sm',
+ '--text-base',
+ '--text-lg',
+ '--text-xl',
+ '--text-2xl',
+ '--text-3xl',
+ '--text-4xl',
+ ],
+ 'All Font Weights': [
+ '--font-weight-normal',
+ '--font-weight-medium',
+ '--font-weight-semibold',
+ '--font-weight-bold',
+ ],
+ 'All Line Heights': [
+ '--leading-tight',
+ '--leading-snug',
+ '--leading-base',
+ '--leading-normal',
+ '--leading-relaxed',
+ ],
+} as const;
+
+type TypographyCategoryValue =
+ | string[]
+ | {description: string; tokens: string[]};
+
+// =============================================================================
+// Helper Functions
+// =============================================================================
+
+/**
+ * Parse light-dark() values to extract light and dark mode colors
+ */
+function parseLightDark(value: string): {light: string; dark: string} | null {
+ const match = value.match(/^light-dark\(([^,]+),\s*([^)]+)\)$/);
+ if (match) {
+ return {light: match[1].trim(), dark: match[2].trim()};
+ }
+ return null;
+}
+
+/**
+ * Parse a color value to extract hex and alpha components
+ * Handles: #RGB, #RRGGBB, #RRGGBBAA, rgba(), etc.
+ */
+function parseColorWithAlpha(
+ value: string,
+): {hex: string; alpha: number} | null {
+ // Handle #RRGGBBAA format
+ const hex8Match = value.match(/^#([0-9A-Fa-f]{8})$/);
+ if (hex8Match) {
+ const hex = '#' + hex8Match[1].slice(0, 6);
+ const alpha = parseInt(hex8Match[1].slice(6, 8), 16) / 255;
+ return {hex, alpha: Math.round(alpha * 100) / 100};
+ }
+
+ // Handle #RRGGBB format
+ const hex6Match = value.match(/^#([0-9A-Fa-f]{6})$/);
+ if (hex6Match) {
+ return {hex: value, alpha: 1};
+ }
+
+ // Handle #RGB format
+ const hex3Match = value.match(/^#([0-9A-Fa-f]{3})$/);
+ if (hex3Match) {
+ const r = hex3Match[1][0];
+ const g = hex3Match[1][1];
+ const b = hex3Match[1][2];
+ return {hex: `#${r}${r}${g}${g}${b}${b}`, alpha: 1};
+ }
+
+ // Handle rgba() format
+ const rgbaMatch = value.match(
+ /rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/,
+ );
+ if (rgbaMatch) {
+ const r = parseInt(rgbaMatch[1], 10).toString(16).padStart(2, '0');
+ const g = parseInt(rgbaMatch[2], 10).toString(16).padStart(2, '0');
+ const b = parseInt(rgbaMatch[3], 10).toString(16).padStart(2, '0');
+ const alpha = rgbaMatch[4] ? parseFloat(rgbaMatch[4]) : 1;
+ return {hex: `#${r}${g}${b}`, alpha};
+ }
+
+ return null;
+}
+
+/**
+ * Convert hex + alpha back to a color string
+ */
+function colorWithAlphaToString(hex: string, alpha: number): string {
+ if (alpha >= 1) {
+ return hex.toUpperCase();
+ }
+ const alphaHex = Math.round(alpha * 255)
+ .toString(16)
+ .padStart(2, '0');
+ return `${hex}${alphaHex}`.toUpperCase();
+}
+
+/**
+ * Get a human-readable label from a token name
+ */
+function getTokenLabel(tokenName: string): string {
+ return tokenName
+ .replace(/^--/, '')
+ .replace(/-/g, ' ')
+ .replace(/\b\w/g, c => c.toUpperCase());
+}
+
+// =============================================================================
+// Token Editor Components
+// =============================================================================
+
+interface ColorSwatchProps {
+ tokenName: string;
+ value: string;
+ onChange: (tokenName: string, value: string) => void;
+ mode: 'light' | 'dark';
+}
+
+function ColorSwatch({tokenName, value, onChange, mode}: ColorSwatchProps) {
+ const parsed = parseLightDark(value);
+ const displayValue = parsed
+ ? mode === 'light'
+ ? parsed.light
+ : parsed.dark
+ : value;
+
+ // Parse color with alpha
+ const colorParsed = parseColorWithAlpha(displayValue);
+ const hasColorPicker = colorParsed !== null;
+
+ const handleColorChange = (newHex: string, newAlpha?: number) => {
+ const alpha = newAlpha ?? colorParsed?.alpha ?? 1;
+ const newColor = colorWithAlphaToString(newHex, alpha);
+ const newValue = parsed
+ ? mode === 'light'
+ ? `light-dark(${newColor}, ${parsed.dark})`
+ : `light-dark(${parsed.light}, ${newColor})`
+ : newColor;
+ onChange(tokenName, newValue);
+ };
+
+ const handleAlphaChange = (newAlpha: number) => {
+ if (colorParsed) {
+ handleColorChange(colorParsed.hex, newAlpha);
+ }
+ };
+
+ return (
+ <div
+ style={{
+ display: 'flex',
+ alignItems: 'center',
+ gap: '12px',
+ padding: '8px 12px',
+ borderRadius: '8px',
+ backgroundColor: 'var(--color-wash)',
+ }}>
+ <div
+ style={{
+ width: '32px',
+ height: '32px',
+ borderRadius: '6px',
+ backgroundColor: displayValue,
+ border: '1px solid var(--color-divider-emphasized)',
+ flexShrink: 0,
+ // Checkerboard pattern for alpha preview
+ backgroundImage:
+ colorParsed && colorParsed.alpha < 1
+ ? `linear-gradient(45deg, #ccc 25%, transparent 25%),
+ linear-gradient(-45deg, #ccc 25%, transparent 25%),
+ linear-gradient(45deg, transparent 75%, #ccc 75%),
+ linear-gradient(-45deg, transparent 75%, #ccc 75%)`
+ : undefined,
+ backgroundSize: '8px 8px',
+ backgroundPosition: '0 0, 0 4px, 4px -4px, -4px 0px',
+ }}>
+ <div
+ style={{
+ width: '100%',
+ height: '100%',
+ borderRadius: '6px',
+ backgroundColor: displayValue,
+ }}
+ />
+ </div>
+ <div style={{flex: 1, minWidth: 0}}>
+ <div
+ style={{
+ fontSize: '13px',
+ fontWeight: 500,
+ color: 'var(--color-text-primary)',
+ marginBottom: '2px',
+ }}>
+ {getTokenLabel(tokenName)}
+ </div>
+ <code
+ style={{
+ fontSize: '11px',
+ color: 'var(--color-text-secondary)',
+ fontFamily: 'var(--font-code)',
+ }}>
+ {tokenName}
+ </code>
+ </div>
+ <div style={{display: 'flex', alignItems: 'center', gap: '6px'}}>
+ {hasColorPicker && colorParsed && (
+ <>
+ <input
+ type="color"
+ value={colorParsed.hex}
+ onChange={e => handleColorChange(e.target.value)}
+ style={{
+ width: '28px',
+ height: '28px',
+ padding: 0,
+ border: 'none',
+ borderRadius: '4px',
+ cursor: 'pointer',
+ }}
+ />
+ <input
+ type="number"
+ min="0"
+ max="100"
+ step="1"
+ value={Math.round(colorParsed.alpha * 100)}
+ onChange={e => handleAlphaChange(Number(e.target.value) / 100)}
+ title="Alpha %"
+ style={{
+ width: '50px',
+ padding: '4px 6px',
+ fontSize: '12px',
+ fontFamily: 'var(--font-code)',
+ border: '1px solid var(--color-divider-emphasized)',
+ borderRadius: '4px',
+ backgroundColor: 'var(--color-surface)',
+ color: 'var(--color-text-primary)',
+ textAlign: 'center',
+ }}
+ />
+ <span
+ style={{
+ fontSize: '11px',
+ color: 'var(--color-text-secondary)',
+ }}>
+ %
+ </span>
+ </>
+ )}
+ <input
+ type="text"
+ value={displayValue}
+ onChange={e => {
+ const newValue = parsed
+ ? mode === 'light'
+ ? `light-dark(${e.target.value}, ${parsed.dark})`
+ : `light-dark(${parsed.light}, ${e.target.value})`
+ : e.target.value;
+ onChange(tokenName, newValue);
+ }}
+ style={{
+ width: '100px',
+ padding: '4px 8px',
+ fontSize: '12px',
+ fontFamily: 'var(--font-code)',
+ border: '1px solid var(--color-divider-emphasized)',
+ borderRadius: '4px',
+ backgroundColor: 'var(--color-surface)',
+ color: 'var(--color-text-primary)',
+ }}
+ />
+ </div>
+ </div>
+ );
+}
+
+interface SpacingEditorProps {
+ tokenName: string;
+ value: string;
+ onChange: (tokenName: string, value: string) => void;
+}
+
+function SpacingEditor({tokenName, value, onChange}: SpacingEditorProps) {
+ const numValue = parseInt(value, 10);
+
+ return (
+ <div
+ style={{
+ display: 'flex',
+ alignItems: 'center',
+ gap: '12px',
+ padding: '8px 12px',
+ borderRadius: '8px',
+ backgroundColor: 'var(--color-wash)',
+ }}>
+ <div
+ style={{
+ width: `${Math.min(numValue, 48)}px`,
+ height: '24px',
+ backgroundColor: 'var(--color-accent)',
+ borderRadius: '4px',
+ flexShrink: 0,
+ }}
+ />
+ <div style={{flex: 1, minWidth: 0}}>
+ <div
+ style={{
+ fontSize: '13px',
+ fontWeight: 500,
+ color: 'var(--color-text-primary)',
+ marginBottom: '2px',
+ }}>
+ {getTokenLabel(tokenName)}
+ </div>
+ <code
+ style={{
+ fontSize: '11px',
+ color: 'var(--color-text-secondary)',
+ fontFamily: 'var(--font-code)',
+ }}>
+ {tokenName}
+ </code>
+ </div>
+ <input
+ type="text"
+ value={value}
+ onChange={e => onChange(tokenName, e.target.value)}
+ style={{
+ width: '80px',
+ padding: '4px 8px',
+ fontSize: '12px',
+ fontFamily: 'var(--font-code)',
+ border: '1px solid var(--color-divider-emphasized)',
+ borderRadius: '4px',
+ backgroundColor: 'var(--color-surface)',
+ color: 'var(--color-text-primary)',
+ }}
+ />
+ </div>
+ );
+}
+
+interface RadiusEditorProps {
+ tokenName: string;
+ value: string;
+ onChange: (tokenName: string, value: string) => void;
+}
+
+function RadiusEditor({tokenName, value, onChange}: RadiusEditorProps) {
+ return (
+ <div
+ style={{
+ display: 'flex',
+ alignItems: 'center',
+ gap: '12px',
+ padding: '8px 12px',
+ borderRadius: '8px',
+ backgroundColor: 'var(--color-wash)',
+ }}>
+ <div
+ style={{
+ width: '32px',
+ height: '32px',
+ backgroundColor: 'var(--color-accent)',
+ borderRadius: value,
+ flexShrink: 0,
+ }}
+ />
+ <div style={{flex: 1, minWidth: 0}}>
+ <div
+ style={{
+ fontSize: '13px',
+ fontWeight: 500,
+ color: 'var(--color-text-primary)',
+ marginBottom: '2px',
+ }}>
+ {getTokenLabel(tokenName)}
+ </div>
+ <code
+ style={{
+ fontSize: '11px',
+ color: 'var(--color-text-secondary)',
+ fontFamily: 'var(--font-code)',
+ }}>
+ {tokenName}
+ </code>
+ </div>
+ <input
+ type="text"
+ value={value}
+ onChange={e => onChange(tokenName, e.target.value)}
+ style={{
+ width: '80px',
+ padding: '4px 8px',
+ fontSize: '12px',
+ fontFamily: 'var(--font-code)',
+ border: '1px solid var(--color-divider-emphasized)',
+ borderRadius: '4px',
+ backgroundColor: 'var(--color-surface)',
+ color: 'var(--color-text-primary)',
+ }}
+ />
+ </div>
+ );
+}
+
+interface TypographyEditorProps {
+ tokenName: string;
+ value: string;
+ onChange: (tokenName: string, value: string) => void;
+}
+
+function TypographyEditor({tokenName, value, onChange}: TypographyEditorProps) {
+ const isFont = tokenName.includes('font-') && !tokenName.includes('weight');
+ const isSize = tokenName.includes('text-');
+ const isWeight = tokenName.includes('weight');
+ const isLeading = tokenName.includes('leading');
+
+ return (
+ <div
+ style={{
+ display: 'flex',
+ alignItems: 'center',
+ gap: '12px',
+ padding: '8px 12px',
+ borderRadius: '8px',
+ backgroundColor: 'var(--color-wash)',
+ }}>
+ <div
+ style={{
+ width: '48px',
+ height: '32px',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ fontSize: isSize ? value : '14px',
+ fontWeight: isWeight ? value : 400,
+ fontFamily: isFont ? value : 'inherit',
+ lineHeight: isLeading ? value : 1.4,
+ color: 'var(--color-text-primary)',
+ flexShrink: 0,
+ }}>
+ Aa
+ </div>
+ <div style={{flex: 1, minWidth: 0}}>
+ <div
+ style={{
+ fontSize: '13px',
+ fontWeight: 500,
+ color: 'var(--color-text-primary)',
+ marginBottom: '2px',
+ }}>
+ {getTokenLabel(tokenName)}
+ </div>
+ <code
+ style={{
+ fontSize: '11px',
+ color: 'var(--color-text-secondary)',
+ fontFamily: 'var(--font-code)',
+ }}>
+ {tokenName}
+ </code>
+ </div>
+ <input
+ type="text"
+ value={value}
+ onChange={e => onChange(tokenName, e.target.value)}
+ style={{
+ width: isFont ? '200px' : '80px',
+ padding: '4px 8px',
+ fontSize: '12px',
+ fontFamily: 'var(--font-code)',
+ border: '1px solid var(--color-divider-emphasized)',
+ borderRadius: '4px',
+ backgroundColor: 'var(--color-surface)',
+ color: 'var(--color-text-primary)',
+ }}
+ />
+ </div>
+ );
+}
+
+// =============================================================================
+// Component Preview
+// =============================================================================
+
+// =============================================================================
+// Spacing Table Data
+// =============================================================================
+
+interface SpacingRow extends Record<string, unknown> {
+ token: string;
+ value: string;
+ preview: React.ReactNode;
+}
+
+const spacingTableColumns: XDSTableColumn<SpacingRow>[] = [
+ {key: 'token', header: 'Token'},
+ {key: 'value', header: 'Value'},
+ {key: 'preview', header: 'Preview'},
+];
+
+function ComponentPreview() {
+ const [dialogOpen, setDialogOpen] = React.useState(false);
+ const [selectedTab, setSelectedTab] = React.useState('overview');
+ const [switchValue, setSwitchValue] = React.useState(true);
+ const [sliderValue, setSliderValue] = React.useState(50);
+ const [checkboxValue, setCheckboxValue] = React.useState(false);
+ const [radioValue, setRadioValue] = React.useState('option1');
+
+ // Spacing data for table
+ const spacingData: SpacingRow[] = Object.entries(spacingDefaults).map(
+ ([token, value]) => ({
+ token,
+ value,
+ preview: (
+ <div
+ style={{
+ width: value,
+ height: '16px',
+ backgroundColor: 'var(--color-accent)',
+ borderRadius: '2px',
+ }}
+ />
+ ),
+ }),
+ );
+
+ return (
+ <div style={{display: 'flex', flexDirection: 'column', gap: '32px'}}>
+ {/* Typography Scale - Article Example */}
+ <div>
+ <XDSText type="label" style={{marginBottom: '16px', display: 'block'}}>
+ Typography Scale
+ </XDSText>
+ <XDSCard padding="lg">
+ <article>
+ <XDSHeading level={1}>Building Design Systems</XDSHeading>
+ <XDSText
+ type="supporting"
+ style={{
+ marginTop: '8px',
+ marginBottom: '24px',
+ display: 'block',
+ }}>
+ A guide to creating consistent, scalable UI components
+ </XDSText>
+
+ <XDSText
+ type="large"
+ style={{marginBottom: '16px', display: 'block'}}>
+ Design systems provide a shared vocabulary between designers and
+ developers, enabling teams to build products faster and more
+ consistently.
+ </XDSText>
+
+ <XDSDivider style={{margin: '24px 0'}} />
+
+ <XDSHeading level={2} style={{marginBottom: '12px'}}>
+ Why Tokens Matter
+ </XDSHeading>
+ <XDSText
+ type="body"
+ style={{marginBottom: '16px', display: 'block'}}>
+ Design tokens are the visual design atoms of the design system —
+ specifically, they are named entities that store visual design
+ attributes. We use them in place of hard-coded values to ensure
+ flexibility and consistency.
+ </XDSText>
+
+ <XDSHeading level={3} style={{marginBottom: '8px'}}>
+ Example: Using Color Tokens
+ </XDSHeading>
+ <XDSText
+ type="body"
+ style={{marginBottom: '12px', display: 'block'}}>
+ Instead of using raw hex values, reference semantic tokens:
+ </XDSText>
+
+ {/* Code Block */}
+ <pre
+ style={{
+ padding: '16px',
+ borderRadius: 'var(--radius-element)',
+ backgroundColor: 'var(--color-wash)',
+ border: '1px solid var(--color-divider)',
+ fontFamily: 'var(--font-code)',
+ fontSize: 'var(--text-sm)',
+ lineHeight: 'var(--leading-normal)',
+ overflow: 'auto',
+ margin: '0 0 16px 0',
+ }}>
+ <code
+ style={{
+ color: 'var(--color-text-primary)',
+ }}>
+ {`// ❌ Don't use raw values
+const styles = stylex.create({
+ button: {
+ backgroundColor: '#0064E0',
+ color: '#FFFFFF',
+ },
+});
+
+// ✅ Use semantic tokens
+const styles = stylex.create({
+ button: {
+ backgroundColor: colorVars['--color-accent'],
+ color: colorVars['--color-text-on-media'],
+ },
+});`}
+ </code>
+ </pre>
+
+ <XDSHeading level={4} style={{marginBottom: '8px'}}>
+ Benefits of This Approach
+ </XDSHeading>
+ <XDSText
+ type="body"
+ style={{marginBottom: '8px', display: 'block'}}>
+ Using tokens provides several advantages:
+ </XDSText>
+ <ul
+ style={{
+ margin: '0 0 16px 0',
+ paddingLeft: '24px',
+ color: 'var(--color-text-primary)',
+ fontSize: 'var(--text-base)',
+ lineHeight: 'var(--leading-base)',
+ }}>
+ <li>Automatic dark mode support via light-dark()</li>
+ <li>Centralized theme customization</li>
+ <li>Consistent visual language across components</li>
+ <li>Easy global updates when design changes</li>
+ </ul>
+
+ <XDSText type="supporting">
+ Last updated: March 2026 · 5 min read
+ </XDSText>
+ </article>
+ </XDSCard>
+ </div>
+
+ {/* Button Sizes */}
+ <div>
+ <XDSText type="label" style={{marginBottom: '12px', display: 'block'}}>
+ Button Sizes
+ </XDSText>
+ <div
+ style={{
+ display: 'flex',
+ flexDirection: 'column',
+ gap: '16px',
+ }}>
+ <div style={{display: 'flex', gap: '8px', alignItems: 'center'}}>
+ <XDSText type="supporting" style={{width: '40px', flexShrink: 0}}>
+ sm
+ </XDSText>
+ <XDSButton label="Primary" variant="primary" size="sm" />
+ <XDSButton label="Secondary" variant="secondary" size="sm" />
+ <XDSButton label="Ghost" variant="ghost" size="sm" />
+ <XDSButton label="Destructive" variant="destructive" size="sm" />
+ </div>
+ <div style={{display: 'flex', gap: '8px', alignItems: 'center'}}>
+ <XDSText type="supporting" style={{width: '40px', flexShrink: 0}}>
+ md
+ </XDSText>
+ <XDSButton label="Primary" variant="primary" size="md" />
+ <XDSButton label="Secondary" variant="secondary" size="md" />
+ <XDSButton label="Ghost" variant="ghost" size="md" />
+ <XDSButton label="Destructive" variant="destructive" size="md" />
+ </div>
+ <div style={{display: 'flex', gap: '8px', alignItems: 'center'}}>
+ <XDSText type="supporting" style={{width: '40px', flexShrink: 0}}>
+ lg
+ </XDSText>
+ <XDSButton label="Primary" variant="primary" size="lg" />
+ <XDSButton label="Secondary" variant="secondary" size="lg" />
+ <XDSButton label="Ghost" variant="ghost" size="lg" />
+ <XDSButton label="Destructive" variant="destructive" size="lg" />
+ </div>
+ </div>
+ </div>
+
+ {/* Button States */}
+ <div>
+ <XDSText type="label" style={{marginBottom: '12px', display: 'block'}}>
+ Button States
+ </XDSText>
+ <div style={{display: 'flex', gap: '8px', flexWrap: 'wrap'}}>
+ <XDSButton label="Default" variant="primary" />
+ <XDSButton label="Disabled" variant="primary" isDisabled />
+ <XDSButton label="Loading" variant="primary" isLoading />
+ </div>
+ </div>
+
+ {/* Spacing Table */}
+ <div>
+ <XDSText type="label" style={{marginBottom: '12px', display: 'block'}}>
+ Spacing Scale
+ </XDSText>
+ <XDSTable
+ columns={spacingTableColumns}
+ data={spacingData}
+ getRowKey={row => row.token}
+ density="compact"
+ dividers="rows"
+ />
+ </div>
+
+ {/* Badges */}
+ <div>
+ <XDSText type="label" style={{marginBottom: '12px', display: 'block'}}>
+ Badges
+ </XDSText>
+ <div style={{display: 'flex', gap: '8px', flexWrap: 'wrap'}}>
+ <XDSBadge label="Default" />
+ <XDSBadge label="Primary" variant="primary" />
+ <XDSBadge label="Ghost" variant="ghost" />
+ <XDSBadge label="Positive" sentiment="positive" />
+ <XDSBadge label="Negative" sentiment="negative" />
+ <XDSBadge label="Warning" sentiment="warning" />
+ </div>
+ </div>
+
+ {/* Tokens */}
+ <div>
+ <XDSText type="label" style={{marginBottom: '12px', display: 'block'}}>
+ Tokens
+ </XDSText>
+ <div style={{display: 'flex', gap: '8px', flexWrap: 'wrap'}}>
+ <XDSToken label="Default" />
+ <XDSToken label="Blue" color="blue" />
+ <XDSToken label="Green" color="green" />
+ <XDSToken label="Red" color="red" />
+ <XDSToken label="Purple" color="purple" />
+ <XDSToken label="Orange" color="orange" />
+ </div>
+ </div>
+
+ {/* Form Controls */}
+ <div>
+ <XDSText type="label" style={{marginBottom: '12px', display: 'block'}}>
+ Form Controls
+ </XDSText>
+ <div
+ style={{
+ display: 'flex',
+ flexDirection: 'column',
+ gap: '12px',
+ maxWidth: '300px',
+ }}>
+ <XDSTextInput label="Text Input" placeholder="Enter text..." />
+ <XDSSwitch
+ label="Toggle Switch"
+ isSelected={switchValue}
+ onChange={setSwitchValue}
+ />
+ <XDSCheckboxInput
+ label="Checkbox"
+ isSelected={checkboxValue}
+ onChange={setCheckboxValue}
+ />
+ <XDSSlider
+ label="Slider"
+ value={sliderValue}
+ onChange={setSliderValue}
+ minValue={0}
+ maxValue={100}
+ />
+ </div>
+ </div>
+
+ {/* Radio List */}
+ <div>
+ <XDSText type="label" style={{marginBottom: '12px', display: 'block'}}>
+ Radio List
+ </XDSText>
+ <XDSRadioList
+ label="Select an option"
+ value={radioValue}
+ onChange={setRadioValue}>
+ <XDSRadioListItem value="option1" label="Option 1" />
+ <XDSRadioListItem value="option2" label="Option 2" />
+ <XDSRadioListItem value="option3" label="Option 3" />
+ </XDSRadioList>
+ </div>
+
+ {/* Progress */}
+ <div>
+ <XDSText type="label" style={{marginBottom: '12px', display: 'block'}}>
+ Progress
+ </XDSText>
+ <div
+ style={{
+ display: 'flex',
+ flexDirection: 'column',
+ gap: '8px',
+ maxWidth: '300px',
+ }}>
+ <XDSProgressBar value={25} label="25%" />
+ <XDSProgressBar value={50} label="50%" />
+ <XDSProgressBar value={75} label="75%" />
+ </div>
+ </div>
+
+ {/* Tabs */}
+ <div>
+ <XDSText type="label" style={{marginBottom: '12px', display: 'block'}}>
+ Tabs
+ </XDSText>
+ <XDSTabList
+ tabs={[
+ {id: 'overview', label: 'Overview'},
+ {id: 'details', label: 'Details'},
+ {id: 'settings', label: 'Settings'},
+ ]}
+ selectedId={selectedTab}
+ onSelect={setSelectedTab}
+ />
+ </div>
+
+ {/* Avatar */}
+ <div>
+ <XDSText type="label" style={{marginBottom: '12px', display: 'block'}}>
+ Avatars
+ </XDSText>
+ <div style={{display: 'flex', gap: '8px', alignItems: 'center'}}>
+ <XDSAvatar name="John Doe" size="sm" />
+ <XDSAvatar name="Jane Smith" size="md" />
+ <XDSAvatar name="Bob Wilson" size="lg" />
+ </div>
+ </div>
+
+ {/* Banner */}
+ <div>
+ <XDSText type="label" style={{marginBottom: '12px', display: 'block'}}>
+ Banners
+ </XDSText>
+ <div style={{display: 'flex', flexDirection: 'column', gap: '8px'}}>
+ <XDSBanner
+ title="Information"
+ description="This is an informational banner."
+ status="info"
+ />
+ <XDSBanner
+ title="Success"
+ description="Operation completed successfully."
+ status="success"
+ />
+ <XDSBanner
+ title="Warning"
+ description="Please review before continuing."
+ status="warning"
+ />
+ <XDSBanner
+ title="Error"
+ description="Something went wrong."
+ status="error"
+ />
+ </div>
+ </div>
+
+ {/* Card */}
+ <div>
+ <XDSText type="label" style={{marginBottom: '12px', display: 'block'}}>
+ Card
+ </XDSText>
+ <XDSCard padding="md">
+ <XDSStack gap="sm">
+ <XDSHeading level={4}>Card Title</XDSHeading>
+ <XDSText type="body">
+ This is a sample card with some content to demonstrate how cards
+ look with the current theme.
+ </XDSText>
+ <div style={{display: 'flex', gap: '8px'}}>
+ <XDSButton label="Action" variant="primary" size="sm" />
+ <XDSButton label="Cancel" variant="ghost" size="sm" />
+ </div>
+ </XDSStack>
+ </XDSCard>
+ </div>
+
+ {/* Dialog trigger */}
+ <div>
+ <XDSText type="label" style={{marginBottom: '12px', display: 'block'}}>
+ Dialog
+ </XDSText>
+ <XDSButton
+ label="Open Dialog"
+ variant="secondary"
+ onClick={() => setDialogOpen(true)}
+ />
+ <XDSDialog
+ isOpen={dialogOpen}
+ onClose={() => setDialogOpen(false)}
+ title="Sample Dialog">
+ <div style={{padding: '0 24px 24px 24px'}}>
+ <XDSStack gap="md">
+ <XDSText type="body">
+ This is a sample dialog to preview how dialogs look with the
+ current theme settings.
+ </XDSText>
+ <XDSTextInput
+ label="Example Input"
+ placeholder="Type something..."
+ />
+ <div
+ style={{
+ display: 'flex',
+ gap: '8px',
+ justifyContent: 'flex-end',
+ }}>
+ <XDSButton
+ label="Cancel"
+ variant="ghost"
+ onClick={() => setDialogOpen(false)}
+ />
+ <XDSButton
+ label="Confirm"
+ variant="primary"
+ onClick={() => setDialogOpen(false)}
+ />
+ </div>
+ </XDSStack>
+ </div>
+ </XDSDialog>
+ </div>
+ </div>
+ );
+}
+
+// =============================================================================
+// Code Generator
+// =============================================================================
+
+function generateThemeCode(
+ themeName: string,
+ tokens: Record<string, string>,
+ defaults: Record<string, string>,
+): string {
+ const changedTokens: Record<string, string> = {};
+
+ for (const [key, value] of Object.entries(tokens)) {
+ if (value !== defaults[key]) {
+ changedTokens[key] = value;
+ }
+ }
+
+ if (Object.keys(changedTokens).length === 0) {
+ return `import { defineTheme } from '@xds/core/theme';
+
+export const ${themeName}Theme = defineTheme({
+ name: '${themeName}',
+ tokens: {},
+});`;
+ }
+
+ const tokenEntries = Object.entries(changedTokens)
+ .map(([key, value]) => {
+ const parsed = parseLightDark(value);
+ if (parsed) {
+ return ` '${key}': ['${parsed.light}', '${parsed.dark}'],`;
+ }
+ return ` '${key}': '${value}',`;
+ })
+ .join('\n');
+
+ return `import { defineTheme } from '@xds/core/theme';
+
+export const ${themeName}Theme = defineTheme({
+ name: '${themeName}',
+ tokens: {
+${tokenEntries}
+ },
+});`;
+}
+
+// =============================================================================
+// Main Theme Editor Component
+// =============================================================================
+
+// =============================================================================
+// Toolbar Styles
+// =============================================================================
+
+const toolbarStyles = stylex.create({
+ toolbar: {
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'space-between',
+ paddingInline: spacingVars['--spacing-4'],
+ paddingBlock: spacingVars['--spacing-2'],
+ backgroundColor: colorVars['--color-surface'],
+ borderBottomWidth: '1px',
+ borderBottomStyle: 'solid',
+ borderBottomColor: colorVars['--color-border'],
+ },
+ toolbarGroup: {
+ display: 'flex',
+ alignItems: 'center',
+ gap: spacingVars['--spacing-2'],
+ },
+ toolbarDivider: {
+ width: '1px',
+ height: '20px',
+ backgroundColor: colorVars['--color-border'],
+ },
+});
+
+// =============================================================================
+// Theme Editor Component
+// =============================================================================
+
+function ThemeEditorComponent() {
+ const [activeGroup, setActiveGroup] = React.useState<TokenGroupKey>('colors');
+ const [activeColorCategory, setActiveColorCategory] =
+ React.useState<string>('Core Semantic');
+ const [activeTypographyCategory, setActiveTypographyCategory] =
+ React.useState<string>('Heading 1');
+ const [mode, setMode] = React.useState<'light' | 'dark'>('light');
+ const [themeName, setThemeName] = React.useState('custom');
+ const [showCode, setShowCode] = React.useState(false);
+
+ // Collect all defaults
+ const allDefaults = React.useMemo(
+ () => ({
+ ...colorDefaults,
+ ...spacingDefaults,
+ ...radiusDefaults,
+ ...typographyDefaults,
+ ...textSizeDefaults,
+ ...fontWeightDefaults,
+ ...typeScaleDefaults,
+ ...sizeDefaults,
+ ...shadowDefaults,
+ ...transitionDefaults,
+ }),
+ [],
+ );
+
+ const [tokens, setTokens] =
+ React.useState<Record<string, string>>(allDefaults);
+
+ const handleTokenChange = React.useCallback(
+ (tokenName: string, value: string) => {
+ setTokens(prev => ({...prev, [tokenName]: value}));
+ },
+ [],
+ );
+
+ const handleReset = React.useCallback(() => {
+ setTokens(allDefaults);
+ }, [allDefaults]);
+
+ // Create a theme from current tokens
+ const currentTheme = React.useMemo(() => {
+ const tokenOverrides: Record<string, string> = {};
+ for (const [key, value] of Object.entries(tokens)) {
+ if (value !== allDefaults[key]) {
+ tokenOverrides[key] = value;
+ }
+ }
+ return defineTheme({
+ name: themeName,
+ tokens: tokenOverrides as Partial<Record<string, string>>,
+ icons: defaultIconRegistry,
+ });
+ }, [tokens, themeName, allDefaults]);
+
+ const renderTokenEditor = () => {
+ const group = TOKEN_GROUPS[activeGroup];
+
+ if (activeGroup === 'colors') {
+ const categoryTokens =
+ COLOR_CATEGORIES[
+ activeColorCategory as keyof typeof COLOR_CATEGORIES
+ ] || [];
+
+ return (
+ <div style={{display: 'flex', flexDirection: 'column', gap: '8px'}}>
+ {/* Color category selector */}
+ <div style={{marginBottom: '8px'}}>
+ <select
+ value={activeColorCategory}
+ onChange={e => setActiveColorCategory(e.target.value)}
+ style={{
+ width: '100%',
+ padding: '8px 12px',
+ fontSize: '14px',
+ border: '1px solid var(--color-divider-emphasized)',
+ borderRadius: '8px',
+ backgroundColor: 'var(--color-surface)',
+ color: 'var(--color-text-primary)',
+ }}>
+ {Object.keys(COLOR_CATEGORIES).map(category => (
+ <option key={category} value={category}>
+ {category}
+ </option>
+ ))}
+ </select>
+ </div>
+
+ {categoryTokens.map(tokenName => (
+ <ColorSwatch
+ key={tokenName}
+ tokenName={tokenName}
+ value={tokens[tokenName] || ''}
+ onChange={handleTokenChange}
+ mode={mode}
+ />
+ ))}
+ </div>
+ );
+ }
+
+ if (activeGroup === 'spacing' || activeGroup === 'size') {
+ return (
+ <div style={{display: 'flex', flexDirection: 'column', gap: '8px'}}>
+ {Object.keys(group.tokens).map(tokenName => (
+ <SpacingEditor
+ key={tokenName}
+ tokenName={tokenName}
+ value={tokens[tokenName] || ''}
+ onChange={handleTokenChange}
+ />
+ ))}
+ </div>
+ );
+ }
+
+ if (activeGroup === 'radius') {
+ return (
+ <div style={{display: 'flex', flexDirection: 'column', gap: '8px'}}>
+ {Object.keys(group.tokens).map(tokenName => (
+ <RadiusEditor
+ key={tokenName}
+ tokenName={tokenName}
+ value={tokens[tokenName] || ''}
+ onChange={handleTokenChange}
+ />
+ ))}
+ </div>
+ );
+ }
+
+ if (activeGroup === 'typography') {
+ const categoryValue = TYPOGRAPHY_CATEGORIES[
+ activeTypographyCategory as keyof typeof TYPOGRAPHY_CATEGORIES
+ ] as TypographyCategoryValue | undefined;
+
+ // Get the list of tokens for this category
+ const categoryTokens: string[] = categoryValue
+ ? Array.isArray(categoryValue)
+ ? categoryValue
+ : categoryValue.tokens
+ : [];
+
+ const categoryDescription =
+ categoryValue && !Array.isArray(categoryValue)
+ ? categoryValue.description
+ : null;
+
+ // Determine sample text rendering for semantic categories
+ const isSemanticStyle = categoryValue && !Array.isArray(categoryValue);
+
+ return (
+ <div style={{display: 'flex', flexDirection: 'column', gap: '8px'}}>
+ {/* Typography category selector */}
+ <div style={{marginBottom: '8px'}}>
+ <select
+ value={activeTypographyCategory}
+ onChange={e => setActiveTypographyCategory(e.target.value)}
+ style={{
+ width: '100%',
+ padding: '8px 12px',
+ fontSize: '14px',
+ border: '1px solid var(--color-divider-emphasized)',
+ borderRadius: '8px',
+ backgroundColor: 'var(--color-surface)',
+ color: 'var(--color-text-primary)',
+ }}>
+ <optgroup label="Semantic Styles">
+ {Object.keys(TYPOGRAPHY_CATEGORIES)
+ .filter(k => {
+ const v = TYPOGRAPHY_CATEGORIES[
+ k as keyof typeof TYPOGRAPHY_CATEGORIES
+ ] as TypographyCategoryValue;
+ return !Array.isArray(v);
+ })
+ .map(category => (
+ <option key={category} value={category}>
+ {category}
+ </option>
+ ))}
+ </optgroup>
+ <optgroup label="Raw Tokens">
+ {Object.keys(TYPOGRAPHY_CATEGORIES)
+ .filter(k => {
+ const v = TYPOGRAPHY_CATEGORIES[
+ k as keyof typeof TYPOGRAPHY_CATEGORIES
+ ] as TypographyCategoryValue;
+ return Array.isArray(v);
+ })
+ .map(category => (
+ <option key={category} value={category}>
+ {category}
+ </option>
+ ))}
+ </optgroup>
+ </select>
+ </div>
+
+ {/* Description for semantic styles */}
+ {categoryDescription && (
+ <div
+ style={{
+ padding: '8px 12px',
+ borderRadius: '8px',
+ backgroundColor: 'var(--color-accent-deemphasized)',
+ fontSize: '12px',
+ color: 'var(--color-text-secondary)',
+ marginBottom: '4px',
+ }}>
+ {categoryDescription}
+ </div>
+ )}
+
+ {/* Sample text preview for semantic styles */}
+ {isSemanticStyle && (
+ <div
+ style={{
+ padding: '16px',
+ borderRadius: '8px',
+ backgroundColor: 'var(--color-wash)',
+ border: '1px solid var(--color-divider)',
+ marginBottom: '8px',
+ }}>
+ <div
+ style={{
+ fontSize: tokens[categoryTokens[0]] || 'inherit',
+ fontWeight: tokens[categoryTokens[1]] || 'inherit',
+ lineHeight: tokens[categoryTokens[2]] || 'inherit',
+ color: 'var(--color-text-primary)',
+ }}>
+ {activeTypographyCategory === 'Code Text'
+ ? 'const theme = defineTheme({...});'
+ : `The quick brown fox jumps over the lazy dog`}
+ </div>
+ </div>
+ )}
+
+ {/* Token editors */}
+ {categoryTokens.map(tokenName => (
+ <TypographyEditor
+ key={tokenName}
+ tokenName={tokenName}
+ value={tokens[tokenName] || ''}
+ onChange={handleTokenChange}
+ />
+ ))}
+ </div>
+ );
+ }
+
+ // Default: generic text input
+ return (
+ <div style={{display: 'flex', flexDirection: 'column', gap: '8px'}}>
+ {Object.keys(group.tokens).map(tokenName => (
+ <div
+ key={tokenName}
+ style={{
+ display: 'flex',
+ alignItems: 'center',
+ gap: '12px',
+ padding: '8px 12px',
+ borderRadius: '8px',
+ backgroundColor: 'var(--color-wash)',
+ }}>
+ <div style={{flex: 1, minWidth: 0}}>
+ <div
+ style={{
+ fontSize: '13px',
+ fontWeight: 500,
+ color: 'var(--color-text-primary)',
+ marginBottom: '2px',
+ }}>
+ {getTokenLabel(tokenName)}
+ </div>
+ <code
+ style={{
+ fontSize: '11px',
+ color: 'var(--color-text-secondary)',
+ fontFamily: 'var(--font-code)',
+ }}>
+ {tokenName}
+ </code>
+ </div>
+ <input
+ type="text"
+ value={tokens[tokenName] || ''}
+ onChange={e => handleTokenChange(tokenName, e.target.value)}
+ style={{
+ width: '200px',
+ padding: '4px 8px',
+ fontSize: '12px',
+ fontFamily: 'var(--font-code)',
+ border: '1px solid var(--color-divider-emphasized)',
+ borderRadius: '4px',
+ backgroundColor: 'var(--color-surface)',
+ color: 'var(--color-text-primary)',
+ }}
+ />
+ </div>
+ ))}
+ </div>
+ );
+ };
+
+ return (
+ <div style={{display: 'flex', flexDirection: 'column', height: '100vh'}}>
+ {/* ── Top Bar ─────────────────────────────────────── */}
+ <XDSTopNav
+ label="Theme editor navigation"
+ heading={<XDSTopNavHeading heading="XDS Theme Editor" />}
+ endContent={
+ <>
+ <XDSButton
+ label="Search"
+ tooltip="Search"
+ variant="ghost"
+ icon={<MagnifyingGlassIcon style={{width: 16, height: 16}} />}
+ />
+ <XDSButton
+ label="Notifications"
+ tooltip="Notifications"
+ variant="ghost"
+ icon={<BellIcon style={{width: 16, height: 16}} />}
+ />
+ <XDSButton
+ label="Profile"
+ tooltip="Profile"
+ variant="ghost"
+ icon={<UserCircleIcon style={{width: 16, height: 16}} />}
+ />
+ </>
+ }
+ />
+
+ <XDSDivider />
+
+ {/* ── Toolbar ─────────────────────────────────────── */}
+ <div {...stylex.props(toolbarStyles.toolbar)}>
+ <div {...stylex.props(toolbarStyles.toolbarGroup)}>
+ <XDSDropdownMenu
+ button={{
+ label: themeName || 'Default',
+ variant: 'secondary',
+ size: 'sm',
+ }}
+ items={[
+ {
+ label: 'Default',
+ onClick: () => {
+ setThemeName('default');
+ handleReset();
+ },
+ },
+ {label: 'Neutral', onClick: () => setThemeName('neutral')},
+ {label: 'Brutalist', onClick: () => setThemeName('brutalist')},
+ ]}
+ />
+
+ <div {...stylex.props(toolbarStyles.toolbarDivider)} />
+
+ <XDSButton
+ label="Light mode"
+ tooltip="Light mode"
+ variant={mode === 'light' ? 'secondary' : 'ghost'}
+ size="sm"
+ icon={<SunIcon style={{width: 14, height: 14}} />}
+ onClick={() => setMode('light')}
+ />
+ <XDSButton
+ label="Dark mode"
+ tooltip="Dark mode"
+ variant={mode === 'dark' ? 'secondary' : 'ghost'}
+ size="sm"
+ icon={<MoonIcon style={{width: 14, height: 14}} />}
+ onClick={() => setMode('dark')}
+ />
+
+ <div {...stylex.props(toolbarStyles.toolbarDivider)} />
+
+ <XDSButton
+ label="Undo"
+ tooltip="Undo"
+ variant="ghost"
+ size="sm"
+ icon={<ArrowUturnLeftIcon style={{width: 14, height: 14}} />}
+ />
+ <XDSButton
+ label="Redo"
+ tooltip="Redo"
+ variant="ghost"
+ size="sm"
+ icon={<ArrowUturnRightIcon style={{width: 14, height: 14}} />}
+ />
+ <XDSButton
+ label="Reset"
+ variant="ghost"
+ size="sm"
+ onClick={handleReset}>
+ Reset
+ </XDSButton>
+ </div>
+
+ <div {...stylex.props(toolbarStyles.toolbarGroup)}>
+ <XDSButton
+ label="Share"
+ tooltip="Share"
+ variant="ghost"
+ size="sm"
+ icon={<ShareIcon style={{width: 14, height: 14}} />}
+ />
+ <XDSButton
+ label="Save"
+ tooltip="Save"
+ variant="ghost"
+ size="sm"
+ icon={<BookmarkIcon style={{width: 14, height: 14}} />}
+ />
+
+ <div {...stylex.props(toolbarStyles.toolbarDivider)} />
+
+ <XDSButton
+ label="View code"
+ variant="secondary"
+ size="sm"
+ icon={<CodeBracketIcon style={{width: 14, height: 14}} />}
+ onClick={() => setShowCode(!showCode)}>
+ Code
+ </XDSButton>
+
+ <XDSButton
+ label="Export to Figma"
+ variant="secondary"
+ size="sm"
+ icon={<ArrowDownTrayIcon style={{width: 14, height: 14}} />}>
+ Export to Figma
+ </XDSButton>
+ </div>
+ </div>
+
+ {/* ── Main Content ────────────────────────────────── */}
+ <div
+ style={{
+ display: 'flex',
+ flex: 1,
+ overflow: 'hidden',
+ backgroundColor: 'var(--color-wash)',
+ }}>
+ {/* Left Panel - Token Editor */}
+ <div
+ style={{
+ width: '400px',
+ borderRight: '1px solid var(--color-divider-emphasized)',
+ display: 'flex',
+ flexDirection: 'column',
+ backgroundColor: 'var(--color-surface)',
+ }}>
+ {/* Header */}
+ <div
+ style={{
+ padding: '16px',
+ borderBottom: '1px solid var(--color-divider)',
+ }}>
+ <XDSHeading level={3}>Theme Editor</XDSHeading>
+ <XDSText type="supporting" style={{marginTop: '4px'}}>
+ Customize XDS design tokens
+ </XDSText>
+ </div>
+
+ {/* Theme name input */}
+ <div
+ style={{
+ padding: '12px 16px',
+ borderBottom: '1px solid var(--color-divider)',
+ }}>
+ <XDSTextInput
+ label="Theme Name"
+ value={themeName}
+ onChange={setThemeName}
+ size="sm"
+ />
+ </div>
+
+ {/* Mode toggle */}
+ <div
+ style={{
+ padding: '12px 16px',
+ borderBottom: '1px solid var(--color-divider)',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'space-between',
+ }}>
+ <XDSText type="label">Edit Mode</XDSText>
+ <div style={{display: 'flex', gap: '8px'}}>
+ <XDSButton
+ label="Light"
+ variant={mode === 'light' ? 'primary' : 'ghost'}
+ size="sm"
+ onClick={() => setMode('light')}
+ />
+ <XDSButton
+ label="Dark"
+ variant={mode === 'dark' ? 'primary' : 'ghost'}
+ size="sm"
+ onClick={() => setMode('dark')}
+ />
+ </div>
+ </div>
+
+ {/* Token group tabs */}
+ <div
+ style={{
+ padding: '12px 16px',
+ borderBottom: '1px solid var(--color-divider)',
+ display: 'flex',
+ gap: '4px',
+ flexWrap: 'wrap',
+ }}>
+ {(Object.keys(TOKEN_GROUPS) as TokenGroupKey[]).map(groupKey => (
+ <XDSButton
+ key={groupKey}
+ label={TOKEN_GROUPS[groupKey].label}
+ variant={activeGroup === groupKey ? 'primary' : 'ghost'}
+ size="sm"
+ onClick={() => setActiveGroup(groupKey)}
+ />
+ ))}
+ </div>
+
+ {/* Group description */}
+ <div
+ style={{
+ padding: '12px 16px',
+ borderBottom: '1px solid var(--color-divider)',
+ }}>
+ <XDSText type="supporting">
+ {TOKEN_GROUPS[activeGroup].description}
+ </XDSText>
+ </div>
+
+ {/* Token list */}
+ <div
+ style={{
+ flex: 1,
+ overflow: 'auto',
+ padding: '16px',
+ }}>
+ {renderTokenEditor()}
+ </div>
+
+ {/* Actions */}
+ <div
+ style={{
+ padding: '16px',
+ borderTop: '1px solid var(--color-divider)',
+ display: 'flex',
+ gap: '8px',
+ }}>
+ <XDSButton
+ label="Reset All"
+ variant="ghost"
+ onClick={handleReset}
+ />
+ <XDSButton
+ label={showCode ? 'Hide Code' : 'Export Code'}
+ variant="secondary"
+ onClick={() => setShowCode(!showCode)}
+ />
+ </div>
+ </div>
+
+ {/* Right Panel - Preview */}
+ <div
+ style={{
+ flex: 1,
+ display: 'flex',
+ flexDirection: 'column',
+ overflow: 'hidden',
+ }}>
+ {/* Preview header */}
+ <div
+ style={{
+ padding: '16px 24px',
+ borderBottom: '1px solid var(--color-divider)',
+ backgroundColor: 'var(--color-surface)',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'space-between',
+ }}>
+ <div>
+ <XDSHeading level={4}>Live Preview</XDSHeading>
+ <XDSText type="supporting">See your changes in real-time</XDSText>
+ </div>
+ </div>
+
+ {/* Code panel (collapsible) */}
+ {showCode && (
+ <div
+ style={{
+ padding: '16px 24px',
+ borderBottom: '1px solid var(--color-divider)',
+ backgroundColor: 'var(--color-wash)',
+ maxHeight: '300px',
+ overflow: 'auto',
+ }}>
+ <XDSText
+ type="label"
+ style={{marginBottom: '8px', display: 'block'}}>
+ Generated Theme Code
+ </XDSText>
+ <pre
+ style={{
+ padding: '16px',
+ borderRadius: '8px',
+ backgroundColor: 'var(--color-surface)',
+ border: '1px solid var(--color-divider-emphasized)',
+ fontSize: '12px',
+ fontFamily: 'var(--font-code)',
+ overflow: 'auto',
+ margin: 0,
+ color: 'var(--color-text-primary)',
+ }}>
+ {generateThemeCode(themeName, tokens, allDefaults)}
+ </pre>
+ </div>
+ )}
+
+ {/* Preview content */}
+ <div
+ style={{
+ flex: 1,
+ overflow: 'auto',
+ padding: '24px',
+ }}>
+ <XDSTheme theme={currentTheme} mode={mode}>
+ <div
+ style={{
+ backgroundColor: 'var(--color-surface)',
+ borderRadius: '12px',
+ padding: '24px',
+ minHeight: '100%',
+ }}>
+ <ComponentPreview />
+ </div>
+ </XDSTheme>
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+}
+
+// =============================================================================
+// Storybook Meta
+// =============================================================================
+
+const meta: Meta = {
+ title: 'Theme Editor',
+ parameters: {
+ layout: 'fullscreen',
+ docs: {
+ page: null,
+ },
+ },
+};
+
+export default meta;
+
+type Story = StoryObj;
+
+export const ThemeEditor: Story = {
+ render: () => <ThemeEditorComponent />,
+ parameters: {
+ // Disable the theme decorator for this story since we manage our own theme
+ xdsTheme: 'none',
+ },
+};