diff --git a/apps/docs/package.json b/apps/docs/package.json index 12f7bd8a..309d2e04 100644 --- a/apps/docs/package.json +++ b/apps/docs/package.json @@ -7,6 +7,9 @@ }, "type": "module", "sideEffects": false, + "imports": { + "#docs/comparison": "./src/examples/comparison.tsx" + }, "scripts": { "build": "vp build", "check:docs": "tsx scripts/check-docs.ts", diff --git a/apps/docs/scripts/generate-playground-types.ts b/apps/docs/scripts/generate-playground-types.ts index 1df4b74f..900f4d60 100644 --- a/apps/docs/scripts/generate-playground-types.ts +++ b/apps/docs/scripts/generate-playground-types.ts @@ -20,9 +20,11 @@ import * as z from 'zod'; const scriptDir = dirname(fileURLToPath(import.meta.url)); const docsPackageJsonPath = resolve(scriptDir, '../package.json'); +const docsExamplesDir = resolve(scriptDir, '../src/examples'); const reactPackageDir = resolve(scriptDir, '../../../packages/@luke-ui/react'); const rainbowSprinklesDir = resolve(scriptDir, '../../../packages/@luke-ui/rainbow-sprinkles'); const outputPath = resolve(scriptDir, '../src/generated/playground-types.generated.json'); +const docsComparisonVirtualPath = 'file:///docs/comparison.tsx'; const files: Record = {}; @@ -34,6 +36,10 @@ function addFile(packageName: string, packageDir: string, filePath: string): voi files[virtualPath(packageName, relative(packageDir, filePath))] = readFileSync(filePath, 'utf8'); } +function addDocsFile(virtualPath: string, filePath: string): void { + files[virtualPath] = readFileSync(filePath, 'utf8'); +} + function walk(dir: string, visit: (filePath: string) => void): void { for (const entry of readdirSync(dir, { withFileTypes: true })) { if (entry.name === 'node_modules') continue; @@ -151,6 +157,8 @@ for (const [packageName, packageDir] of externalTypePackages) { addTypesPackage(packageName, packageDir); } +addDocsFile(docsComparisonVirtualPath, join(docsExamplesDir, 'comparison.tsx')); + const output = JSON.stringify(files); mkdirSync(dirname(outputPath), { recursive: true }); writeFileSync(outputPath, output); diff --git a/apps/docs/src/components/playground/preview-runner.browser.test.tsx b/apps/docs/src/components/playground/preview-runner.browser.test.tsx index 6bbedf54..295b3e36 100644 --- a/apps/docs/src/components/playground/preview-runner.browser.test.tsx +++ b/apps/docs/src/components/playground/preview-runner.browser.test.tsx @@ -7,6 +7,7 @@ import { act } from 'react'; import type { Root } from 'react-dom/client'; import { createRoot } from 'react-dom/client'; import { afterEach, expect, test } from 'vite-plus/test'; +import toneSource from '../../examples/button/tones.tsx?raw'; import type { PlaygroundPreviewMessage } from '../../lib/playground-protocol.js'; import { isPlaygroundPreviewMessage } from '../../lib/playground-protocol.js'; import { DocsThemeRoot } from '../theme-controls.js'; @@ -94,6 +95,20 @@ test('compiles parent playground code and posts success', async () => { .toEqual({ type: 'playground:success' }); }); +test('runs the Button tone example with the docs comparison helper', async () => { + const messages = collectParentPreviewMessages(); + await mountPreview(); + + await act(async () => { + postFromParent({ code: toneSource, type: 'playground:code' }); + }); + + await expect + .poll(() => messages.find((message) => message.type === 'playground:success')) + .toEqual({ type: 'playground:success' }); + expect(container).toHaveTextContent('Neutral'); +}); + test('posts the compileComponent error when parent playground code is invalid', async () => { const messages = collectParentPreviewMessages(); await mountPreview(); diff --git a/apps/docs/src/examples/button/appearance.tsx b/apps/docs/src/examples/button/appearance.tsx index 58a4899d..ca201742 100644 --- a/apps/docs/src/examples/button/appearance.tsx +++ b/apps/docs/src/examples/button/appearance.tsx @@ -1,12 +1,18 @@ -import { Box } from '@luke-ui/react/box'; import { Button } from '@luke-ui/react/button'; +import { Comparison, ComparisonItem } from '#docs/comparison'; export default () => { return ( - - - - - + + + + + + + + + + + ); }; diff --git a/apps/docs/src/examples/button/sizes.tsx b/apps/docs/src/examples/button/sizes.tsx index 35cbdc01..89ec560e 100644 --- a/apps/docs/src/examples/button/sizes.tsx +++ b/apps/docs/src/examples/button/sizes.tsx @@ -1,16 +1,15 @@ -import { Box } from '@luke-ui/react/box'; import { Button } from '@luke-ui/react/button'; -import { Icon } from '@luke-ui/react/icon'; +import { Comparison, ComparisonItem } from '#docs/comparison'; export default () => { return ( - - - - + + + + + + + + ); }; diff --git a/apps/docs/src/examples/button/tones.tsx b/apps/docs/src/examples/button/tones.tsx index 15d94b96..bc9ebfb3 100644 --- a/apps/docs/src/examples/button/tones.tsx +++ b/apps/docs/src/examples/button/tones.tsx @@ -1,12 +1,18 @@ -import { Box } from '@luke-ui/react/box'; import { Button } from '@luke-ui/react/button'; +import { Comparison, ComparisonItem } from '#docs/comparison'; export default () => { return ( - - - - - + + + + + + + + + + + ); }; diff --git a/apps/docs/src/examples/checkbox/sizes.tsx b/apps/docs/src/examples/checkbox/sizes.tsx index d3fd987e..b62457d1 100644 --- a/apps/docs/src/examples/checkbox/sizes.tsx +++ b/apps/docs/src/examples/checkbox/sizes.tsx @@ -1,18 +1,24 @@ -import { Box } from '@luke-ui/react/box'; import { Checkbox } from '@luke-ui/react/checkbox'; +import { Comparison, ComparisonItem } from '#docs/comparison'; export default () => { return ( - - - Small - - - Medium - - - Large - - + + + + Example checkbox + + + + + Example checkbox + + + + + Example checkbox + + + ); }; diff --git a/apps/docs/src/examples/combobox-field/sizes.tsx b/apps/docs/src/examples/combobox-field/sizes.tsx index 57e02c54..50e281f7 100644 --- a/apps/docs/src/examples/combobox-field/sizes.tsx +++ b/apps/docs/src/examples/combobox-field/sizes.tsx @@ -1,37 +1,42 @@ import { Box } from '@luke-ui/react/box'; import { ComboboxField } from '@luke-ui/react/combobox-field'; import { ComboboxItem } from '@luke-ui/react/primitives/combobox'; +import { Comparison, ComparisonItem } from '#docs/comparison'; -type Fruit = { id: string; label: string }; +type Option = { id: string; label: string }; -const fruits: Array = [ - { id: 'apple', label: 'Apple' }, - { id: 'orange', label: 'Orange' }, - { id: 'banana', label: 'Banana' }, - { id: 'grape', label: 'Grape' }, +const options: Array