An open source design system that's fully customizable and agent ready
TypeScript
refactor(templates): settings-sidebar — reduce CSS, responsive drill-down, fill height (grade 90→97) (#2628)
rubyycheung72ba77982e91
diff --git a/packages/cli/templates/pages/settings-sidebar/page.tsx b/packages/cli/templates/pages/settings-sidebar/page.tsxindex 088b3640a2..7856b53308 100644--- a/packages/cli/templates/pages/settings-sidebar/page.tsx+++ b/packages/cli/templates/pages/settings-sidebar/page.tsx@@ -3,6 +3,7 @@'use client';import {useState} from 'react';+import {useMediaQuery} from '@xds/core/hooks';import * as stylex from '@stylexjs/stylex';import {XDSVStack,@@ -13,6 +14,7 @@ import {XDSLayoutPanel,} from '@xds/core/Layout';import {XDSList, XDSListItem} from '@xds/core/List';+import {XDSToolbar} from '@xds/core/Toolbar';import {XDSText, XDSHeading} from '@xds/core/Text';import {XDSLink} from '@xds/core/Link';import {XDSButton} from '@xds/core/Button';@@ -43,9 +45,17 @@ import {ComputerDesktopIcon,PencilSquareIcon,ShareIcon,+ ArrowLeftIcon,+ ChevronRightIcon,} from '@heroicons/react/24/outline';const styles = stylex.create({+ // Anchor the page to the viewport height so the sidebar + content fill the+ // screen. XDSLayout height="fill" is min-height:100% which collapses when the+ // host container is content-sized; XDSLayout has no viewport-height prop.+ fillViewport: {+ minHeight: '100dvh',+ },iconBox: {borderRadius: radiusVars['--radius-container'],backgroundColor: colorVars['--color-background-surface'],@@ -54,9 +64,6 @@ const styles = stylex.create({rowPadding: {paddingBlock: spacingVars['--spacing-4'],},- cardContentPadding: {- paddingInline: spacingVars['--spacing-4'],- },sideNavPadding: {paddingBlock: spacingVars['--spacing-4'],paddingInline: spacingVars['--spacing-3'],@@ -77,6 +84,15 @@ const NAV_ITEMS = [{label: 'Travel for work', icon: BriefcaseIcon},];+// Section title shown beside the mobile back button (matches each section's+// in-content heading, which is hidden on mobile to avoid a duplicate).+const SECTION_TITLES: Record<string, string> = {+ 'Personal information': 'Personal info',+ 'Login & security': 'Login & security',+ Privacy: 'Privacy',+ 'Languages & currency': 'Languages & currency',+};+interface InfoRow {label: string;value: string;@@ -213,6 +229,10 @@ const TIMEZONES = [];export default function SettingsSecurityTemplate() {+ const isNarrow = useMediaQuery('(max-width: 768px)');+ // Mobile is a master→detail drill-down: 'nav' shows the menu, 'detail' shows+ // the selected section with a back button. Desktop shows both side-by-side.+ const [mobileView, setMobileView] = useState<'nav' | 'detail'>('nav');const [activeNav, setActiveNav] = useState('Personal information');const [activeTab, setActiveTab] = useState('login');const [readReceipts, setReadReceipts] = useState(true);@@ -236,44 +256,100 @@ export default function SettingsSecurityTemplate() {const [mailingAddress, setMailingAddress] = useState('');const [emergencyContact, setEmergencyContact] = useState('Provided');+ // Selecting a nav item also drills into the detail view on mobile.+ const selectNav = (label: string) => {+ setActiveNav(label);+ setMobileView('detail');+ };++ const navList = (+ <XDSVStack gap={4} xstyle={styles.sideNavPadding}>+ <XDSHeading level={2} xstyle={styles.sideNavHeading}>+ Account settings+ </XDSHeading>+ <XDSList density="spacious">+ {NAV_ITEMS.map(item => (+ <XDSListItem+ key={item.label}+ label={item.label}+ startContent={<XDSIcon icon={item.icon} />}+ endContent={+ isNarrow ? (+ <XDSIcon icon={ChevronRightIcon} size="sm" color="secondary" />+ ) : undefined+ }+ isSelected={!isNarrow && activeNav === item.label}+ onClick={() => selectNav(item.label)}+ />+ ))}+ </XDSList>+ <XDSDivider />+ <XDSList density="spacious">+ <XDSListItem+ label="Professional hosting tools"+ startContent={<XDSIcon icon={WrenchScrewdriverIcon} />}+ onClick={() => {}}+ />+ </XDSList>+ </XDSVStack>+ );++ // Mobile, nav view: show only the menu (full width, no sidebar slot).+ if (isNarrow && mobileView === 'nav') {+ return (+ <XDSLayout+ height="fill"+ xstyle={styles.fillViewport}+ content={<XDSLayoutContent padding={2}>{navList}</XDSLayoutContent>}+ />+ );+ }+return (<XDSLayoutheight="fill"- contentWidth={700}+ contentWidth={1200}+ xstyle={styles.fillViewport}start={- <XDSLayoutPanel hasDivider padding={0}>- <XDSVStack gap={4} xstyle={styles.sideNavPadding}>- <XDSHeading level={2} xstyle={styles.sideNavHeading}>- Account settings- </XDSHeading>- <XDSList density="spacious">- {NAV_ITEMS.map(item => (- <XDSListItem- key={item.label}- label={item.label}- startContent={<XDSIcon icon={item.icon} />}- isSelected={activeNav === item.label}- onClick={() => setActiveNav(item.label)}- />- ))}- </XDSList>- <XDSDivider />- <XDSList density="spacious">- <XDSListItem- label="Professional hosting tools"- startContent={<XDSIcon icon={WrenchScrewdriverIcon} />}- onClick={() => {}}- />- </XDSList>- </XDSVStack>- </XDSLayoutPanel>+ isNarrow ? undefined : (+ <XDSLayoutPanel hasDivider padding={0}>+ {navList}+ </XDSLayoutPanel>+ )}content={<XDSLayoutContent padding={4}><XDSVStack gap={0}>+ {/* Mobile detail view: a back button sits beside the section title+ (the per-section headings below are hidden on mobile). Toolbar's+ start slot edge-compensates the ghost button so its icon aligns+ flush with the content edge. */}+ {isNarrow && (+ <XDSToolbar+ label={`Back to Account settings — ${SECTION_TITLES[activeNav]}`}+ gap={2}+ startContent={+ <>+ <XDSButton+ label="Back to Account settings"+ variant="ghost"+ size="sm"+ isIconOnly+ icon={<XDSIcon icon={ArrowLeftIcon} size="sm" />}+ onClick={() => setMobileView('nav')}+ />+ <XDSHeading level={2}>+ {SECTION_TITLES[activeNav]}+ </XDSHeading>+ </>+ }+ />+ )}{activeNav === 'Login & security' && (<XDSVStack gap={6}>- <XDSHeading level={2}>Login & security</XDSHeading>+ {!isNarrow && (+ <XDSHeading level={2}>Login & security</XDSHeading>+ )}<XDSTabListvalue={activeTab}@@ -406,7 +482,9 @@ export default function SettingsSecurityTemplate() {{activeNav === 'Languages & currency' && (<XDSVStack gap={6}>- <XDSHeading level={2}>Languages & currency</XDSHeading>+ {!isNarrow && (+ <XDSHeading level={2}>Languages & currency</XDSHeading>+ )}<XDSVStack gap={0}><ExpandableRowlabel="Preferred language"@@ -471,7 +549,7 @@ export default function SettingsSecurityTemplate() {{activeNav === 'Personal information' && (<XDSVStack gap={6}>- <XDSHeading level={2}>Personal info</XDSHeading>+ {!isNarrow && <XDSHeading level={2}>Personal info</XDSHeading>}<XDSVStack gap={0}><ExpandableRowlabel="Legal name"@@ -578,12 +656,9 @@ export default function SettingsSecurityTemplate() {</ExpandableRow></XDSVStack>- <XDSCard padding={0}>- <XDSVStack gap={0} xstyle={styles.cardContentPadding}>- <XDSHStack- gap={3}- vAlign="start"- xstyle={styles.rowPadding}>+ <XDSCard padding={4}>+ <XDSVStack gap={4}>+ <XDSHStack gap={3} vAlign="start"><XDSCenter width={48} height={48} xstyle={styles.iconBox}><XDSIcon icon={LockClosedIcon} /></XDSCenter>@@ -601,10 +676,7 @@ export default function SettingsSecurityTemplate() {</XDSVStack></XDSHStack><XDSDivider />- <XDSHStack- gap={3}- vAlign="start"- xstyle={styles.rowPadding}>+ <XDSHStack gap={3} vAlign="start"><XDSCenter width={48} height={48} xstyle={styles.iconBox}><XDSIcon icon={PencilSquareIcon} /></XDSCenter>@@ -624,10 +696,7 @@ export default function SettingsSecurityTemplate() {</XDSVStack></XDSHStack><XDSDivider />- <XDSHStack- gap={3}- vAlign="start"- xstyle={styles.rowPadding}>+ <XDSHStack gap={3} vAlign="start"><XDSCenter width={48} height={48} xstyle={styles.iconBox}><XDSIcon icon={ShareIcon} /></XDSCenter>@@ -651,7 +720,7 @@ export default function SettingsSecurityTemplate() {{activeNav === 'Privacy' && (<XDSVStack gap={6}>- <XDSHeading level={2}>Privacy</XDSHeading>+ {!isNarrow && <XDSHeading level={2}>Privacy</XDSHeading>}<XDSVStack gap={8}><XDSVStack gap={0}>