Skip to content

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

TypeScript

fix(docsite): codegen playground scope on build instead of committing it (#2603)

Cindy Zhang35e9dff12e41
diff --git a/apps/docsite/package.json b/apps/docsite/package.json
index 9c37006ac3..06e9b4c372 100644
--- a/apps/docsite/package.json
+++ b/apps/docsite/package.json
@@ -4,7 +4,7 @@
"private": true,
"scripts": {
"build:theme": "xds theme build src/themes/astryxTheme.ts --out src/themes/astryx.css",
- "generate": "pnpm build:theme && node scripts/generate-data.mjs && node scripts/generate-playground-types.mjs && node scripts/copy-vendor.mjs",
+ "generate": "pnpm build:theme && node scripts/generate-data.mjs && node scripts/generate-scope.mjs && node scripts/generate-playground-types.mjs && node scripts/copy-vendor.mjs",
"dev": "pnpm generate && next dev",
"build": "pnpm generate && next build",
"start": "next start",
diff --git a/apps/docsite/scripts/generate-scope.mjs b/apps/docsite/scripts/generate-scope.mjs
index 6d12f5c9ec..bb67b3e3c9 100644
--- a/apps/docsite/scripts/generate-scope.mjs
+++ b/apps/docsite/scripts/generate-scope.mjs
@@ -1,11 +1,13 @@
#!/usr/bin/env node
// Copyright (c) Meta Platforms, Inc. and affiliates.
-
/**
- * Generates apps/docsite/src/app/playground/preview/scope.ts
+ * Generates apps/docsite/src/generated/playground-scope.ts
*
* Maps every XDS module available in the playground preview iframe.
+ * This runs as part of `pnpm generate` (before dev/build) so new components
+ * are picked up automatically — no manual maintenance needed.
+ *
* Run: node scripts/generate-scope.mjs
*/
@@ -16,9 +18,11 @@ import {fileURLToPath} from 'node:url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const ROOT = resolve(__dirname, '..');
const CORE_PKG = resolve(ROOT, '../../packages/core/package.json');
-const OUT = resolve(ROOT, 'src/app/playground/preview/scope.ts');
+const OUT = resolve(ROOT, 'src/generated/playground-scope.ts');
+
+const HEADER = `// Copyright (c) Meta Platforms, Inc. and affiliates.
-const HEADER = '// @generated by scripts/generate-scope.mjs \u2014 do not edit manually';
+// @generated by scripts/generate-scope.mjs — do not edit manually`;
// Read core package.json exports and extract PascalCase component subpaths
const corePkg = JSON.parse(readFileSync(CORE_PKG, 'utf-8'));
@@ -34,7 +38,7 @@ const components = exportKeys
})
.map((k) => k.replace('./', ''));
-// Themes
+// Themes — add new themes here as they become available
const SCOPE_THEMES = [
{pkg: '@xds/theme-default', name: 'defaultTheme', subpath: '/built'},
{pkg: '@xds/theme-neutral', name: 'neutralTheme', subpath: '/built'},
@@ -42,10 +46,9 @@ const SCOPE_THEMES = [
];
// Heroicons variants — exposed alongside Lucide so playground snippets
-// and shared template code that still import from '@heroicons/react/*'
-// keep rendering. The docsite itself authors new code against Lucide;
-// these entries are purely for playground runtime compatibility with
-// template / example code that hasn't been migrated.
+// and shared template code that still imports from '@heroicons/react/*'
+// keeps rendering. New docsite code authors against Lucide; these entries
+// are purely for playground runtime compatibility.
const HEROICON_VARIANTS = [
{path: '16/solid', alias: 'Heroicons16Solid'},
{path: '20/solid', alias: 'Heroicons20Solid'},
@@ -54,72 +57,109 @@ const HEROICON_VARIANTS = [
];
-// Build output
+// Build output — matches the structure of the previously committed scope.ts
const lines = [HEADER, ''];
-// React
+// ── React ──────────────────────────────────────────────────────────────
lines.push("import React, {useState, useCallback, useMemo, useEffect, useRef} from 'react';");
lines.push('');
-// StyleX mock
-lines.push('const stylexMock = {');
-lines.push(" create: <T extends Record<string, unknown>>(styles: T): T => styles,");
-lines.push(" props: (..._styles: unknown[]) => ({className: '', style: {} as Record<string, string>}),");
-lines.push(" defineVars: <T extends Record<string, unknown>>(tokens: T): T => tokens,");
-lines.push(" keyframes: (kf: Record<string, Record<string, string>>) => kf,");
-lines.push(" types: {angle: (v: string) => v, color: (v: string) => v, image: (v: string) => v, integer: (v: string) => v, length: (v: string) => v, lengthPercentage: (v: string) => v, number: (v: string) => v, percentage: (v: string) => v, resolution: (v: string) => v, time: (v: string) => v, transformFunction: (v: string) => v, transformList: (v: string) => v, url: (v: string) => v},");
-lines.push('};');
+// ── StyleX mock ────────────────────────────────────────────────────────
+lines.push(`const stylexMock = {
+ create: <T extends Record<string, unknown>>(styles: T): T => styles,
+ props: (..._styles: unknown[]) => {
+ const style: Record<string, string> = {};
+ return {className: '', style};
+ },
+ defineVars: <T extends Record<string, unknown>>(tokens: T): T => tokens,
+ keyframes: (kf: Record<string, Record<string, string>>) => kf,
+ types: {
+ angle: (v: string) => v,
+ color: (v: string) => v,
+ image: (v: string) => v,
+ integer: (v: string) => v,
+ length: (v: string) => v,
+ lengthPercentage: (v: string) => v,
+ number: (v: string) => v,
+ percentage: (v: string) => v,
+ resolution: (v: string) => v,
+ time: (v: string) => v,
+ transformFunction: (v: string) => v,
+ transformList: (v: string) => v,
+ url: (v: string) => v,
+ },
+};`);
lines.push('');
-// Component imports
+// ── Component imports ──────────────────────────────────────────────────
for (const name of components) {
lines.push(`import * as ${name} from '@xds/core/${name}';`);
}
lines.push('');
-// Theme imports
+// ── Theme imports ──────────────────────────────────────────────────────
for (const t of SCOPE_THEMES) {
lines.push(`import {${t.name}} from '${t.pkg}${t.subpath}';`);
}
lines.push('');
-// XDSTheme + tokens
+// ── XDSTheme + tokens ──────────────────────────────────────────────────
lines.push("import {XDSTheme} from '@xds/core/theme';");
+lines.push("import type {XDSDefinedTheme} from '@xds/core/theme';");
+lines.push("import {createElement, type ComponentProps} from 'react';");
lines.push("import * as xdsTokens from '@xds/core/theme/tokens.stylex';");
lines.push('');
-// Lucide icons (the docsite's primary icon library going forward)
-// plus Heroicons (kept for backward compatibility with template /
-// example code that still imports from '@heroicons/react/*').
+// ── Icon libraries ─────────────────────────────────────────────────────
lines.push("import * as LucideIcons from 'lucide-react';");
+lines.push('// Heroicons kept available in the playground scope alongside Lucide');
+lines.push("// so template / example code that still imports from");
+lines.push("// '@heroicons/react/*' continues to render. New docsite code authors");
+lines.push('// against Lucide; these entries are purely for backwards compat.');
for (const h of HEROICON_VARIANTS) {
lines.push(`import * as ${h.alias} from '@heroicons/react/${h.path}';`);
}
lines.push('');
-// ControlledXDSTheme wrapper
-lines.push(`const ControlledXDSTheme = (props: Record<string, unknown>) => {`);
-lines.push(` const mode = (typeof window !== 'undefined' && (window as any).__xds_preview_mode__) || 'system';`);
-lines.push(` const themeName = (typeof window !== 'undefined' && (window as any).__xds_preview_theme__) || 'default';`);
-lines.push(` const THEMES: Record<string, unknown> = {`);
-for (const t of SCOPE_THEMES) {
- lines.push(` '${t.name.replace('Theme', '').toLowerCase()}': ${t.name},`);
-}
-lines.push(` };`);
-lines.push(` const theme = (THEMES[themeName] ?? ${SCOPE_THEMES[0].name}) as any;`);
-lines.push(` return React.createElement(XDSTheme, {...props, theme, mode});`);
-lines.push(`};`);
+// ── ControlledXDSTheme wrapper ─────────────────────────────────────────
+const themeEntries = SCOPE_THEMES.map(
+ (t) => ` ${t.name.replace('Theme', '').toLowerCase()}: ${t.name},`,
+).join('\n');
+
+lines.push(`const SCOPE_THEMES: Record<string, XDSDefinedTheme> = {
+${themeEntries}
+};
+
+const ControlledXDSTheme = (props: ComponentProps<typeof XDSTheme>) => {
+ const win =
+ typeof window !== 'undefined'
+ ? (window as unknown as Record<string, unknown>)
+ : null;
+ const mode =
+ (win?.__xds_preview_mode__ as 'light' | 'dark' | 'system') || 'system';
+ const themeName = (win?.__xds_preview_theme__ as string) || 'default';
+ const theme = SCOPE_THEMES[themeName] ?? ${SCOPE_THEMES[0].name};
+ return createElement(XDSTheme, {...props, theme, mode});
+};`);
lines.push('');
-// Scope map
+// ── Scope map ──────────────────────────────────────────────────────────
lines.push('export const scope: Record<string, Record<string, unknown>> = {');
// react
-lines.push(" 'react': {default: React, ...React, useState, useCallback, useMemo, useEffect, useRef},");
+lines.push(` react: {
+ default: React,
+ ...React,
+ useState,
+ useCallback,
+ useMemo,
+ useEffect,
+ useRef,
+ },`);
// stylex
lines.push(" '@stylexjs/stylex': {default: stylexMock, ...stylexMock},");
-lines.push(" 'stylex': {default: stylexMock, ...stylexMock},");
+lines.push(" stylex: {default: stylexMock, ...stylexMock},");
// themes
for (const t of SCOPE_THEMES) {
@@ -139,16 +179,22 @@ for (const name of components) {
}
// Barrel export — all components spread
-lines.push(` '@xds/core': {${components.map((n) => `...${n}`).join(', ')}},`);
+const spreads = components.map((n) => ` ...${n},`).join('\n');
+lines.push(` '@xds/core': {
+${spreads}
+ },`);
-// Lucide icons + Heroicons (both available to playground code)
+// Lucide icons + Heroicons
lines.push(" 'lucide-react': LucideIcons,");
for (const h of HEROICON_VARIANTS) {
lines.push(` '@heroicons/react/${h.path}': ${h.alias},`);
}
// next/image stub
-lines.push(" 'next/image': {default: (props: Record<string, unknown>) => React.createElement('img', props)},");
+lines.push(` 'next/image': {
+ default: (props: Record<string, unknown>) =>
+ React.createElement('img', props),
+ },`);
lines.push('};');
lines.push('');
diff --git a/apps/docsite/src/__tests__/playground-scope.test.ts b/apps/docsite/src/__tests__/playground-scope.test.ts
new file mode 100644
index 0000000000..22e3cc736e
--- /dev/null
+++ b/apps/docsite/src/__tests__/playground-scope.test.ts
@@ -0,0 +1,161 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file Playground scope coverage test.
+ *
+ * Validates that the generated playground scope includes every public
+ * component exported from @xds/core/package.json, plus the expected
+ * non-component scope entries (themes, icons, stylex, react, next/image).
+ *
+ * This test reads the generated file as text (rather than importing it)
+ * because the scope imports @xds/core/* which requires a prior build step.
+ * Instead we verify the generator produced the correct import/scope lines.
+ *
+ * Run: pnpm -F @xds/docsite test
+ */
+
+import * as fs from 'node:fs';
+import * as path from 'node:path';
+import {describe, it, expect, beforeAll} from 'vitest';
+
+const GENERATED_SCOPE_PATH = path.resolve(
+ __dirname,
+ '../generated/playground-scope.ts',
+);
+
+const CORE_PKG_PATH = path.resolve(
+ __dirname,
+ '../../../../packages/core/package.json',
+);
+
+/**
+ * Same skip pattern as generate-scope.mjs — non-component exports like
+ * CSS files, utils, hooks, theme, etc.
+ */
+const SKIP =
+ /\.(css|stylex)$|\/utils$|^\.\/(theme|hooks|utils|syntax|docs|groups|reset)|\.$/;
+
+function getExpectedComponents(): string[] {
+ const pkg = JSON.parse(fs.readFileSync(CORE_PKG_PATH, 'utf-8'));
+ return Object.keys(pkg.exports ?? {})
+ .filter(k => {
+ if (SKIP.test(k)) {return false;}
+ const name = k.replace('./', '');
+ return /^[A-Z]/.test(name);
+ })
+ .map(k => k.replace('./', ''));
+}
+
+describe('playground-scope', () => {
+ let expectedComponents: string[];
+ let scopeContent: string;
+
+ beforeAll(() => {
+ expectedComponents = getExpectedComponents();
+ if (!fs.existsSync(GENERATED_SCOPE_PATH)) {
+ throw new Error(
+ `Generated scope file not found at ${GENERATED_SCOPE_PATH}. ` +
+ 'Run `pnpm generate` (or `node scripts/generate-scope.mjs`) first.',
+ );
+ }
+ scopeContent = fs.readFileSync(GENERATED_SCOPE_PATH, 'utf-8');
+ });
+
+ it('generated file exists and has the codegen header', () => {
+ expect(scopeContent).toContain('@generated by scripts/generate-scope.mjs');
+ });
+
+ // ── Component coverage ─────────────────────────────────────────────────
+
+ it('imports every PascalCase component from @xds/core', () => {
+ const missing = expectedComponents.filter(
+ name =>
+ !scopeContent.includes(`import * as ${name} from '@xds/core/${name}';`),
+ );
+ expect(missing).toEqual([]);
+ });
+
+ it('has a scope entry for every component', () => {
+ const missing = expectedComponents.filter(
+ name => !scopeContent.includes(`'@xds/core/${name}': ${name},`),
+ );
+ expect(missing).toEqual([]);
+ });
+
+ it('has a barrel @xds/core entry that spreads all components', () => {
+ expect(scopeContent).toContain("'@xds/core': {");
+ const missing = expectedComponents.filter(
+ name => !scopeContent.includes(`...${name},`),
+ );
+ expect(missing).toEqual([]);
+ });
+
+ it('component count matches core exports', () => {
+ const importLines = scopeContent
+ .split('\n')
+ .filter(l => l.match(/^import \* as \w+ from '@xds\/core\/[A-Z]/));
+ expect(importLines.length).toBe(expectedComponents.length);
+ });
+
+ // ── Non-component scope entries ────────────────────────────────────────
+
+ it('includes react scope with hooks', () => {
+ expect(scopeContent).toContain('react: {');
+ expect(scopeContent).toContain('useState');
+ expect(scopeContent).toContain('useCallback');
+ expect(scopeContent).toContain('useMemo');
+ expect(scopeContent).toContain('useEffect');
+ expect(scopeContent).toContain('useRef');
+ });
+
+ it('includes stylex mock under both specifiers', () => {
+ expect(scopeContent).toContain("'@stylexjs/stylex':");
+ expect(scopeContent).toContain('stylex:');
+ expect(scopeContent).toContain('stylexMock');
+ });
+
+ it('includes all theme entries (bare and /built subpath)', () => {
+ expect(scopeContent).toContain("'@xds/theme-default':");
+ expect(scopeContent).toContain("'@xds/theme-default/built':");
+ expect(scopeContent).toContain("'@xds/theme-neutral':");
+ expect(scopeContent).toContain("'@xds/theme-neutral/built':");
+ expect(scopeContent).toContain("'@xds/theme-matcha':");
+ expect(scopeContent).toContain("'@xds/theme-matcha/built':");
+ });
+
+ it('includes XDSTheme controlled wrapper and tokens', () => {
+ expect(scopeContent).toContain("'@xds/core/theme': {XDSTheme:");
+ expect(scopeContent).toContain(
+ "'@xds/core/theme/tokens.stylex': xdsTokens,",
+ );
+ expect(scopeContent).toContain('ControlledXDSTheme');
+ expect(scopeContent).toContain('SCOPE_THEMES');
+ });
+
+ it('includes lucide-react icons', () => {
+ expect(scopeContent).toContain("'lucide-react': LucideIcons,");
+ expect(scopeContent).toContain(
+ "import * as LucideIcons from 'lucide-react';",
+ );
+ });
+
+ it('includes all heroicon variants', () => {
+ expect(scopeContent).toContain(
+ "'@heroicons/react/16/solid': Heroicons16Solid,",
+ );
+ expect(scopeContent).toContain(
+ "'@heroicons/react/20/solid': Heroicons20Solid,",
+ );
+ expect(scopeContent).toContain(
+ "'@heroicons/react/24/outline': Heroicons24Outline,",
+ );
+ expect(scopeContent).toContain(
+ "'@heroicons/react/24/solid': Heroicons24Solid,",
+ );
+ });
+
+ it('includes next/image stub', () => {
+ expect(scopeContent).toContain("'next/image':");
+ expect(scopeContent).toContain("React.createElement('img', props)");
+ });
+});
diff --git a/apps/docsite/src/app/(preview)/playground-preview/runner.ts b/apps/docsite/src/app/(preview)/playground-preview/runner.ts
index 0bfb88e12f..2a15315a91 100644
--- a/apps/docsite/src/app/(preview)/playground-preview/runner.ts
+++ b/apps/docsite/src/app/(preview)/playground-preview/runner.ts
@@ -13,7 +13,7 @@
*/
import type * as TS from 'typescript';
-import {scope} from './scope';
+import {scope} from '@/generated/playground-scope';
/** Set by the page after loading /vendor/typescript.js */
let ts: typeof TS | null = null;
diff --git a/apps/docsite/src/app/(preview)/playground-preview/scope.ts b/apps/docsite/src/app/(preview)/playground-preview/scope.ts
deleted file mode 100644
index fd069da1fa..0000000000
--- a/apps/docsite/src/app/(preview)/playground-preview/scope.ts
+++ /dev/null
@@ -1,344 +0,0 @@
-// Copyright (c) Meta Platforms, Inc. and affiliates.
-
-// @generated by scripts/generate-scope.mjs — do not edit manually
-
-import React, {useState, useCallback, useMemo, useEffect, useRef} from 'react';
-
-const stylexMock = {
- create: <T extends Record<string, unknown>>(styles: T): T => styles,
- props: (..._styles: unknown[]) => {
- const style: Record<string, string> = {};
- return {className: '', style};
- },
- defineVars: <T extends Record<string, unknown>>(tokens: T): T => tokens,
- keyframes: (kf: Record<string, Record<string, string>>) => kf,
- types: {
- angle: (v: string) => v,
- color: (v: string) => v,
- image: (v: string) => v,
- integer: (v: string) => v,
- length: (v: string) => v,
- lengthPercentage: (v: string) => v,
- number: (v: string) => v,
- percentage: (v: string) => v,
- resolution: (v: string) => v,
- time: (v: string) => v,
- transformFunction: (v: string) => v,
- transformList: (v: string) => v,
- url: (v: string) => v,
- },
-};
-
-import * as AlertDialog from '@xds/core/AlertDialog';
-import * as AppShell from '@xds/core/AppShell';
-import * as AspectRatio from '@xds/core/AspectRatio';
-import * as Avatar from '@xds/core/Avatar';
-import * as Badge from '@xds/core/Badge';
-import * as Banner from '@xds/core/Banner';
-import * as Breadcrumbs from '@xds/core/Breadcrumbs';
-import * as Button from '@xds/core/Button';
-import * as Calendar from '@xds/core/Calendar';
-import * as Card from '@xds/core/Card';
-import * as Carousel from '@xds/core/Carousel';
-import * as Center from '@xds/core/Center';
-import * as Chat from '@xds/core/Chat';
-import * as CheckboxInput from '@xds/core/CheckboxInput';
-import * as CheckboxList from '@xds/core/CheckboxList';
-import * as ClickableCard from '@xds/core/ClickableCard';
-import * as CodeBlock from '@xds/core/CodeBlock';
-import * as Collapsible from '@xds/core/Collapsible';
-import * as CommandPalette from '@xds/core/CommandPalette';
-import * as DateInput from '@xds/core/DateInput';
-import * as Dialog from '@xds/core/Dialog';
-import * as Divider from '@xds/core/Divider';
-import * as DropdownMenu from '@xds/core/DropdownMenu';
-import * as EmptyState from '@xds/core/EmptyState';
-import * as Field from '@xds/core/Field';
-import * as FormLayout from '@xds/core/FormLayout';
-import * as Grid from '@xds/core/Grid';
-import * as HoverCard from '@xds/core/HoverCard';
-import * as Icon from '@xds/core/Icon';
-import * as IconButton from '@xds/core/IconButton';
-import * as Item from '@xds/core/Item';
-import * as Kbd from '@xds/core/Kbd';
-import * as Layer from '@xds/core/Layer';
-import * as Layout from '@xds/core/Layout';
-import * as Link from '@xds/core/Link';
-import * as List from '@xds/core/List';
-import * as Markdown from '@xds/core/Markdown';
-import * as MetadataList from '@xds/core/MetadataList';
-import * as MobileNav from '@xds/core/MobileNav';
-import * as MoreMenu from '@xds/core/MoreMenu';
-import * as MultiSelector from '@xds/core/MultiSelector';
-import * as NavIcon from '@xds/core/NavIcon';
-import * as NavMenu from '@xds/core/NavMenu';
-import * as NumberInput from '@xds/core/NumberInput';
-import * as OverflowList from '@xds/core/OverflowList';
-import * as Overlay from '@xds/core/Overlay';
-import * as Pagination from '@xds/core/Pagination';
-import * as Popover from '@xds/core/Popover';
-import * as PowerSearch from '@xds/core/PowerSearch';
-import * as ProgressBar from '@xds/core/ProgressBar';
-import * as RadioList from '@xds/core/RadioList';
-import * as Resizable from '@xds/core/Resizable';
-import * as Section from '@xds/core/Section';
-import * as SegmentedControl from '@xds/core/SegmentedControl';
-import * as SelectableCard from '@xds/core/SelectableCard';
-import * as Selector from '@xds/core/Selector';
-import * as SideNav from '@xds/core/SideNav';
-import * as SizeContext from '@xds/core/SizeContext';
-import * as Skeleton from '@xds/core/Skeleton';
-import * as Slider from '@xds/core/Slider';
-import * as Spinner from '@xds/core/Spinner';
-import * as Stack from '@xds/core/Stack';
-import * as StatusDot from '@xds/core/StatusDot';
-import * as Switch from '@xds/core/Switch';
-import * as TabList from '@xds/core/TabList';
-import * as Table from '@xds/core/Table';
-import * as Text from '@xds/core/Text';
-import * as TextArea from '@xds/core/TextArea';
-import * as TextInput from '@xds/core/TextInput';
-import * as Thumbnail from '@xds/core/Thumbnail';
-import * as TimeInput from '@xds/core/TimeInput';
-import * as Timestamp from '@xds/core/Timestamp';
-import * as Toast from '@xds/core/Toast';
-import * as ToggleButton from '@xds/core/ToggleButton';
-import * as Token from '@xds/core/Token';
-import * as Tokenizer from '@xds/core/Tokenizer';
-import * as Toolbar from '@xds/core/Toolbar';
-import * as Tooltip from '@xds/core/Tooltip';
-import * as TopNav from '@xds/core/TopNav';
-import * as TreeList from '@xds/core/TreeList';
-import * as Typeahead from '@xds/core/Typeahead';
-
-import {defaultTheme} from '@xds/theme-default/built';
-import {neutralTheme} from '@xds/theme-neutral/built';
-import {matchaTheme} from '@xds/theme-matcha/built';
-
-import {XDSTheme} from '@xds/core/theme';
-import type {XDSDefinedTheme} from '@xds/core/theme';
-import {createElement, type ComponentProps} from 'react';
-import * as xdsTokens from '@xds/core/theme/tokens.stylex';
-
-import * as LucideIcons from 'lucide-react';
-// Heroicons kept available in the playground scope alongside Lucide
-// so template / example code that still imports from
-// '@heroicons/react/*' continues to render. New docsite code authors
-// against Lucide; these entries are purely for backwards compat.
-import * as Heroicons16Solid from '@heroicons/react/16/solid';
-import * as Heroicons20Solid from '@heroicons/react/20/solid';
-import * as Heroicons24Outline from '@heroicons/react/24/outline';
-import * as Heroicons24Solid from '@heroicons/react/24/solid';
-
-const SCOPE_THEMES: Record<string, XDSDefinedTheme> = {
- default: defaultTheme,
- neutral: neutralTheme,
- matcha: matchaTheme,
-};
-
-const ControlledXDSTheme = (props: ComponentProps<typeof XDSTheme>) => {
- const win =
- typeof window !== 'undefined'
- ? (window as unknown as Record<string, unknown>)
- : null;
- const mode =
- (win?.__xds_preview_mode__ as 'light' | 'dark' | 'system') || 'system';
- const themeName = (win?.__xds_preview_theme__ as string) || 'default';
- const theme = SCOPE_THEMES[themeName] ?? defaultTheme;
- return createElement(XDSTheme, {...props, theme, mode});
-};
-
-export const scope: Record<string, Record<string, unknown>> = {
- react: {
- default: React,
- ...React,
- useState,
- useCallback,
- useMemo,
- useEffect,
- useRef,
- },
- '@stylexjs/stylex': {default: stylexMock, ...stylexMock},
- stylex: {default: stylexMock, ...stylexMock},
- '@xds/theme-default': {default: defaultTheme, defaultTheme},
- '@xds/theme-default/built': {default: defaultTheme, defaultTheme},
- '@xds/theme-neutral': {default: neutralTheme, neutralTheme},
- '@xds/theme-neutral/built': {default: neutralTheme, neutralTheme},
- '@xds/theme-matcha': {default: matchaTheme, matchaTheme},
- '@xds/theme-matcha/built': {default: matchaTheme, matchaTheme},
- '@xds/core/theme': {XDSTheme: ControlledXDSTheme},
- '@xds/core/theme/tokens.stylex': xdsTokens,
- '@xds/core/AlertDialog': AlertDialog,
- '@xds/core/AppShell': AppShell,
- '@xds/core/AspectRatio': AspectRatio,
- '@xds/core/Avatar': Avatar,
- '@xds/core/Badge': Badge,
- '@xds/core/Banner': Banner,
- '@xds/core/Breadcrumbs': Breadcrumbs,
- '@xds/core/Button': Button,
- '@xds/core/Calendar': Calendar,
- '@xds/core/Card': Card,
- '@xds/core/Carousel': Carousel,
- '@xds/core/Center': Center,
- '@xds/core/Chat': Chat,
- '@xds/core/CheckboxInput': CheckboxInput,
- '@xds/core/CheckboxList': CheckboxList,
- '@xds/core/ClickableCard': ClickableCard,
- '@xds/core/CodeBlock': CodeBlock,
- '@xds/core/Collapsible': Collapsible,
- '@xds/core/CommandPalette': CommandPalette,
- '@xds/core/DateInput': DateInput,
- '@xds/core/Dialog': Dialog,
- '@xds/core/Divider': Divider,
- '@xds/core/DropdownMenu': DropdownMenu,
- '@xds/core/EmptyState': EmptyState,
- '@xds/core/Field': Field,
- '@xds/core/FormLayout': FormLayout,
- '@xds/core/Grid': Grid,
- '@xds/core/HoverCard': HoverCard,
- '@xds/core/Icon': Icon,
- '@xds/core/IconButton': IconButton,
- '@xds/core/Item': Item,
- '@xds/core/Kbd': Kbd,
- '@xds/core/Layer': Layer,
- '@xds/core/Layout': Layout,
- '@xds/core/Link': Link,
- '@xds/core/List': List,
- '@xds/core/Markdown': Markdown,
- '@xds/core/MetadataList': MetadataList,
- '@xds/core/MobileNav': MobileNav,
- '@xds/core/MoreMenu': MoreMenu,
- '@xds/core/MultiSelector': MultiSelector,
- '@xds/core/NavIcon': NavIcon,
- '@xds/core/NavMenu': NavMenu,
- '@xds/core/NumberInput': NumberInput,
- '@xds/core/OverflowList': OverflowList,
- '@xds/core/Overlay': Overlay,
- '@xds/core/Pagination': Pagination,
- '@xds/core/Popover': Popover,
- '@xds/core/PowerSearch': PowerSearch,
- '@xds/core/ProgressBar': ProgressBar,
- '@xds/core/RadioList': RadioList,
- '@xds/core/Resizable': Resizable,
- '@xds/core/Section': Section,
- '@xds/core/SegmentedControl': SegmentedControl,
- '@xds/core/SelectableCard': SelectableCard,
- '@xds/core/Selector': Selector,
- '@xds/core/SideNav': SideNav,
- '@xds/core/SizeContext': SizeContext,
- '@xds/core/Skeleton': Skeleton,
- '@xds/core/Slider': Slider,
- '@xds/core/Spinner': Spinner,
- '@xds/core/Stack': Stack,
- '@xds/core/StatusDot': StatusDot,
- '@xds/core/Switch': Switch,
- '@xds/core/TabList': TabList,
- '@xds/core/Table': Table,
- '@xds/core/Text': Text,
- '@xds/core/TextArea': TextArea,
- '@xds/core/TextInput': TextInput,
- '@xds/core/Thumbnail': Thumbnail,
- '@xds/core/TimeInput': TimeInput,
- '@xds/core/Timestamp': Timestamp,
- '@xds/core/Toast': Toast,
- '@xds/core/ToggleButton': ToggleButton,
- '@xds/core/Token': Token,
- '@xds/core/Tokenizer': Tokenizer,
- '@xds/core/Toolbar': Toolbar,
- '@xds/core/Tooltip': Tooltip,
- '@xds/core/TopNav': TopNav,
- '@xds/core/TreeList': TreeList,
- '@xds/core/Typeahead': Typeahead,
- '@xds/core': {
- ...AlertDialog,
- ...AppShell,
- ...AspectRatio,
- ...Avatar,
- ...Badge,
- ...Banner,
- ...Breadcrumbs,
- ...Button,
- ...Calendar,
- ...Card,
- ...Carousel,
- ...Center,
- ...Chat,
- ...CheckboxInput,
- ...CheckboxList,
- ...ClickableCard,
- ...CodeBlock,
- ...Collapsible,
- ...CommandPalette,
- ...DateInput,
- ...Dialog,
- ...Divider,
- ...DropdownMenu,
- ...EmptyState,
- ...Field,
- ...FormLayout,
- ...Grid,
- ...HoverCard,
- ...Icon,
- ...IconButton,
- ...Item,
- ...Kbd,
- ...Layer,
- ...Layout,
- ...Link,
- ...List,
- ...Markdown,
- ...MetadataList,
- ...MobileNav,
- ...MoreMenu,
- ...MultiSelector,
- ...NavIcon,
- ...NavMenu,
- ...NumberInput,
- ...OverflowList,
- ...Overlay,
- ...Pagination,
- ...Popover,
- ...PowerSearch,
- ...ProgressBar,
- ...RadioList,
- ...Resizable,
- ...Section,
- ...SegmentedControl,
- ...SelectableCard,
- ...Selector,
- ...SideNav,
- ...SizeContext,
- ...Skeleton,
- ...Slider,
- ...Spinner,
- ...Stack,
- ...StatusDot,
- ...Switch,
- ...TabList,
- ...Table,
- ...Text,
- ...TextArea,
- ...TextInput,
- ...Thumbnail,
- ...TimeInput,
- ...Timestamp,
- ...Toast,
- ...ToggleButton,
- ...Token,
- ...Tokenizer,
- ...Toolbar,
- ...Tooltip,
- ...TopNav,
- ...TreeList,
- ...Typeahead,
- },
- 'lucide-react': LucideIcons,
- '@heroicons/react/16/solid': Heroicons16Solid,
- '@heroicons/react/20/solid': Heroicons20Solid,
- '@heroicons/react/24/outline': Heroicons24Outline,
- '@heroicons/react/24/solid': Heroicons24Solid,
- 'next/image': {
- default: (props: Record<string, unknown>) =>
- React.createElement('img', props),
- },
-};