Skip to content

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

TypeScript

feat(docsite): live iframe previews for login templates (#1483)

rubyycheungc99d18c7c388
diff --git a/apps/sandbox/public/templates/login-split-cover.png b/apps/sandbox/public/templates/login-split-cover.png
new file mode 100644
index 0000000000..175e700cac
Binary files /dev/null and b/apps/sandbox/public/templates/login-split-cover.png differ
diff --git a/apps/sandbox/src/app/(fullscreen)/pages/docsite/TemplateCard.tsx b/apps/sandbox/src/app/(fullscreen)/pages/docsite/TemplateCard.tsx
index 3b316a4939..a521162e2e 100644
--- a/apps/sandbox/src/app/(fullscreen)/pages/docsite/TemplateCard.tsx
+++ b/apps/sandbox/src/app/(fullscreen)/pages/docsite/TemplateCard.tsx
@@ -1,6 +1,6 @@
'use client';
-import React, {useState, useEffect} from 'react';
+import React, {useState, useEffect, useRef, useCallback} from 'react';
import {XDSCard} from '@xds/core/Card';
import {XDSButton} from '@xds/core/Button';
import {XDSHeading, XDSText} from '@xds/core/Text';
@@ -9,9 +9,11 @@ import {XDSPopover} from '@xds/core/Popover';
import {BookmarkIcon, BookmarkFilledIcon} from './docsite-icons';
import {CraftingCat} from './CraftingCat';
import {SharePopoverContent} from './SharePopover';
+import {basePath} from './constants';
export function TemplateCard({
src,
+ slug,
name,
isSelected: _isSelected,
onSelect: _onSelect,
@@ -22,6 +24,7 @@ export function TemplateCard({
cardSize: _cardSize = 'medium',
}: {
src: string;
+ slug?: string;
name: string;
isSelected?: boolean;
onSelect?: () => void;
@@ -35,6 +38,22 @@ export function TemplateCard({
const [showCanvas, setShowCanvas] = useState(false);
const [showUsePopover, setShowUsePopover] = useState(false);
const [bookmarked, setBookmarked] = useState(false);
+ const [iframeScale, setIframeScale] = useState(0.25);
+ const iframeWrapperRef = useRef<HTMLDivElement>(null);
+
+ const updateIframeScale = useCallback(() => {
+ if (iframeWrapperRef.current) {
+ setIframeScale(iframeWrapperRef.current.offsetWidth / 1920);
+ }
+ }, []);
+
+ useEffect(() => {
+ if (!slug) return;
+ updateIframeScale();
+ const observer = new ResizeObserver(updateIframeScale);
+ if (iframeWrapperRef.current) observer.observe(iframeWrapperRef.current);
+ return () => observer.disconnect();
+ }, [slug, updateIframeScale]);
useEffect(() => {
if (isGenerating) {
@@ -61,20 +80,49 @@ export function TemplateCard({
onMouseEnter={() => setHovered(true)}
onMouseLeave={() => setHovered(false)}
onClick={onPreview}>
- {/* Image layer — always present */}
- <img
- src={src}
- alt={name}
- style={{
- display: 'block',
- width: '100%',
- aspectRatio: '1920 / 1205',
- objectFit: 'cover' as const,
- objectPosition: 'top',
- opacity: isGenerating ? 0 : 1,
- transition: 'opacity 600ms ease',
- }}
- />
+ {/* Preview layer — live iframe when slug is provided, static image otherwise */}
+ {slug ? (
+ <div
+ ref={iframeWrapperRef}
+ style={{
+ position: 'relative',
+ width: '100%',
+ aspectRatio: '1920 / 1205',
+ overflow: 'hidden',
+ opacity: isGenerating ? 0 : 1,
+ transition: 'opacity 600ms ease',
+ }}>
+ <iframe
+ src={`${basePath}/templates/${slug}/?embed=1`}
+ title={name}
+ style={{
+ position: 'absolute',
+ top: 0,
+ left: 0,
+ width: 1920,
+ height: 1205,
+ border: 'none',
+ transform: `scale(${iframeScale})`,
+ transformOrigin: 'top left',
+ pointerEvents: 'none',
+ }}
+ />
+ </div>
+ ) : (
+ <img
+ src={src}
+ alt={name}
+ style={{
+ display: 'block',
+ width: '100%',
+ aspectRatio: '1920 / 1205',
+ objectFit: 'cover' as const,
+ objectPosition: 'top',
+ opacity: isGenerating ? 0 : 1,
+ transition: 'opacity 600ms ease',
+ }}
+ />
+ )}
{/* Canvas layer — overlaid, fades in/out */}
{showCanvas && (
<div
diff --git a/apps/sandbox/src/app/(fullscreen)/pages/docsite/TemplatePreview.tsx b/apps/sandbox/src/app/(fullscreen)/pages/docsite/TemplatePreview.tsx
index 08a4e90a90..3c92253330 100644
--- a/apps/sandbox/src/app/(fullscreen)/pages/docsite/TemplatePreview.tsx
+++ b/apps/sandbox/src/app/(fullscreen)/pages/docsite/TemplatePreview.tsx
@@ -26,7 +26,7 @@ import {
import {XDSPopover} from '@xds/core/Popover';
import {SharePopoverContent} from './SharePopover';
-import {XDS_THEMES} from './constants';
+import {XDS_THEMES, basePath} from './constants';
import {CraftingCat} from './CraftingCat';
import type {PointedElement} from './ChatPanel';
@@ -34,6 +34,7 @@ import type {PointedElement} from './ChatPanel';
export function TemplatePreview({
templateName,
imageSrc,
+ slug,
onBack: _onBack,
isGenerating,
onPublish,
@@ -49,6 +50,7 @@ export function TemplatePreview({
}: {
templateName: string;
imageSrc: string;
+ slug?: string;
onBack: () => void;
isGenerating: boolean;
onPublish?: () => void;
@@ -398,7 +400,20 @@ export function TemplatePreview({
margin: isFullPreview ? 0 : 'auto 0',
transition: 'width 300ms ease, border-radius 300ms ease',
}}>
- {imageSrc ? (
+ {slug ? (
+ <iframe
+ src={`${basePath}/templates/${slug}/?embed=1`}
+ title={templateName}
+ style={{
+ display: 'block',
+ width: '100%',
+ height: '100vh',
+ border: 'none',
+ opacity: isGenerating ? 0 : 1,
+ transition: 'opacity 600ms ease',
+ }}
+ />
+ ) : imageSrc ? (
<img
src={imageSrc}
alt="Template preview"
diff --git a/apps/sandbox/src/app/(fullscreen)/pages/docsite/TemplatePreviewModal.tsx b/apps/sandbox/src/app/(fullscreen)/pages/docsite/TemplatePreviewModal.tsx
index 07e854c5af..2540151591 100644
--- a/apps/sandbox/src/app/(fullscreen)/pages/docsite/TemplatePreviewModal.tsx
+++ b/apps/sandbox/src/app/(fullscreen)/pages/docsite/TemplatePreviewModal.tsx
@@ -16,6 +16,7 @@ import {
AVATAR_IMAGE,
XDS_DESIGN_AVATAR,
THEME_PICKER_ENTRIES,
+ basePath,
} from './constants';
import {SharePopoverContent} from './SharePopover';
import {
@@ -71,6 +72,7 @@ const tokenStyles = stylex.create({
export type TemplatePreviewItem = {
name: string;
img: string;
+ slug?: string;
author: string;
description?: string;
};
@@ -179,19 +181,34 @@ export function TemplatePreviewModal({
overflowX: 'hidden',
border: '1px solid var(--color-border, #e0e0e0)',
}}>
- <img
- src={item.img}
- alt={item.name}
- style={{
- width: '100%',
- display: 'block',
- opacity: transitioning ? 0 : 1,
- transition: 'opacity 250ms ease',
- animation: transitioning
- ? 'none'
- : 'previewFadeIn 300ms ease',
- }}
- />
+ {item.slug ? (
+ <iframe
+ src={`${basePath}/templates/${item.slug}/?embed=1`}
+ title={item.name}
+ style={{
+ width: '100%',
+ height: '100%',
+ border: 'none',
+ display: 'block',
+ opacity: transitioning ? 0 : 1,
+ transition: 'opacity 250ms ease',
+ }}
+ />
+ ) : (
+ <img
+ src={item.img}
+ alt={item.name}
+ style={{
+ width: '100%',
+ display: 'block',
+ opacity: transitioning ? 0 : 1,
+ transition: 'opacity 250ms ease',
+ animation: transitioning
+ ? 'none'
+ : 'previewFadeIn 300ms ease',
+ }}
+ />
+ )}
</div>
</XDSVStack>
diff --git a/apps/sandbox/src/app/(fullscreen)/pages/docsite/constants.ts b/apps/sandbox/src/app/(fullscreen)/pages/docsite/constants.ts
index d1daa97d8a..564165dced 100644
--- a/apps/sandbox/src/app/(fullscreen)/pages/docsite/constants.ts
+++ b/apps/sandbox/src/app/(fullscreen)/pages/docsite/constants.ts
@@ -180,6 +180,7 @@ export const NAV_ITEMS: {key: 'craft' | 'explore' | 'docs'; label: string}[] = [
export const TEMPLATES: {
name: string;
src: string;
+ slug?: string;
size: 'xlarge' | 'large' | 'medium' | 'small';
author: string;
isOfficial: boolean;
@@ -188,7 +189,8 @@ export const TEMPLATES: {
{name: 'Shopping Details', src: SHOPPING_DETAILS_IMAGE, size: 'small', author: 'Andrea Anderson', isOfficial: true},
{name: 'Button Component', src: SCREENSHOT_3_IMAGE, size: 'small', author: 'XDS Design', isOfficial: true},
{name: 'Settings Page', src: `${basePath}/templates/card4-preview.png`, size: 'small', author: 'XDS Design', isOfficial: true},
- {name: 'Login Form', src: DUMMY_IMAGE, size: 'xlarge', author: 'Marcus Chen', isOfficial: false},
+ {name: 'Login (SSO)', src: DUMMY_IMAGE, slug: 'login-sso', size: 'large', author: 'XDS Design', isOfficial: true},
+ {name: 'Login (Split)', src: DUMMY_IMAGE, slug: 'login-split', size: 'large', author: 'XDS Design', isOfficial: true},
{name: 'Dashboard', src: DUMMY_IMAGE, size: 'large', author: 'Marcus Chen', isOfficial: false},
{name: 'Data Table', src: DUMMY_IMAGE, size: 'small', author: 'XDS Design', isOfficial: true},
{name: 'File Explorer', src: DUMMY_IMAGE, size: 'small', author: 'Sarah Kim', isOfficial: false},
diff --git a/apps/sandbox/src/app/(fullscreen)/pages/docsite/page.tsx b/apps/sandbox/src/app/(fullscreen)/pages/docsite/page.tsx
index 6057df50b8..ba29b1848c 100644
--- a/apps/sandbox/src/app/(fullscreen)/pages/docsite/page.tsx
+++ b/apps/sandbox/src/app/(fullscreen)/pages/docsite/page.tsx
@@ -727,6 +727,7 @@ function DocsiteLandingTemplate() {
<TemplatePreview
templateName={t.name}
imageSrc={t.src}
+ slug={t.slug}
onBack={handleBackFromUse}
isGenerating={previewGenerating}
onPublish={() => {
@@ -1504,6 +1505,7 @@ function DocsiteLandingTemplate() {
}}>
<TemplateCard
src={template.src}
+ slug={template.slug}
name={template.name}
isSelected={selected.has(template.originalIndex)}
isGenerating={
@@ -1555,6 +1557,7 @@ function DocsiteLandingTemplate() {
item={{
name: t.name,
img: t.src,
+ slug: t.slug,
author: t.author,
}}
onStartCrafting={() => {