Skip to content

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

TypeScript

feat(docsite): rename (marketing) to (site), add Open in Playground (#2342)

Cindy Zhang36226335625e
diff --git a/apps/docsite/scripts/generate-data.mjs b/apps/docsite/scripts/generate-data.mjs
index 2e9519e580..bfe1f00e0d 100644
--- a/apps/docsite/scripts/generate-data.mjs
+++ b/apps/docsite/scripts/generate-data.mjs
@@ -691,11 +691,15 @@ async function generateTemplateRegistry() {
// Skip scaffolds — these are starter templates, not showcases
if (doc.scaffold) continue;
+ let source = '';
+ try { source = fs.readFileSync(pagePath, 'utf-8'); } catch { /* ignore */ }
+
templates.push({
slug: dir.name,
name: doc.name || dir.name,
description: doc.description || '',
isReady: doc.isReady ?? true,
+ source,
});
}
@@ -708,6 +712,7 @@ export interface TemplateEntry {
name: string;
description: string;
isReady: boolean;
+ source: string;
}
export const templates: TemplateEntry[] = ${JSON.stringify(templates, null, 2)};
diff --git a/apps/docsite/src/app/(marketing)/community/page.tsx b/apps/docsite/src/app/(site)/community/page.tsx
similarity index 100%
rename from apps/docsite/src/app/(marketing)/community/page.tsx
rename to apps/docsite/src/app/(site)/community/page.tsx
diff --git a/apps/docsite/src/app/(marketing)/layout.tsx b/apps/docsite/src/app/(site)/layout.tsx
similarity index 100%
rename from apps/docsite/src/app/(marketing)/layout.tsx
rename to apps/docsite/src/app/(site)/layout.tsx
diff --git a/apps/docsite/src/app/(marketing)/page.tsx b/apps/docsite/src/app/(site)/page.tsx
similarity index 100%
rename from apps/docsite/src/app/(marketing)/page.tsx
rename to apps/docsite/src/app/(site)/page.tsx
diff --git a/apps/docsite/src/app/(marketing)/templates/[slug]/page.tsx b/apps/docsite/src/app/(site)/templates/[slug]/page.tsx
similarity index 75%
rename from apps/docsite/src/app/(marketing)/templates/[slug]/page.tsx
rename to apps/docsite/src/app/(site)/templates/[slug]/page.tsx
index 6b09f38f1f..2a5c2e79b8 100644
--- a/apps/docsite/src/app/(marketing)/templates/[slug]/page.tsx
+++ b/apps/docsite/src/app/(site)/templates/[slug]/page.tsx
@@ -3,14 +3,15 @@
/**
* Page type: template viewer
* Preview a template + view its source code.
- * TODO: render template in iframe, show source from pipeline.
*/
import {notFound} from 'next/navigation';
import {XDSHeading, XDSText} from '@xds/core/Text';
import {XDSVStack} from '@xds/core/Layout';
import {XDSSection} from '@xds/core/Section';
+import {XDSCodeBlock} from '@xds/core/CodeBlock';
import {templates} from '../../../../generated/templateRegistry';
+import {PlaygroundButton} from '../../../../components/PlaygroundButton';
export function generateStaticParams() {
return templates.map(t => ({slug: t.slug}));
@@ -34,7 +35,12 @@ export default async function TemplatePage({
<XDSText type="body" color="secondary">
{template.description}
</XDSText>
- {/* TODO: template preview iframe + source code viewer */}
+ {template.source && (
+ <>
+ <PlaygroundButton source={template.source} />
+ <XDSCodeBlock code={template.source} language="tsx" hasCopyButton />
+ </>
+ )}
</XDSVStack>
</XDSSection>
);
diff --git a/apps/docsite/src/app/(marketing)/templates/page.tsx b/apps/docsite/src/app/(site)/templates/page.tsx
similarity index 86%
rename from apps/docsite/src/app/(marketing)/templates/page.tsx
rename to apps/docsite/src/app/(site)/templates/page.tsx
index 8a70de558c..6201f6094d 100644
--- a/apps/docsite/src/app/(marketing)/templates/page.tsx
+++ b/apps/docsite/src/app/(site)/templates/page.tsx
@@ -18,6 +18,7 @@ import {XDSOverlay} from '@xds/core/Overlay';
import {XDSBadge} from '@xds/core/Badge';
import {templates} from '../../../generated/templateRegistry';
import {TemplateThumbnail} from '../../../components/TemplateThumbnail';
+import {buildPlaygroundHref} from '../../../components/playgroundLink';
const styles = stylex.create({
heroTitle: {
@@ -56,6 +57,7 @@ export default function TemplatesPage() {
slug: t.slug,
href: `/templates/${t.slug}`,
isReady: t.isReady,
+ source: t.source,
})),
[],
);
@@ -102,12 +104,18 @@ export default function TemplatesPage() {
size="sm"
href={item.href}
/>
- <XDSButton
- label="Use"
- variant="secondary"
- size="sm"
- href={item.href}
- />
+ {item.source && (
+ <XDSButton
+ label="Open in Playground"
+ variant="secondary"
+ size="sm"
+ onClick={() => {
+ window.location.href = buildPlaygroundHref(
+ item.source,
+ );
+ }}
+ />
+ )}
</XDSHStack>
</XDSVStack>
</div>
diff --git a/apps/docsite/src/app/(marketing)/themes/editor/page.tsx b/apps/docsite/src/app/(site)/themes/editor/page.tsx
similarity index 100%
rename from apps/docsite/src/app/(marketing)/themes/editor/page.tsx
rename to apps/docsite/src/app/(site)/themes/editor/page.tsx
diff --git a/apps/docsite/src/app/(marketing)/themes/page.tsx b/apps/docsite/src/app/(site)/themes/page.tsx
similarity index 100%
rename from apps/docsite/src/app/(marketing)/themes/page.tsx
rename to apps/docsite/src/app/(site)/themes/page.tsx
diff --git a/apps/docsite/src/app/playground/PlaygroundClient.tsx b/apps/docsite/src/app/playground/PlaygroundClient.tsx
index 0ac9a5016b..c6a25bc927 100644
--- a/apps/docsite/src/app/playground/PlaygroundClient.tsx
+++ b/apps/docsite/src/app/playground/PlaygroundClient.tsx
@@ -320,6 +320,18 @@ export function PlaygroundClient() {
return () => mq.removeEventListener('change', update);
}, []);
+ // Re-read code from hash on hashchange (e.g. SPA navigation with new code)
+ useEffect(() => {
+ const onHashChange = () => {
+ const newCode = getInitialCode();
+ if (newCode !== DEFAULT_CODE) {
+ setCode(newCode);
+ }
+ };
+ window.addEventListener('hashchange', onHashChange);
+ return () => window.removeEventListener('hashchange', onHashChange);
+ }, []);
+
const send = useCallback((c: string) => {
const win = iframeRef.current?.contentWindow;
if (!win) {
diff --git a/apps/docsite/src/components/PlaygroundButton.tsx b/apps/docsite/src/components/PlaygroundButton.tsx
new file mode 100644
index 0000000000..c028cc0080
--- /dev/null
+++ b/apps/docsite/src/components/PlaygroundButton.tsx
@@ -0,0 +1,29 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+'use client';
+
+import {XDSButton} from '@xds/core/Button';
+import {buildPlaygroundHref} from './playgroundLink';
+
+interface PlaygroundButtonProps {
+ source: string;
+ label?: string;
+}
+
+export function PlaygroundButton({
+ source,
+ label = 'Open in Playground',
+}: PlaygroundButtonProps) {
+ const href = buildPlaygroundHref(source);
+
+ return (
+ <XDSButton
+ label={label}
+ variant="secondary"
+ size="sm"
+ onClick={() => {
+ window.location.href = href;
+ }}
+ />
+ );
+}
diff --git a/apps/docsite/src/components/component-detail/ExampleBlock.tsx b/apps/docsite/src/components/component-detail/ExampleBlock.tsx
index 35fd1273a2..6fe65a8bc6 100644
--- a/apps/docsite/src/components/component-detail/ExampleBlock.tsx
+++ b/apps/docsite/src/components/component-detail/ExampleBlock.tsx
@@ -10,7 +10,10 @@ import {XDSText} from '@xds/core/Text';
import {XDSCodeBlock} from '@xds/core/CodeBlock';
import {XDSTabList, XDSTab} from '@xds/core/TabList';
import {XDSSpinner} from '@xds/core/Spinner';
+import {XDSButton} from '@xds/core/Button';
+import {XDSHStack} from '@xds/core/Layout';
import type {ExampleEntry} from '../../generated/exampleRegistry';
+import {buildPlaygroundHref} from '../playgroundLink';
function LivePreview({entry}: {entry: ExampleEntry}) {
const [Component, setComponent] = useState<ComponentType | null>(null);
@@ -74,10 +77,24 @@ export function ExampleBlock({entry}: ExampleBlockProps) {
<LivePreview entry={entry} />
<XDSSection variant="muted" padding={1} dividers={['top']}>
- <XDSTabList value={tab} onChange={setTab} size="sm">
- <XDSTab value="description" label="Description" />
- <XDSTab value="code" label="Code" />
- </XDSTabList>
+ <XDSHStack
+ gap={1}
+ style={{justifyContent: 'space-between', alignItems: 'center'}}>
+ <XDSTabList value={tab} onChange={setTab} size="sm">
+ <XDSTab value="description" label="Description" />
+ <XDSTab value="code" label="Code" />
+ </XDSTabList>
+ {entry.source && (
+ <XDSButton
+ label="Open in Playground"
+ variant="ghost"
+ size="sm"
+ onClick={() => {
+ window.location.href = buildPlaygroundHref(entry.source);
+ }}
+ />
+ )}
+ </XDSHStack>
</XDSSection>
<XDSSection variant="muted">
{tab === 'description' ? (
diff --git a/apps/docsite/src/components/playgroundLink.ts b/apps/docsite/src/components/playgroundLink.ts
new file mode 100644
index 0000000000..ae947c8986
--- /dev/null
+++ b/apps/docsite/src/components/playgroundLink.ts
@@ -0,0 +1,11 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+import {compressToEncodedURIComponent} from 'lz-string';
+
+/**
+ * Build a playground URL with prepopulated source code.
+ */
+export function buildPlaygroundHref(source: string): string {
+ const compressed = compressToEncodedURIComponent(source);
+ return `/playground#code=${compressed}`;
+}