An open source design system that's fully customizable and agent ready
TypeScript
fix(SideNav): consistent spacing regardless of header/topContent visibility (#601)
Cindy Zhang6a11d5383e8d
diff --git a/apps/sandbox/src/app/(fullscreen)/pages/shell-lab/page.tsx b/apps/sandbox/src/app/(fullscreen)/pages/shell-lab/page.tsxindex 248f16809d..6549d3795f 100644--- a/apps/sandbox/src/app/(fullscreen)/pages/shell-lab/page.tsx+++ b/apps/sandbox/src/app/(fullscreen)/pages/shell-lab/page.tsx@@ -41,9 +41,10 @@ interface ShellConfig {showSideNav: boolean;showTopNav: boolean;showBanner: boolean;+ showFooter: boolean;showFooterIcons: boolean;showTopContent: boolean;- showSideNavHeading: boolean;+ sideNavHeadingStyle: 'none' | 'simple' | 'link' | 'menu' | 'full';showNestedItems: boolean;defaultCollapsed: boolean;controlledCollapse: boolean;@@ -63,9 +64,10 @@ const DEFAULT_CONFIG: ShellConfig = {showSideNav: true,showTopNav: true,showBanner: false,+ showFooter: false,showFooterIcons: true,showTopContent: true,- showSideNavHeading: true,+ sideNavHeadingStyle: 'link',showNestedItems: true,defaultCollapsed: false,controlledCollapse: false,@@ -107,8 +109,10 @@ function ConfigPanel({})}options={[+ {value: 'section', label: 'Section'},{value: 'wash', label: 'Wash'},{value: 'surface', label: 'Surface'},+ {value: 'elevated', label: 'Elevated'},]}/><SelectorRow@@ -152,16 +156,32 @@ function ConfigPanel({value={config.showTopNav}onChange={v => onChange({showTopNav: v})}/>- <ToggleRow+ <SelectorRowlabel="SideNav Heading"- value={config.showSideNavHeading}- onChange={v => onChange({showSideNavHeading: v})}+ value={config.sideNavHeadingStyle}+ onChange={v =>+ onChange({+ sideNavHeadingStyle: v as ShellConfig['sideNavHeadingStyle'],+ })+ }+ options={[+ {value: 'none', label: 'None'},+ {value: 'simple', label: 'Simple'},+ {value: 'link', label: 'Link'},+ {value: 'menu', label: 'Menu'},+ {value: 'full', label: 'Full'},+ ]}/><ToggleRowlabel="Banner"value={config.showBanner}onChange={v => onChange({showBanner: v})}/>+ <ToggleRow+ label="Footer"+ value={config.showFooter}+ onChange={v => onChange({showFooter: v})}+ /><ToggleRowlabel="Footer Icons"value={config.showFooterIcons}@@ -328,35 +348,74 @@ function SelectorRow({// =============================================================================function SampleSideNav({config}: {config: ShellConfig}) {+ const appIcon = (+ <XDSNavIcon+ icon={+ <svg+ xmlns="http://www.w3.org/2000/svg"+ viewBox="0 0 24 24"+ fill="currentColor"+ width="16"+ height="16">+ <path d="M21 16.5c0 .38-.21.71-.53.88l-7.9 4.44c-.36.2-.8.2-1.14 0l-7.9-4.44A.991.991 0 013 16.5v-9c0-.38.21-.71.53-.88l7.9-4.44c.36-.2.8-.2 1.14 0l7.9 4.44c.32.17.53.5.53.88v9z" />+ </svg>+ }+ />+ );++ const headingMenu = (+ <XDSVStack gap={1}>+ <XDSSideNavItem label="Switch to Project A" />+ <XDSSideNavItem label="Switch to Project B" />+ <XDSSideNavItem label="Switch to Project C" />+ </XDSVStack>+ );++ const heading =+ config.sideNavHeadingStyle === 'none' ? undefined : (+ <XDSSideNavHeading+ icon={appIcon}+ heading="Shell Lab"+ headingHref={+ config.sideNavHeadingStyle === 'link' ||+ config.sideNavHeadingStyle === 'full'+ ? '#'+ : undefined+ }+ superheading={+ config.sideNavHeadingStyle === 'full' ? 'Acme Suite' : undefined+ }+ superheadingHref={+ config.sideNavHeadingStyle === 'full' ? '#' : undefined+ }+ subheading={+ config.sideNavHeadingStyle === 'full' ? 'Business Account' : undefined+ }+ menu={+ config.sideNavHeadingStyle === 'menu' ||+ config.sideNavHeadingStyle === 'full'+ ? headingMenu+ : undefined+ }+ />+ );+return (<XDSSideNav- header={- config.showSideNavHeading ? (- <XDSSideNavHeading- icon={- <XDSNavIcon- icon={- <svg- xmlns="http://www.w3.org/2000/svg"- viewBox="0 0 24 24"- fill="currentColor"- width="16"- height="16">- <path d="M21 16.5c0 .38-.21.71-.53.88l-7.9 4.44c-.36.2-.8.2-1.14 0l-7.9-4.44A.991.991 0 013 16.5v-9c0-.38.21-.71.53-.88l7.9-4.44c.36-.2.8-.2 1.14 0l7.9 4.44c.32.17.53.5.53.88v9z" />- </svg>- }- />- }- heading="Shell Lab"- headingHref="#"- />- ) : undefined- }+ header={heading}topContent={config.showTopContent ? (<XDSSideNavItem label="Create New" />) : undefined}+ footer={+ config.showFooter ? (+ <XDSSideNavSection title="Account">+ <XDSSideNavItem label="Jane Smith" />+ <XDSSideNavItem label="Upgrade to Pro" />+ </XDSSideNavSection>+ ) : undefined+ }footerIcons={config.showFooterIcons ? (<>@@ -664,13 +723,22 @@ export default function ShellLabPage() {{/* Floating config panel */}{showConfig && (- <div {...stylex.props(styles.configOverlay)}>+ <div+ style={{+ position: 'fixed',+ top: 16,+ right: 16,+ width: 360,+ maxHeight: 'calc(100vh - 32px)',+ overflowY: 'auto' as const,+ zIndex: 10000,+ }}><ConfigPanel config={config} onChange={handleConfigChange} /></div>)}{/* Toggle config visibility */}- <div {...stylex.props(styles.toggleButton)}>+ <div style={{position: 'fixed', bottom: 16, right: 16, zIndex: 10001}}><buttononClick={() => setShowConfig(v => !v)}style={{diff --git a/packages/core/src/SideNav/XDSSideNav.tsx b/packages/core/src/SideNav/XDSSideNav.tsxindex f5afcedee7..edcbd81c4d 100644--- a/packages/core/src/SideNav/XDSSideNav.tsx+++ b/packages/core/src/SideNav/XDSSideNav.tsx@@ -44,36 +44,48 @@ const styles = stylex.create({top: 0,zIndex: 1,backgroundColor: 'inherit',- },- topContent: {+ paddingBlockStart: spacingVars['--spacing-2'],+ paddingBlockEnd: spacingVars['--spacing-1'],paddingInline: spacingVars['--spacing-2'],- paddingBlock: spacingVars['--spacing-1'],+ gap: spacingVars['--spacing-2'],},+ topContent: {},scrollable: {flex: 1,overflowY: 'auto',overflowX: 'hidden',paddingInline: spacingVars['--spacing-2'],- paddingBlock: spacingVars['--spacing-1'],+ },+ scrollableNoTop: {+ paddingBlockStart: spacingVars['--spacing-2'],+ },+ scrollableWithTop: {+ paddingBlockStart: spacingVars['--spacing-1'],+ },+ scrollableNoBottom: {+ paddingBlockEnd: spacingVars['--spacing-2'],+ },+ scrollableWithBottom: {+ paddingBlockEnd: spacingVars['--spacing-1'],},stickyBottom: {+ display: 'flex',+ flexDirection: 'column',flexShrink: 0,marginTop: 'auto',position: 'sticky',bottom: 0,backgroundColor: 'inherit',- },- footer: {+ gap: spacingVars['--spacing-2'],paddingInline: spacingVars['--spacing-2'],- paddingBlock: spacingVars['--spacing-2'],+ paddingBlockStart: spacingVars['--spacing-1'],+ paddingBlockEnd: spacingVars['--spacing-2'],+ borderBlockStart: `1px solid ${colorVars['--color-divider']}`,},footerIcons: {display: 'flex',alignItems: 'center',gap: spacingVars['--spacing-1'],- paddingInline: spacingVars['--spacing-2'],- paddingBlock: spacingVars['--spacing-2'],- borderBlockStart: `1px solid ${colorVars['--color-divider']}`,},});@@ -190,10 +202,19 @@ export function XDSSideNav({)}</div>)}- <div {...stylex.props(styles.scrollable)}>{children}</div>+ <div+ {...stylex.props(+ styles.scrollable,+ hasStickyTop ? styles.scrollableWithTop : styles.scrollableNoTop,+ hasStickyBottom+ ? styles.scrollableWithBottom+ : styles.scrollableNoBottom,+ )}>+ {children}+ </div>{hasStickyBottom && (<div {...stylex.props(styles.stickyBottom)}>- {footer && <div {...stylex.props(styles.footer)}>{footer}</div>}+ {footer}{footerIcons && (<div {...stylex.props(styles.footerIcons)}>{footerIcons}</div>)}diff --git a/packages/core/src/SideNav/XDSSideNavHeading.tsx b/packages/core/src/SideNav/XDSSideNavHeading.tsxindex da5e1b56c3..d469f938d5 100644--- a/packages/core/src/SideNav/XDSSideNavHeading.tsx+++ b/packages/core/src/SideNav/XDSSideNavHeading.tsx@@ -32,6 +32,7 @@ import {// of lazy loading layer resources.import {useXDSPopover} from '../Popover/useXDSPopover';import {XDSLink} from '../Link';+import {getIcon} from '../Icon/globalIconRegistry';import {xdsClassName, mergeProps} from '../utils';// =============================================================================@@ -44,7 +45,7 @@ const styles = stylex.create({alignItems: 'center',gap: spacingVars['--spacing-2'],paddingInline: spacingVars['--spacing-2'],- paddingBlock: spacingVars['--spacing-3'],+ paddingBlock: spacingVars['--spacing-2'],boxSizing: 'border-box',textDecoration: 'none',color: 'inherit',@@ -65,10 +66,6 @@ const styles = stylex.create({},},},- interactiveInset: {- marginInline: spacingVars['--spacing-2'],- marginBlock: spacingVars['--spacing-1'],- },icon: {flexShrink: 0,display: 'flex',@@ -116,11 +113,12 @@ const styles = stylex.create({display: 'flex',alignItems: 'center',justifyContent: 'center',- width: spacingVars['--spacing-4'],- height: spacingVars['--spacing-4'],+ minWidth: spacingVars['--spacing-7'],+ minHeight: spacingVars['--spacing-7'],color: colorVars['--color-icon-secondary'],},popoverContent: {+ padding: spacingVars['--spacing-1'],borderRadius: radiusVars['--radius-element'],backgroundColor: colorVars['--color-surface'],boxShadow: `0 4px 12px ${colorVars['--color-shadow-elevation']}`,@@ -202,29 +200,8 @@ export interface XDSSideNavHeadingProps {'data-testid'?: string;}-// =============================================================================-// Chevron SVG// =============================================================================-function ChevronDownIcon() {- return (- <svg- width="16"- height="16"- viewBox="0 0 16 16"- fill="none"- aria-hidden="true">- <path- d="M4 6L8 10L12 6"- stroke="currentColor"- strokeWidth="1.5"- strokeLinecap="round"- strokeLinejoin="round"- />- </svg>- );-}-// =============================================================================// Component// =============================================================================@@ -353,9 +330,7 @@ export function XDSSideNavHeading({);const chevronElement = showChevron && (- <span {...stylex.props(styles.chevron)}>- <ChevronDownIcon />- </span>+ <span {...stylex.props(styles.chevron)}>{getIcon('chevronDown')}</span>);// Whole heading is a link (no menu, single headingHref)@@ -367,12 +342,7 @@ export function XDSSideNavHeading({data-testid={testId}{...mergeProps(xdsClassName('side-nav-heading'),- stylex.props(- styles.root,- styles.interactive,- styles.interactiveInset,- xstyle,- ),+ stylex.props(styles.root, styles.interactive, xstyle),className,style,)}@@ -396,12 +366,7 @@ export function XDSSideNavHeading({{...popover.triggerProps}{...mergeProps(xdsClassName('side-nav-heading'),- stylex.props(- styles.root,- styles.interactive,- styles.interactiveInset,- xstyle,- ),+ stylex.props(styles.root, styles.interactive, xstyle),className,style,)}>@@ -448,7 +413,7 @@ export function XDSSideNavHeading({aria-label="Open menu"{...popover.triggerProps}{...stylex.props(styles.chevron, styles.interactive)}>- <ChevronDownIcon />+ {getIcon('chevronDown')}</button>)}</div>diff --git a/packages/core/src/SideNav/XDSSideNavSection.tsx b/packages/core/src/SideNav/XDSSideNavSection.tsxindex 063f3884de..28d4ece7db 100644--- a/packages/core/src/SideNav/XDSSideNavSection.tsx+++ b/packages/core/src/SideNav/XDSSideNavSection.tsx@@ -77,6 +77,7 @@ const styles = stylex.create({items: {display: 'flex',flexDirection: 'column',+ gap: spacingVars['--spacing-0-5'],},});