An open source design system that's fully customizable and agent ready
TypeScript
Component page cleanup (#2411)
Kenton Quatmanfaad8d907aed
diff --git a/apps/docsite/src/app/(docs)/components/page.tsx b/apps/docsite/src/app/(docs)/components/page.tsxindex ca2166300c..abdc1f361b 100644--- a/apps/docsite/src/app/(docs)/components/page.tsx+++ b/apps/docsite/src/app/(docs)/components/page.tsx@@ -6,15 +6,13 @@'use client';-import {useMemo, useState} from 'react';+import {useMemo} 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 {XDSTextInput} from '@xds/core/TextInput';import {blocks} from '../../../generated/blockRegistry';import {ShowcaseThumbnail} from '../../../components/ShowcaseThumbnail';@@ -34,8 +32,6 @@ const styles = stylex.create({});export default function ComponentsGalleryPage() {- const [query, setQuery] = useState('');-const items = useMemo(() =>showcases.map(b => ({@@ -48,14 +44,6 @@ 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={8}>@@ -69,18 +57,8 @@ export default function ComponentsGalleryPage() {</XDSText></XDSVStack>- <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 => (+ {items.map(item => (<XDSVStack key={item.slug} gap={2}><XDSClickableCardlabel={item.name}diff --git a/apps/docsite/src/components/DocsShell.tsx b/apps/docsite/src/components/DocsShell.tsxindex a5d7f6804d..76893f9265 100644--- a/apps/docsite/src/components/DocsShell.tsx+++ b/apps/docsite/src/components/DocsShell.tsx@@ -2,15 +2,21 @@'use client';+import {useState, useMemo} from 'react';import {usePathname} from 'next/navigation';+import {MagnifyingGlassIcon} from '@heroicons/react/24/outline';import {XDSAppShell} from '@xds/core/AppShell';import {XDSSideNav, XDSSideNavItem, XDSSideNavSection} from '@xds/core/SideNav';+import {XDSTextInput} from '@xds/core/TextInput';import {SharedTopNav} from './SharedTopNav';import type {ComponentEntry} from '../generated/componentRegistry';import type {PackageMeta} from '../generated/packageRegistry';import type {DocTopic} from '../generated/docsRegistry';import type {TemplateEntry} from '../generated/templateRegistry';-import type {ComponentItem} from '../generated/groupedComponentRegistry';+import type {+ ComponentItem,+ GroupedEntry,+} from '../generated/groupedComponentRegistry';import {groupedComponents} from '../generated/groupedComponentRegistry';interface DocsShellProps {@@ -59,9 +65,40 @@ export function DocsShell({defaultIsMobile,}: DocsShellProps) {const pathname = usePathname();+ const [componentQuery, setComponentQuery] = useState('');const {componentItems, utilities} = buildComponentSidebar();+ const q = componentQuery.trim().toLowerCase();++ // When searching, flatten groups to individual entries so results are+ // all at the same level with no nesting.+ const flatSearchResults = useMemo<GroupedEntry[]>(() => {+ if (!q) {return [];}+ return componentItems.flatMap(item => {+ if (item.type === 'entry') {+ return item.displayName.toLowerCase().includes(q) ? [item] : [];+ }+ return item.entries+ .filter(e => e.displayName.toLowerCase().includes(q))+ .map(e => ({+ type: 'entry' as const,+ name: e.name,+ displayName: e.displayName,+ href: e.href,+ description: '',+ }));+ });+ }, [componentItems, q]);++ const filteredUtilities = useMemo(+ () =>+ q+ ? utilities.filter(u => u.displayName.toLowerCase().includes(q))+ : utilities,+ [utilities, q],+ );+// Classify packagesconst isTheme = (p: PackageMeta) => p.name.includes('theme-');const themePackages = packages.filter(isTheme);@@ -192,65 +229,92 @@ export function DocsShell({</>)}- {/* Components — rendered as a flat list directly under the section- (no redundant "Components" parent wrapper). The first item is- an Overview link back to the /components gallery so users on- a detail page can return to the index. Sub-grouped items like- Avatar / Button keep their own collapsible behavior for their- nested entries. */}- <XDSSideNavSection title="Components" isHeaderHidden>- <XDSSideNavItem- label="Overview"- href="/components"- isSelected={pathname === '/components'}- />- {componentItems.map(item =>- item.type === 'entry' ? (- <XDSSideNavItem- key={item.name}- label={item.displayName}- href={item.href}- isSelected={pathname === item.href}+ {/* Components — only shown on /components routes */}+ {isOnComponentsRoute && (+ <>+ <XDSSideNavSection title="Components" isHeaderHidden>+ <XDSTextInput+ label="Search components"+ isLabelHidden+ value={componentQuery}+ onChange={setComponentQuery}+ placeholder="Search components…"+ startIcon={MagnifyingGlassIcon}+ hasClear+ style={{marginBottom: 'var(--spacing-3)'}}/>- ) : (- <XDSSideNavItem- key={item.label}- label={item.displayName}- collapsible={{- defaultIsCollapsed: !item.entries.some(- e => pathname === e.href,- ),- }}>- {item.entries.map(entry => (- <XDSSideNavItem- key={entry.name}- label={entry.displayName}- href={entry.href}- isSelected={pathname === entry.href}- />- ))}- </XDSSideNavItem>- ),- )}- </XDSSideNavSection>-- {/* Utilities — secondary list rendered below the main Components- section. Always starts collapsed; users can expand on demand. */}- {utilities.length > 0 && (- <XDSSideNavSection title="Utilities" isHeaderHidden>- <XDSSideNavItem- label="Utilities"- collapsible={{defaultIsCollapsed: true}}>- {utilities.map(comp => (+ {!q && (<XDSSideNavItem- key={comp.name}- label={comp.displayName}- href={comp.href}- isSelected={pathname === comp.href}+ label="Overview"+ href="/components"+ isSelected={pathname === '/components'}/>- ))}- </XDSSideNavItem>- </XDSSideNavSection>+ )}+ {q+ ? flatSearchResults.map(item => (+ <XDSSideNavItem+ key={item.name}+ label={item.displayName}+ href={item.href}+ isSelected={pathname === item.href}+ />+ ))+ : componentItems.map(item =>+ item.type === 'entry' ? (+ <XDSSideNavItem+ key={item.name}+ label={item.displayName}+ href={item.href}+ isSelected={pathname === item.href}+ />+ ) : (+ <XDSSideNavItem+ key={item.label}+ label={item.displayName}+ collapsible={{+ defaultIsCollapsed: !item.entries.some(+ e => pathname === e.href,+ ),+ }}>+ {item.entries.map(entry => (+ <XDSSideNavItem+ key={entry.name}+ label={entry.displayName}+ href={entry.href}+ isSelected={pathname === entry.href}+ />+ ))}+ </XDSSideNavItem>+ ),+ )}+ {/* Utilities — secondary list rendered below the main Components+ section. Always starts collapsed; users can expand on demand. */}+ {filteredUtilities.length > 0 &&+ (q ? (+ filteredUtilities.map(comp => (+ <XDSSideNavItem+ key={comp.name}+ label={comp.displayName}+ href={comp.href}+ isSelected={pathname === comp.href}+ />+ ))+ ) : (+ <XDSSideNavItem+ label="Utilities"+ collapsible={{defaultIsCollapsed: true}}>+ {utilities.map(comp => (+ <XDSSideNavItem+ key={comp.name}+ label={comp.displayName}+ href={comp.href}+ isSelected={pathname === comp.href}+ />+ ))}+ </XDSSideNavItem>+ ))}+ </XDSSideNavSection>+ </>)}</XDSSideNav>}>diff --git a/apps/docsite/src/components/component-detail/ComponentDetailClient.tsx b/apps/docsite/src/components/component-detail/ComponentDetailClient.tsxindex 28b2913750..149f74b8a6 100644--- a/apps/docsite/src/components/component-detail/ComponentDetailClient.tsx+++ b/apps/docsite/src/components/component-detail/ComponentDetailClient.tsx@@ -130,7 +130,7 @@ function ComponentDetailInner({style={{marginInline: 'auto'}}><XDSVStack gap={4}><XDSVStack gap={2}>- <XDSText type="display-1">{comp.name}</XDSText>+ <XDSText type="display-1">{comp.displayName}</XDSText><XDSText type="supporting" color="secondary">{pkg}{pkgVersion ? ` v${pkgVersion}` : ''} · {comp.moduleName}diff --git a/packages/core/src/SelectableCard/SelectableCard.doc.mjs b/packages/core/src/SelectableCard/SelectableCard.doc.mjsindex 1d81c26d32..00ab7065c4 100644--- a/packages/core/src/SelectableCard/SelectableCard.doc.mjs+++ b/packages/core/src/SelectableCard/SelectableCard.doc.mjs@@ -4,6 +4,7 @@export const docs = {name: 'SelectableCard',displayName: 'Selectable Card',+ group: 'Card',keywords: ['card', 'selectable', 'toggle', 'checkbox', 'radio', 'selection'],usage: {description: 'A card that toggles between selected and unselected states with an accent border. For navigation use ClickableCard.',