Skip to content

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

TypeScript

feat(docsite): Update card component and add search to the Components page (#2384)

Kenton Quatman06d23ac41e71
diff --git a/apps/docsite/src/app/(docs)/components/page.tsx b/apps/docsite/src/app/(docs)/components/page.tsx
index 7670a87e53..ca2166300c 100644
--- a/apps/docsite/src/app/(docs)/components/page.tsx
+++ b/apps/docsite/src/app/(docs)/components/page.tsx
@@ -6,14 +6,15 @@
'use client';
-import {useMemo} from 'react';
+import {useMemo, useState} from 'react';
import * as stylex from '@stylexjs/stylex';
+import {MagnifyingGlassIcon} from '@heroicons/react/24/outline';
import {XDSText} from '@xds/core/Text';
import {XDSVStack} from '@xds/core/Layout';
import {XDSSection} from '@xds/core/Section';
import {XDSGrid} from '@xds/core/Grid';
import {XDSClickableCard} from '@xds/core/ClickableCard';
-import {XDSOverlay} from '@xds/core/Overlay';
+import {XDSTextInput} from '@xds/core/TextInput';
import {blocks} from '../../../generated/blockRegistry';
import {ShowcaseThumbnail} from '../../../components/ShowcaseThumbnail';
@@ -30,18 +31,11 @@ const styles = stylex.create({
backgroundColor: 'var(--color-background-muted)',
borderRadius: 'var(--radius-container)',
},
- overlayInner: {
- display: 'flex',
- flexDirection: 'column' as const,
- justifyContent: 'flex-end',
- alignItems: 'flex-start',
- height: '100%',
- width: '100%',
- padding: 8,
- },
});
export default function ComponentsGalleryPage() {
+ const [query, setQuery] = useState('');
+
const items = useMemo(
() =>
showcases.map(b => ({
@@ -54,9 +48,17 @@ export default function ComponentsGalleryPage() {
[],
);
+ const filteredItems = useMemo(() => {
+ const q = query.trim().toLowerCase();
+ if (!q) {
+ return items;
+ }
+ return items.filter(item => item.name.toLowerCase().includes(q));
+ }, [items, query]);
+
return (
<XDSSection maxWidth="xl" padding={6}>
- <XDSVStack gap={6}>
+ <XDSVStack gap={8}>
<XDSVStack gap={2} style={{alignItems: 'center'}}>
<XDSText type="display-2" xstyle={styles.heroTitle}>
Browse the library
@@ -67,35 +69,24 @@ export default function ComponentsGalleryPage() {
</XDSText>
</XDSVStack>
- <XDSGrid columns={{minWidth: 300, repeat: 'fill'}} gap={4}>
- {items.map(item => (
- <XDSClickableCard
- key={item.slug}
- label={item.name}
- href={item.href}
- variant="transparent"
- padding={0}>
- <XDSOverlay
- showOn="hover"
- scrim="dark"
- content={
- <div {...stylex.props(styles.overlayInner)}>
- <XDSVStack gap={0.5}>
- <XDSText
- type="body"
- weight="bold"
- style={{color: '#fff'}}>
- {item.name}
- </XDSText>
- <XDSText
- type="supporting"
- style={{color: 'rgba(255,255,255,0.7)'}}>
- {item.description.slice(0, 80)}
- {item.description.length > 80 ? '\u2026' : ''}
- </XDSText>
- </XDSVStack>
- </div>
- }>
+ <XDSTextInput
+ label="Search components"
+ isLabelHidden
+ value={query}
+ onChange={setQuery}
+ placeholder="Search components…"
+ startIcon={MagnifyingGlassIcon}
+ hasClear
+ />
+
+ <XDSGrid columns={{minWidth: 300, repeat: 'fill'}} gap={4} rowGap={6}>
+ {filteredItems.map(item => (
+ <XDSVStack key={item.slug} gap={2}>
+ <XDSClickableCard
+ label={item.name}
+ href={item.href}
+ padding={0}
+ variant="transparent">
{item.category ? (
<ShowcaseThumbnail
dirName={item.slug}
@@ -104,8 +95,9 @@ export default function ComponentsGalleryPage() {
) : (
<div {...stylex.props(styles.cardImage)} />
)}
- </XDSOverlay>
- </XDSClickableCard>
+ </XDSClickableCard>
+ <XDSText>{item.name}</XDSText>
+ </XDSVStack>
))}
</XDSGrid>
</XDSVStack>
diff --git a/apps/docsite/src/app/providers.tsx b/apps/docsite/src/app/providers.tsx
index bed7909496..272dee6d75 100644
--- a/apps/docsite/src/app/providers.tsx
+++ b/apps/docsite/src/app/providers.tsx
@@ -2,15 +2,36 @@
'use client';
+import {createContext, useContext, useState} from 'react';
import Link from 'next/link';
import {XDSTheme} from '@xds/core/theme';
import {XDSLinkProvider} from '@xds/core/Link';
import {defaultTheme} from '@xds/theme-default/built';
+type ThemeMode = 'light' | 'dark';
+
+const ThemeModeContext = createContext<{
+ mode: ThemeMode;
+ toggleMode: () => void;
+}>({
+ mode: 'light',
+ toggleMode: () => {},
+});
+
+export function useThemeMode() {
+ return useContext(ThemeModeContext);
+}
+
export function Providers({children}: {children: React.ReactNode}) {
+ const [mode, setMode] = useState<ThemeMode>('light');
+
+ const toggleMode = () => setMode(m => (m === 'light' ? 'dark' : 'light'));
+
return (
- <XDSTheme theme={defaultTheme}>
- <XDSLinkProvider component={Link}>{children}</XDSLinkProvider>
- </XDSTheme>
+ <ThemeModeContext value={{mode, toggleMode}}>
+ <XDSTheme theme={defaultTheme} mode={mode}>
+ <XDSLinkProvider component={Link}>{children}</XDSLinkProvider>
+ </XDSTheme>
+ </ThemeModeContext>
);
}
diff --git a/apps/docsite/src/components/SharedTopNav.tsx b/apps/docsite/src/components/SharedTopNav.tsx
index 5d4e712870..8e1f4e2629 100644
--- a/apps/docsite/src/components/SharedTopNav.tsx
+++ b/apps/docsite/src/components/SharedTopNav.tsx
@@ -7,7 +7,12 @@ import {usePathname} from 'next/navigation';
import {XDSTopNav, XDSTopNavHeading, XDSTopNavItem} from '@xds/core/TopNav';
import {XDSButton} from '@xds/core/Button';
import {XDSHStack} from '@xds/core/Layout';
-import {MagnifyingGlassIcon, HeartIcon} from '@heroicons/react/24/outline';
+import {
+ MagnifyingGlassIcon,
+ HeartIcon,
+ SunIcon,
+ MoonIcon,
+} from '@heroicons/react/24/outline';
import {GITHUB_REPO} from '../constants';
import {XDS_WORDMARK} from './XDSWordmark';
import {SearchPalette} from './SearchPalette';
@@ -15,6 +20,7 @@ import {components} from '../generated/componentRegistry';
import {packages} from '../generated/packageRegistry';
import {docTopics} from '../generated/docsRegistry';
import {templates} from '../generated/templateRegistry';
+import {useThemeMode} from '../app/providers';
const GitHubIcon = ({
width = 20,
@@ -36,6 +42,7 @@ const GitHubIcon = ({
export function SharedTopNav() {
const [isSearchOpen, setIsSearchOpen] = useState(false);
const pathname = usePathname();
+ const {mode, toggleMode} = useThemeMode();
// Determine active nav item
const getActiveItem = () => {
@@ -97,32 +104,50 @@ export function SharedTopNav() {
</>
}
endContent={
- <XDSHStack gap={0.5}>
- <XDSButton
- label="Search"
- variant="ghost"
- isIconOnly
- icon={<MagnifyingGlassIcon width={20} height={20} />}
- onClick={() => setIsSearchOpen(true)}
- />
- <XDSButton
- label="Community"
- variant="ghost"
- isIconOnly
- icon={<HeartIcon width={20} height={20} />}
- href="/community"
- />
- <XDSButton
- label="GitHub"
- variant="ghost"
- isIconOnly
- icon={<GitHubIcon />}
- href={GITHUB_REPO}
- />
+ <XDSHStack gap={2}>
+ <XDSHStack gap={0.5}>
+ <XDSButton
+ label="Search"
+ variant="ghost"
+ isIconOnly
+ icon={<MagnifyingGlassIcon width={20} height={20} />}
+ onClick={() => setIsSearchOpen(true)}
+ />
+ <XDSButton
+ label={
+ mode === 'light'
+ ? 'Switch to dark mode'
+ : 'Switch to light mode'
+ }
+ variant="ghost"
+ isIconOnly
+ icon={
+ mode === 'light' ? (
+ <MoonIcon width={20} height={20} />
+ ) : (
+ <SunIcon width={20} height={20} />
+ )
+ }
+ onClick={toggleMode}
+ />
+ <XDSButton
+ label="Community"
+ variant="ghost"
+ isIconOnly
+ icon={<HeartIcon width={20} height={20} />}
+ href="/community"
+ />
+ <XDSButton
+ label="GitHub"
+ variant="ghost"
+ isIconOnly
+ icon={<GitHubIcon />}
+ href={GITHUB_REPO}
+ />
+ </XDSHStack>
<XDSButton
label="Get started"
variant="primary"
- size="sm"
href="/docs/getting-started"
/>
</XDSHStack>