An open source design system that's fully customizable and agent ready
TypeScript
feat(sandbox): set up sandbox build and CI deployment (#162)
Cindy Zhang39be577a3686
diff --git a/.github/scripts/generate-pr-comment.js b/.github/scripts/generate-pr-comment.jsindex e70b3459c4..8e194d75b2 100644--- a/.github/scripts/generate-pr-comment.js+++ b/.github/scripts/generate-pr-comment.js@@ -21,6 +21,7 @@ const screenshotUrlsFile = getArg('screenshot-urls') || 'screenshot-urls.json';const runUrl = getArg('run-url') || '';const prNumber = getArg('pr-number') || '';const storybookUrl = getArg('storybook-url') || '';+const sandboxUrl = getArg('sandbox-url') || '';// Read analysis resultslet analysis = { newComponents: [], modifiedComponents: [], componentStats: {}, totalBundle: {} };@@ -196,16 +197,27 @@ if (storybookUrl) {`;}+// Build sandbox link section+let sandboxSection = '';+if (sandboxUrl) {+ sandboxSection = `### π§ͺ Sandbox Preview++**[View Sandbox for this PR](${sandboxUrl})**++`;+}+// Build footer with linkslet footerLinks = [];if (storybookUrl) footerLinks.push(`[Storybook](${storybookUrl})`);+if (sandboxUrl) footerLinks.push(`[Sandbox](${sandboxUrl})`);if (runUrl) footerLinks.push(`[View full report](${runUrl})`);const footerLinksStr = footerLinks.length > 0 ? ` | ${footerLinks.join(' | ')}` : '';// Build the full commentconst body = `## PR Analysis Report-${storybookSection}${componentSection || '_No new or modified components detected._\n\n'}+${storybookSection}${sandboxSection}${componentSection || '_No new or modified components detected._\n\n'}${bundleSection}${a11ySection}${screenshotSection}diff --git a/.github/workflows/storybook.yml b/.github/workflows/storybook.ymlindex db4e99d68a..cdb0a1e663 100644--- a/.github/workflows/storybook.yml+++ b/.github/workflows/storybook.yml@@ -51,6 +51,7 @@ jobs:runs-on: ubuntu-latestoutputs:storybook_url: ${{ steps.urls.outputs.storybook_url }}+ sandbox_url: ${{ steps.urls.outputs.sandbox_url }}short_hash: ${{ steps.urls.outputs.short_hash }}steps:- name: Checkout@@ -68,24 +69,38 @@ jobs:- name: Build core packagerun: yarn build+ - name: Compute short hash+ id: hash+ run: |+ COMMIT_HASH="${{ github.event.pull_request.head.sha || github.sha }}"+ echo "short_hash=${COMMIT_HASH:0:7}" >> $GITHUB_OUTPUT+- name: Build Storybookrun: yarn workspace @xds/storybook build+ - name: Build Sandbox+ run: yarn workspace @xds/sandbox build+ env:+ SANDBOX_BASE_PATH: /${{ steps.hash.outputs.short_hash }}/sandbox+- name: Prepare versioned deploymentid: urlsrun: |- COMMIT_HASH="${{ github.event.pull_request.head.sha || github.sha }}"- SHORT_HASH="${COMMIT_HASH:0:7}"+ SHORT_HASH="${{ steps.hash.outputs.short_hash }}"REPO_NAME="${{ github.event.repository.name }}"REPO_OWNER="${{ github.repository_owner }}"STORYBOOK_URL="https://${REPO_OWNER}.github.io/${REPO_NAME}/${SHORT_HASH}/"+ SANDBOX_URL="https://${REPO_OWNER}.github.io/${REPO_NAME}/${SHORT_HASH}/sandbox/"echo "short_hash=${SHORT_HASH}" >> $GITHUB_OUTPUTecho "storybook_url=${STORYBOOK_URL}" >> $GITHUB_OUTPUT+ echo "sandbox_url=${SANDBOX_URL}" >> $GITHUB_OUTPUT# Create deployment directory structuremkdir -p deploy/${SHORT_HASH}cp -r apps/storybook/dist/* deploy/${SHORT_HASH}/+ mkdir -p deploy/${SHORT_HASH}/sandbox+ cp -r apps/sandbox/out/* deploy/${SHORT_HASH}/sandbox/# Create root index.html that redirects to latest build (only for main branch)if [ "${{ github.event_name }}" == "push" ]; then@@ -247,6 +262,7 @@ jobs:--screenshots screenshots/screenshots.json \--screenshot-urls screenshot-urls.json \--storybook-url "${{ needs.deploy.outputs.storybook_url }}" \+ --sandbox-url "${{ needs.deploy.outputs.sandbox_url }}" \--run-url "$RUN_URL" \--pr-number "${{ github.event.pull_request.number }}")diff --git a/apps/sandbox/.gitignore b/apps/sandbox/.gitignoreindex c0aed06509..56a9886c54 100644--- a/apps/sandbox/.gitignore+++ b/apps/sandbox/.gitignore@@ -1,4 +1,7 @@node_modulesAGENTS.mdxds.config.mjs-pages+/pages+out+.next+next-env.d.tsdiff --git a/apps/sandbox/README.md b/apps/sandbox/README.mdindex f9a53b0ccf..61ac3cb064 100644--- a/apps/sandbox/README.md+++ b/apps/sandbox/README.md@@ -1,10 +1,61 @@# /apps/sandbox-Local development and testing environment for XDS components.+XDS component sandbox for designer exploration and vibe testing. Deployed alongside Storybook on every PR.<!-- SYNC: When files in this directory change, update this document. -->-| File | Role | Purpose |-|------|------|---------|-| `package.json` | Config | Package dependencies and scripts |+## How it works+The sandbox is a Next.js app configured for static export (`output: 'export'`). On PRs, the CI workflow builds it and deploys to GitHub Pages at a versioned URL:++```+https://facebookexperimental.github.io/xds/{commit}/sandbox/+```++## Adding a new page++1. Create `src/app/pages/<name>/page.tsx`:++```tsx+'use client';++import {XDSVStack, XDSHeading, XDSText} from '@xds/core';++export default function MyPage() {+ return (+ <XDSVStack gap="space4">+ <XDSHeading level={1}>My Page</XDSHeading>+ <XDSText type="body">Content here</XDSText>+ </XDSVStack>+ );+}+```++2. Add an entry to the `pages` array in `src/app/Sidebar.tsx`++The page will appear in the sidebar and get its own URL in the PR deployment.++## Local development++```bash+# From repo root+yarn workspace @xds/sandbox dev+# or+cd apps/sandbox && yarn dev+```++## File manifest++| File | Purpose |+| -------------------------- | ------------------------------------------------------------------------ |+| `package.json` | Dependencies β uses PostCSS path for StyleX |+| `babel.config.js` | StyleX babel plugin config (as plugin, not preset) |+| `postcss.config.js` | StyleX PostCSS plugin β extracts CSS from `@stylex;` directive |+| `next.config.mjs` | Static export, basePath for GitHub Pages, webpack alias for theme tokens |+| `tsconfig.json` | TypeScript config with workspace path aliases |+| `src/app/globals.css` | `@stylex;` injection point β PostCSS replaces this with extracted CSS |+| `src/app/providers.tsx` | Client-side theme provider wrapper |+| `src/app/layout.tsx` | Root layout with sidebar navigation |+| `src/app/Sidebar.tsx` | Sidebar navigation component |+| `src/app/page.tsx` | Home page |+| `src/app/pages/*/page.tsx` | Example sandbox pages |diff --git a/apps/sandbox/babel.config.js b/apps/sandbox/babel.config.jsindex 8f1e986d17..a358cce1e7 100644--- a/apps/sandbox/babel.config.js+++ b/apps/sandbox/babel.config.js@@ -1,15 +1,26 @@/* global module, process, __dirname */+const path = require('path');++const rootDir = path.resolve(__dirname, '../..');+module.exports = {- presets: [+ presets: ['next/babel'],+ plugins: [['@stylexjs/babel-plugin',{dev: process.env.NODE_ENV === 'development',runtimeInjection: false,genConditionalClasses: true,+ treeshakeCompensation: true,+ aliases: {+ '@xds/core/*': [path.join(rootDir, 'packages/core/src/*')],+ '@xds/core': [path.join(rootDir, 'packages/core/src')],+ '@xds/theme/*': [path.join(rootDir, 'packages/theme/src/*')],+ },unstable_moduleResolution: {type: 'commonJS',- rootDir: __dirname,+ rootDir,},},],diff --git a/apps/sandbox/next.config.mjs b/apps/sandbox/next.config.mjsindex 6e23e39365..ffb822704c 100644--- a/apps/sandbox/next.config.mjs+++ b/apps/sandbox/next.config.mjs@@ -1,10 +1,32 @@-import stylexPlugin from '@stylexjs/nextjs-plugin';+import path from 'path';+import {fileURLToPath} from 'url';++const __dirname = path.dirname(fileURLToPath(import.meta.url));/** @type {import('next').NextConfig} */const nextConfig = {- transpilePackages: ['@xds/core'],+ output: 'export',+ trailingSlash: true,+ basePath: process.env.SANDBOX_BASE_PATH || '',+ transpilePackages: ['@xds/core', '@xds/theme'],+ images: {+ unoptimized: true,+ },+ typescript: {+ // XDS core has a known type issue in Popover internals;+ // safe to ignore for the sandbox.+ ignoreBuildErrors: true,+ },+ webpack: (config) => {+ config.resolve.alias = {+ ...config.resolve.alias,+ '@xds/core/theme/tokens.stylex': path.resolve(+ __dirname,+ '../../packages/core/src/theme/tokens.stylex.ts',+ ),+ };+ return config;+ },};-export default stylexPlugin({- rootDir: __dirname,-})(nextConfig);+export default nextConfig;diff --git a/apps/sandbox/package.json b/apps/sandbox/package.jsonindex d7e17c7182..5b039efb74 100644--- a/apps/sandbox/package.json+++ b/apps/sandbox/package.json@@ -12,14 +12,16 @@"@stylexjs/stylex": "^0.17.4","@xds/cli": "*","@xds/core": "*",+ "@xds/theme": "*","next": "^15.0.0","react": "^18.3.0",- "react-dom": "^18.3.0",- "@xds/theme": "*"+ "react-dom": "^18.3.0"},"devDependencies": {+ "@babel/preset-react": "^7.25.0",+ "@babel/preset-typescript": "^7.25.0","@stylexjs/babel-plugin": "^0.17.4",- "@stylexjs/nextjs-plugin": "^0.11.1",+ "@stylexjs/postcss-plugin": "^0.17.4","@types/node": "^22.0.0","@types/react": "^18.3.0","@types/react-dom": "^18.3.0",diff --git a/apps/sandbox/postcss.config.js b/apps/sandbox/postcss.config.jsnew file mode 100644index 0000000000..787fc76b54--- /dev/null+++ b/apps/sandbox/postcss.config.js@@ -0,0 +1,31 @@+/* global module, __dirname */+const path = require('path');+const babelConfig = require('./babel.config');++const rootDir = path.resolve(__dirname, '../..');++module.exports = {+ plugins: {+ '@stylexjs/postcss-plugin': {+ include: [+ 'src/**/*.{js,jsx,ts,tsx}',+ path.join(rootDir, 'packages/core/src/**/*.{ts,tsx}'),+ path.join(rootDir, 'packages/theme/src/**/*.{ts,tsx}'),+ ],+ babelConfig: {+ babelrc: false,+ parserOpts: {+ plugins: ['typescript', 'jsx'],+ },+ presets: [+ ['@babel/preset-react', {runtime: 'automatic'}],+ // Must come after preset-react (runs first due to reverse order)+ // to strip TypeScript type assertions before StyleX evaluates them.+ '@babel/preset-typescript',+ ],+ plugins: babelConfig.plugins,+ },+ useCSSLayers: true,+ },+ },+};diff --git a/apps/sandbox/src/app/Sidebar.tsx b/apps/sandbox/src/app/Sidebar.tsxnew file mode 100644index 0000000000..05e0a965c7--- /dev/null+++ b/apps/sandbox/src/app/Sidebar.tsx@@ -0,0 +1,78 @@+'use client';++import * as stylex from '@stylexjs/stylex';+import Link from 'next/link';+import {usePathname} from 'next/navigation';++/**+ * Sidebar navigation for the sandbox.+ *+ * To add a new page:+ * 1. Create `src/app/pages/<name>/page.tsx`+ * 2. Add an entry to the `pages` array below+ *+ * Note: hrefs use trailing slashes because the sandbox is a static export+ * with `trailingSlash: true` in next.config.mjs. Each route becomes a+ * directory with an `index.html` file (e.g. `/pages/example/index.html`).+ * Next.js `<Link>` handles the basePath prefix automatically.+ */+const pages = [+ {name: 'Home', href: '/'},+ {name: 'Example', href: '/pages/example/'},+];++const styles = stylex.create({+ sidebar: {+ width: 220,+ borderRight: '1px solid #e0e0e0',+ padding: '1.5rem 1rem',+ display: 'flex',+ flexDirection: 'column',+ gap: '0.25rem',+ },+ title: {+ fontSize: '0.75rem',+ fontWeight: 700,+ textTransform: 'uppercase',+ letterSpacing: '0.05em',+ color: '#666',+ marginBottom: '0.75rem',+ padding: '0 0.5rem',+ },+ link: {+ display: 'block',+ padding: '0.5rem 0.75rem',+ borderRadius: 6,+ textDecoration: 'none',+ fontSize: '0.875rem',+ color: '#333',+ transition: 'background 0.15s',+ },+ linkActive: {+ backgroundColor: '#f0f0f0',+ fontWeight: 600,+ },+});++export function Sidebar() {+ const pathname = usePathname();++ return (+ <nav {...stylex.props(styles.sidebar)}>+ <div {...stylex.props(styles.title)}>Sandbox</div>+ {pages.map(page => {+ const isActive =+ pathname === page.href ||+ (page.href !== '/' && pathname.startsWith(page.href));+ return (+ <Link+ key={page.href}+ href={page.href}+ {...stylex.props(styles.link, isActive && styles.linkActive)}>+ {page.name}+ </Link>+ );+ })}+ </nav>+ );+}diff --git a/apps/sandbox/src/app/globals.css b/apps/sandbox/src/app/globals.cssnew file mode 100644index 0000000000..867d14b250--- /dev/null+++ b/apps/sandbox/src/app/globals.css@@ -0,0 +1 @@+@stylex;diff --git a/apps/sandbox/src/app/layout.tsx b/apps/sandbox/src/app/layout.tsxindex 3bfb281f83..fad379ca07 100644--- a/apps/sandbox/src/app/layout.tsx+++ b/apps/sandbox/src/app/layout.tsx@@ -1,7 +1,9 @@import type {Metadata} from 'next';import '@xds/core/reset.css';-import {XDSTheme} from '@xds/core/theme';-import {defaultTheme} from '@xds/theme/default';+import '@xds/core/typography.css';+import './globals.css';+import {Providers} from './providers';+import {Sidebar} from './Sidebar';export const metadata: Metadata = {title: 'XDS Sandbox',@@ -12,7 +14,12 @@ export default function RootLayout({children}: {children: React.ReactNode}) {return (<html lang="en"><body>- <XDSTheme theme={defaultTheme}>{children}</XDSTheme>+ <Providers>+ <div style={{display: 'flex', minHeight: '100vh'}}>+ <Sidebar />+ <main style={{flex: 1, padding: '2rem'}}>{children}</main>+ </div>+ </Providers></body></html>);diff --git a/apps/sandbox/src/app/page.tsx b/apps/sandbox/src/app/page.tsxindex 176ae58b82..5e970f3e6b 100644--- a/apps/sandbox/src/app/page.tsx+++ b/apps/sandbox/src/app/page.tsx@@ -1,30 +1,28 @@+'use client';+import * as stylex from '@stylexjs/stylex';-import {XDSText} from '@xds/core';-import {XDSButton} from '@xds/core';-import {XDSVStack} from '@xds/core';+import {XDSVStack} from '@xds/core/Layout';+import {XDSText, XDSHeading} from '@xds/core/Text';const styles = stylex.create({- main: {- display: 'flex',- alignItems: 'center',- justifyContent: 'center',- minHeight: '100vh',- padding: 'var(--spacing-6)',+ container: {+ maxWidth: 640,},});export default function Home() {return (- <main {...stylex.props(styles.main)}>- <XDSVStack gap="space4" hAlign="center">- <XDSText type="large" weight="bold">- XDS Sandbox- </XDSText>- <XDSText type="body" color="secondary">- A testing ground for XDS components.- </XDSText>- <XDSButton label="Get Started" variant="primary" />+ <div {...stylex.props(styles.container)}>+ <XDSVStack gap="space6">+ <XDSVStack gap="space2">+ <XDSHeading level={1}>XDS Sandbox</XDSHeading>+ <XDSText color="secondary">+ A testing ground for XDS components. Use the sidebar to explore+ example pages, or create new ones under{' '}+ <XDSText weight="bold">src/app/pages/</XDSText>.+ </XDSText>+ </XDSVStack></XDSVStack>- </main>+ </div>);}diff --git a/apps/sandbox/src/app/pages/example/page.tsx b/apps/sandbox/src/app/pages/example/page.tsxnew file mode 100644index 0000000000..054c3d9bbd--- /dev/null+++ b/apps/sandbox/src/app/pages/example/page.tsx@@ -0,0 +1,99 @@+'use client';++import * as stylex from '@stylexjs/stylex';+import {XDSVStack, XDSHStack} from '@xds/core/Layout';+import {XDSButton} from '@xds/core/Button';+import {XDSText, XDSHeading} from '@xds/core/Text';+import {XDSTextInput} from '@xds/core/TextInput';+import {XDSCheckboxInput} from '@xds/core/CheckboxInput';+import {XDSBadge} from '@xds/core/Badge';+import {XDSDivider} from '@xds/core';++const styles = stylex.create({+ container: {+ maxWidth: 640,+ },+});++/**+ * Example sandbox page.+ *+ * Copy this file to create a new page:+ * 1. Create `src/app/pages/<name>/page.tsx`+ * 2. Add an entry to the `pages` array in `src/app/Sidebar.tsx`+ */+export default function ExamplePage() {+ return (+ <div {...stylex.props(styles.container)}>+ <XDSVStack gap="space6">+ <XDSVStack gap="space2">+ <XDSHeading level={1}>Example Page</XDSHeading>+ <XDSText color="secondary">+ A scaffold showing common XDS components. Copy this file to create+ new pages.+ </XDSText>+ </XDSVStack>++ <XDSDivider />++ {/* Buttons */}+ <XDSVStack gap="space3">+ <XDSHeading level={2}>Buttons</XDSHeading>+ <XDSHStack gap="space3" align="center">+ <XDSButton variant="primary">Primary</XDSButton>+ <XDSButton variant="secondary">Secondary</XDSButton>+ <XDSButton variant="ghost">Ghost</XDSButton>+ </XDSHStack>+ <XDSHStack gap="space3" align="center">+ <XDSButton size="small">Small</XDSButton>+ <XDSButton size="medium">Medium</XDSButton>+ <XDSButton size="large">Large</XDSButton>+ </XDSHStack>+ </XDSVStack>++ <XDSDivider />++ {/* Badges */}+ <XDSVStack gap="space3">+ <XDSHeading level={2}>Badges</XDSHeading>+ <XDSHStack gap="space3" align="center">+ <XDSBadge variant="info">Info</XDSBadge>+ <XDSBadge variant="success">Success</XDSBadge>+ <XDSBadge variant="warning">Warning</XDSBadge>+ <XDSBadge variant="error">Error</XDSBadge>+ </XDSHStack>+ </XDSVStack>++ <XDSDivider />++ {/* Typography */}+ <XDSVStack gap="space3">+ <XDSHeading level={2}>Typography</XDSHeading>+ <XDSHeading level={3}>Heading 3</XDSHeading>+ <XDSText type="large" weight="bold">+ Large bold text+ </XDSText>+ <XDSText>Default body text</XDSText>+ <XDSText type="detail" color="secondary">+ Detail text in secondary color+ </XDSText>+ </XDSVStack>++ <XDSDivider />++ {/* Form Controls */}+ <XDSVStack gap="space3">+ <XDSHeading level={2}>Form Controls</XDSHeading>+ <XDSTextInput label="Name" placeholder="Enter your name" />+ <XDSTextInput+ label="Email"+ placeholder="[email protected]"+ type="email"+ />+ <XDSCheckboxInput label="Enable notifications" />+ <XDSCheckboxInput label="Subscribe to updates" />+ </XDSVStack>+ </XDSVStack>+ </div>+ );+}diff --git a/apps/sandbox/src/app/providers.tsx b/apps/sandbox/src/app/providers.tsxnew file mode 100644index 0000000000..1ab11e829a--- /dev/null+++ b/apps/sandbox/src/app/providers.tsx@@ -0,0 +1,8 @@+'use client';++import {XDSTheme} from '@xds/core/theme';+import {defaultTheme} from '@xds/theme/default';++export function Providers({children}: {children: React.ReactNode}) {+ return <XDSTheme theme={defaultTheme}>{children}</XDSTheme>;+}diff --git a/apps/sandbox/tsconfig.json b/apps/sandbox/tsconfig.jsonindex 63a5e10f6f..c1334095f8 100644--- a/apps/sandbox/tsconfig.json+++ b/apps/sandbox/tsconfig.json@@ -19,16 +19,7 @@}],"paths": {- "@/*": ["./src/*"],- "@xds/core": ["../../packages/core/src/index.ts"],- "@xds/core/*": [- "../../packages/core/src/*/index.ts",- "../../packages/core/src/*"- ],- "@xds/theme/*": [- "../../packages/theme/src/*/index.ts",- "../../packages/theme/src/*"- ]+ "@/*": ["./src/*"]}},"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],diff --git a/eslint.config.js b/eslint.config.jsindex b1bfb48f22..a0babf178c 100644--- a/eslint.config.js+++ b/eslint.config.js@@ -34,6 +34,7 @@ export default tseslint.config("**/*.test-violations.tsx","apps/example-nextjs/*.js","apps/example-nextjs/next-env.d.ts",+ "apps/sandbox/*.js",],},{diff --git a/package.json b/package.jsonindex 2364691c3c..418265893b 100644--- a/package.json+++ b/package.json@@ -9,7 +9,7 @@"e2e"],"scripts": {- "build": "yarn workspace @xds/core build",+ "build": "yarn workspace @xds/core build && yarn workspace @xds/theme build","dev": "yarn workspace @xds/storybook dev","test": "vitest run","test:watch": "vitest",diff --git a/yarn.lock b/yarn.lockindex 772622e29c..c6b23a7422 100644--- a/yarn.lock+++ b/yarn.lock@@ -1998,16 +1998,17 @@babel-plugin-syntax-hermes-parser "^0.26.0"esbuild "^0.24.0"-"@stylexjs/nextjs-plugin@^0.11.1":- version "0.11.1"- resolved "https://registry.yarnpkg.com/@stylexjs/nextjs-plugin/-/nextjs-plugin-0.11.1.tgz#0137b7d2dd8751cdfcf337079e24d160c2b2c61b"- integrity sha512-42mJGw9W3i9cRrChv25JCMGvWhCVVcmt1EqgOgRMy3XTH45Ehd9TkwDiVmhknvSEDKxw+ib3AiSPjZ1ehZ9d6A==+"@stylexjs/postcss-plugin@^0.17.4":+ version "0.17.5"+ resolved "https://registry.yarnpkg.com/@stylexjs/postcss-plugin/-/postcss-plugin-0.17.5.tgz#03ecd009409cbcb59e5083cac8a62f591ec38e16"+ integrity sha512-GeveZXN8aDrXTSRpDM0SvCjmmY7WCfoel+lWcsf47QcJvjz5auGmh3a9LhIFLpwmAgpsVr20RyB8yxX93NaKow==dependencies:"@babel/core" "^7.26.8"- "@babel/plugin-syntax-flow" "^7.26.0"- "@babel/plugin-syntax-jsx" "^7.25.9"- "@babel/plugin-syntax-typescript" "^7.25.9"- "@stylexjs/babel-plugin" "0.11.1"+ "@stylexjs/babel-plugin" "0.17.5"+ fast-glob "^3.3.2"+ glob-parent "^6.0.2"+ is-glob "^4.0.3"+ postcss "^8.4.49""@stylexjs/postcss-plugin@^0.17.4":version "0.17.5"