An open source design system that's fully customizable and agent ready
TypeScript
feat(sandbox): apply library design to sandbox landing page (#1409)
Kenton Quatmane55d6dff2b28
diff --git a/apps/sandbox/src/app/(sandbox)/[category]/CategoryContent.tsx b/apps/sandbox/src/app/(sandbox)/[category]/CategoryContent.tsxindex 527b9a0b76..92ea95327b 100644--- a/apps/sandbox/src/app/(sandbox)/[category]/CategoryContent.tsx+++ b/apps/sandbox/src/app/(sandbox)/[category]/CategoryContent.tsx@@ -1,41 +1,94 @@'use client';+import {useState, useMemo} from 'react';+import * as stylex from '@stylexjs/stylex';import {XDSHeading, XDSText} from '@xds/core/Text';+import {XDSLayout, XDSLayoutHeader, XDSLayoutContent} from '@xds/core/Layout';+import {XDSTextInput} from '@xds/core/TextInput';+import {XDSGrid} from '@xds/core/Grid';+import {XDSVStack} from '@xds/core/Stack';+import {spacingVars} from '@xds/core/theme/tokens.stylex';import {categories} from '../../sandboxPages';import {ProjectCard} from '../../ProjectCard';+import {SearchIcon} from '../../icons';++const styles = stylex.create({+ emptyState: {+ padding: spacingVars['--spacing-12'],+ textAlign: 'center',+ },+});export function CategoryContent({slug}: {slug: string}) {const category = categories.find(c => c.slug === slug);+ const [search, setSearch] = useState('');++ const filtered = useMemo(() => {+ if (!category) return [];+ if (!search.trim()) return category.pages;+ const q = search.toLowerCase();+ return category.pages.filter(+ p =>+ p.name.toLowerCase().includes(q) ||+ p.description.toLowerCase().includes(q),+ );+ }, [category, search]);if (!category) {return (- <div>- <XDSHeading level={1}>Not Found</XDSHeading>- <XDSText type="body" color="secondary">- Category "{slug}" doesn't exist.- </XDSText>- </div>+ <XDSLayout+ header={+ <XDSLayoutHeader hasDivider padding={6}>+ <XDSHeading level={1}>Not Found</XDSHeading>+ </XDSLayoutHeader>+ }+ content={+ <XDSLayoutContent padding={6}>+ <XDSText type="body" color="secondary">+ Category "{slug}" doesn't exist.+ </XDSText>+ </XDSLayoutContent>+ }+ />);}return (- <div style={{display: 'flex', flexDirection: 'column', gap: 24}}>- <div style={{display: 'flex', flexDirection: 'column', gap: 4}}>- <XDSHeading level={1}>{category.label}</XDSHeading>- <XDSText type="body" color="secondary">- {category.description}- </XDSText>- </div>- <div- style={{- display: 'grid',- gridTemplateColumns: 'repeat(4, 1fr)',- gap: 20,- }}>- {category.pages.map(page => (- <ProjectCard key={page.href} page={page} />- ))}- </div>- </div>+ <XDSLayout+ header={+ <XDSLayoutHeader hasDivider padding={6}>+ <XDSHeading level={1}>{category.label}</XDSHeading>+ </XDSLayoutHeader>+ }+ content={+ <XDSLayoutContent padding={6}>+ <XDSVStack gap={6}>+ <XDSTextInput+ label="Search"+ isLabelHidden+ placeholder="Search..."+ value={search}+ onChange={setSearch}+ startIcon={SearchIcon}+ size="lg"+ />++ {filtered.length === 0 ? (+ <div {...stylex.props(styles.emptyState)}>+ <XDSText type="supporting" color="secondary">+ No results found.+ </XDSText>+ </div>+ ) : (+ <XDSGrid minChildWidth={280} gap={4}>+ {filtered.map(page => (+ <ProjectCard key={page.href} page={page} />+ ))}+ </XDSGrid>+ )}+ </XDSVStack>+ </XDSLayoutContent>+ }+ />);}diff --git a/apps/sandbox/src/app/(sandbox)/page.tsx b/apps/sandbox/src/app/(sandbox)/page.tsxindex e026a94438..66ebdfdfea 100644--- a/apps/sandbox/src/app/(sandbox)/page.tsx+++ b/apps/sandbox/src/app/(sandbox)/page.tsx@@ -1,46 +1,155 @@'use client';+import {useState, useMemo} from 'react';+import * as stylex from '@stylexjs/stylex';import {XDSText, XDSHeading} from '@xds/core/Text';+import {XDSLayout, XDSLayoutHeader, XDSLayoutContent} from '@xds/core/Layout';+import {XDSTextInput} from '@xds/core/TextInput';+import {XDSToggleButton, XDSToggleButtonGroup} from '@xds/core/ToggleButton';+import {XDSDropdownMenu} from '@xds/core/DropdownMenu';+import {XDSGrid} from '@xds/core/Grid';+import {XDSHStack, XDSVStack} from '@xds/core/Stack';+import {XDSDivider} from '@xds/core/Divider';+import {spacingVars} from '@xds/core/theme/tokens.stylex';import {categories} from '../sandboxPages';import {ProjectCard} from '../ProjectCard';+import {SearchIcon} from '../icons';++const CATEGORY_FILTERS = ['All', ...categories.map(c => c.label)];++const allPages = categories.flatMap(c =>+ c.pages.map(p => ({...p, category: c.label})),+);++const styles = stylex.create({+ emptyState: {+ padding: spacingVars['--spacing-12'],+ textAlign: 'center',+ },+ hideOnSmall: {+ display: {+ default: 'none',+ '@media (min-width: 840px)': 'block',+ },+ },+ hideOnLarge: {+ display: {+ default: 'block',+ '@media (min-width: 840px)': 'none',+ },+ },+});export default function Home() {+ const [activeTab, setActiveTab] = useState('All');+ const [search, setSearch] = useState('');++ const filtered = useMemo(() => {+ let items =+ activeTab === 'All'+ ? allPages+ : allPages.filter(p => p.category === activeTab);+ if (search.trim()) {+ const q = search.toLowerCase();+ items = items.filter(+ p =>+ p.name.toLowerCase().includes(q) ||+ p.description.toLowerCase().includes(q),+ );+ }+ return items;+ }, [activeTab, search]);++ const groupedSections = useMemo(() => {+ if (activeTab !== 'All') return null;+ const map = new Map<string, typeof allPages>();+ for (const page of filtered) {+ if (!map.has(page.category)) map.set(page.category, []);+ map.get(page.category)!.push(page);+ }+ return categories+ .filter(c => map.has(c.label))+ .map(c => ({category: c.label, pages: map.get(c.label)!}));+ }, [activeTab, filtered]);+return (- <div style={{display: 'flex', flexDirection: 'column', gap: 40}}>- <div style={{display: 'flex', flexDirection: 'column', gap: 8}}>- <XDSHeading level={1}>XDS Sandbox</XDSHeading>- <XDSText type="body" color="secondary">- A testing ground for XDS components. Explore tools and templates- below, or create new pages under{' '}- <XDSText type="body" weight="bold">- src/app/pages/- </XDSText>- .- </XDSText>- </div>-- {categories.map(category => (- <div- key={category.slug}- style={{display: 'flex', flexDirection: 'column', gap: 16}}>- <div style={{display: 'flex', flexDirection: 'column', gap: 4}}>- <XDSHeading level={2}>{category.label}</XDSHeading>- <XDSText type="body" color="secondary">- {category.description}- </XDSText>- </div>- <div- style={{- display: 'grid',- gridTemplateColumns: 'repeat(4, 1fr)',- gap: 20,- }}>- {category.pages.map(page => (- <ProjectCard key={page.href} page={page} />- ))}- </div>- </div>- ))}- </div>+ <XDSLayout+ header={+ <XDSLayoutHeader hasDivider padding={6}>+ <XDSHeading level={1}>XDS Sandbox</XDSHeading>+ </XDSLayoutHeader>+ }+ content={+ <XDSLayoutContent padding={6}>+ <XDSVStack gap={6}>+ <XDSVStack gap={4}>+ <XDSTextInput+ label="Search"+ isLabelHidden+ placeholder="Search..."+ value={search}+ onChange={setSearch}+ startIcon={SearchIcon}+ size="lg"+ />+ <XDSHStack vAlign="center" hAlign="between">+ <div {...stylex.props(styles.hideOnSmall)}>+ <XDSToggleButtonGroup+ label="Filter by category"+ value={activeTab}+ onChange={v => setActiveTab(v ?? 'All')}>+ {CATEGORY_FILTERS.map(cat => (+ <XDSToggleButton+ key={cat}+ label={cat}+ value={cat}+ size="lg"+ />+ ))}+ </XDSToggleButtonGroup>+ </div>+ <div {...stylex.props(styles.hideOnLarge)}>+ <XDSDropdownMenu+ button={{label: activeTab, size: 'lg'}}+ items={CATEGORY_FILTERS.map(cat => ({+ label: cat,+ onClick: () => setActiveTab(cat),+ }))}+ />+ </div>+ </XDSHStack>+ </XDSVStack>++ {filtered.length === 0 ? (+ <div {...stylex.props(styles.emptyState)}>+ <XDSText type="supporting" color="secondary">+ No results found.+ </XDSText>+ </div>+ ) : groupedSections != null ? (+ <XDSVStack gap={6}>+ {groupedSections.flatMap(section => [+ <XDSDivider key={`d-${section.category}`} />,+ <XDSVStack gap={6} key={section.category}>+ <XDSHeading level={2}>{section.category}</XDSHeading>+ <XDSGrid minChildWidth={280} gap={4}>+ {section.pages.map(page => (+ <ProjectCard key={page.href} page={page} />+ ))}+ </XDSGrid>+ </XDSVStack>,+ ])}+ </XDSVStack>+ ) : (+ <XDSGrid minChildWidth={280} gap={4}>+ {filtered.map(page => (+ <ProjectCard key={page.href} page={page} />+ ))}+ </XDSGrid>+ )}+ </XDSVStack>+ </XDSLayoutContent>+ }+ />);}diff --git a/apps/sandbox/src/app/ProjectCard.tsx b/apps/sandbox/src/app/ProjectCard.tsxindex adbd5bfa8b..25a1c48d31 100644--- a/apps/sandbox/src/app/ProjectCard.tsx+++ b/apps/sandbox/src/app/ProjectCard.tsx@@ -1,16 +1,11 @@'use client';-import {useState} from 'react';import Link from 'next/link';import {XDSText} from '@xds/core/Text';import type {SandboxPage} from './sandboxPages';import {ImageIcon} from './icons';-const basePath = process.env.NEXT_PUBLIC_BASE_PATH || '';-export function ProjectCard({page}: {page: SandboxPage}) {- const [iframeError, setIframeError] = useState(false);-return (<Linkhref={page.href}@@ -31,32 +26,18 @@ export function ProjectCard({page}: {page: SandboxPage}) {height: 160,backgroundColor: 'var(--color-background-body)',overflow: 'hidden',- position: 'relative',+ display: 'flex',+ alignItems: 'center',+ justifyContent: 'center',}}>- {iframeError ? (- <div style={{display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%'}}>- <ImageIcon style={{width: 48, height: 48, opacity: 0.3, color: 'var(--color-text-disabled)'}} />- </div>- ) : (- <iframe- src={`${basePath}${page.href}`}- title={page.name}- onError={() => setIframeError(true)}- style={{- width: 1280,- height: 800,- border: 'none',- transform: 'scale(0.2)',- transformOrigin: 'top left',- position: 'absolute',- top: 0,- left: 0,- pointerEvents: 'none',- }}- tabIndex={-1}- loading="lazy"- />- )}+ <ImageIcon+ style={{+ width: 48,+ height: 48,+ opacity: 0.3,+ color: 'var(--color-text-disabled)',+ }}+ /></div><divstyle={{diff --git a/apps/sandbox/src/app/SandboxShell.tsx b/apps/sandbox/src/app/SandboxShell.tsxindex 1bb5463a67..6337f542b5 100644--- a/apps/sandbox/src/app/SandboxShell.tsx+++ b/apps/sandbox/src/app/SandboxShell.tsx@@ -5,7 +5,7 @@ import {SandboxNav} from './SandboxNav';export function SandboxShell({children}: {children: React.ReactNode}) {return (- <XDSAppShell sideNav={<SandboxNav />} contentPadding={4}>+ <XDSAppShell sideNav={<SandboxNav />} contentPadding={0}>{children}</XDSAppShell>);diff --git a/apps/sandbox/src/app/icons.tsx b/apps/sandbox/src/app/icons.tsxindex d22fc01a0e..98fa5eedea 100644--- a/apps/sandbox/src/app/icons.tsx+++ b/apps/sandbox/src/app/icons.tsx@@ -156,3 +156,17 @@ export const AppWindowIcon = (props: IconProps) => (<path d="M6 4v4" /></svg>);++export const SearchIcon = (props: IconProps) => (+ <svg+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth={2}+ strokeLinecap="round"+ strokeLinejoin="round"+ {...props}>+ <circle cx="11" cy="11" r="8" />+ <line x1="21" y1="21" x2="16.65" y2="16.65" />+ </svg>+);