Skip to content

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

TypeScript

fix(sandbox): restore block preview centering + add ShowcasePreview (#1631)

Cindy Zhangebc2b909cb90
diff --git a/apps/sandbox/src/app/(fullscreen)/BlockDocContext.tsx b/apps/sandbox/src/app/(fullscreen)/BlockDocContext.tsx
index 38e9266eb6..3b931b52dc 100644
--- a/apps/sandbox/src/app/(fullscreen)/BlockDocContext.tsx
+++ b/apps/sandbox/src/app/(fullscreen)/BlockDocContext.tsx
@@ -1,12 +1,28 @@
'use client';
+import {XDSAspectRatio} from '@xds/core/AspectRatio';
+import {XDSCard} from '@xds/core/Card';
+import {XDSCenter} from '@xds/core/Center';
import {XDSText} from '@xds/core/Text';
+import {XDSVStack} from '@xds/core/Layout';
export interface BlockDocMeta {
aspectRatio: number;
scale: number;
}
+export function ShowcasePreview({children}: {children: React.ReactNode}) {
+ return (
+ <XDSCenter width="100%" height="100vh">
+ <XDSCard variant="muted" style={{width: '100%', maxWidth: 968, height: 360}}>
+ <XDSCenter width="100%" height="100%">
+ {children}
+ </XDSCenter>
+ </XDSCard>
+ </XDSCenter>
+ );
+}
+
export function BlockPreview({
meta,
children,
@@ -18,47 +34,22 @@ export function BlockPreview({
const scale = meta.scale;
return (
- <div
- style={{
- flex: 1,
- overflow: 'auto',
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- padding: 24,
- backgroundColor: 'var(--color-background-wash)',
- }}>
- <div style={{width: '100%', maxWidth: 600}}>
- <div
- style={{
- width: '100%',
- aspectRatio: String(ar),
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- border: '1px solid var(--color-border)',
- borderRadius: 12,
- backgroundColor: 'var(--color-background-card)',
- padding: 24,
- overflow: 'hidden',
- }}>
- <div
- style={{
- width: '100%',
- transform: scale !== 1 ? `scale(${scale})` : undefined,
- transformOrigin: 'center center',
- }}>
- {children}
- </div>
- </div>
- <div
- style={{
- marginTop: 8,
- display: 'flex',
- flexDirection: 'column',
- gap: 2,
- textAlign: 'center',
- }}>
+ <XDSCenter style={{flex: 1, overflow: 'auto', padding: 24, backgroundColor: 'var(--color-background-wash)'}}>
+ <XDSVStack gap={2} style={{width: '100%', maxWidth: 600}}>
+ <XDSCard padding={5} style={{overflow: 'hidden'}}>
+ <XDSAspectRatio ratio={ar}>
+ <XDSCenter
+ width="100%"
+ height="100%"
+ style={{
+ transform: scale !== 1 ? `scale(${scale})` : undefined,
+ transformOrigin: 'center center',
+ }}>
+ {children}
+ </XDSCenter>
+ </XDSAspectRatio>
+ </XDSCard>
+ <XDSVStack gap={0} style={{textAlign: 'center'}}>
<XDSText type="supporting" color="secondary">
aspect-ratio:{' '}
{ar === 1
@@ -74,8 +65,8 @@ export function BlockPreview({
Tweak aspectRatio and scale in the .doc.mjs file so the component
fits nicely in this box.
</XDSText>
- </div>
- </div>
- </div>
+ </XDSVStack>
+ </XDSVStack>
+ </XDSCenter>
);
}
diff --git a/scripts/sync-templates.js b/scripts/sync-templates.js
index 0a04e8406f..0e8cfc9a5c 100644
--- a/scripts/sync-templates.js
+++ b/scripts/sync-templates.js
@@ -203,6 +203,26 @@ function generateBlockRouteWrapper(block) {
path.join(ROUTES_DIR, block.dirName),
path.join(SANDBOX_DIR, 'src', 'app', '(fullscreen)', 'BlockDocContext'),
);
+
+ if (block.isShowcase) {
+ return `'use client';
+/**
+ * AUTO-GENERATED by scripts/sync-templates.js — do not edit.
+ * Block: ${block.name} (showcase)
+ */
+import Component from '${componentRel}';
+import {ShowcasePreview} from '${contextRel}';
+
+export default function Page() {
+ return (
+ <ShowcasePreview>
+ <Component />
+ </ShowcasePreview>
+ );
+}
+`;
+ }
+
return `'use client';
/**
* AUTO-GENERATED by scripts/sync-templates.js — do not edit.