An open source design system that's fully customizable and agent ready
TypeScript
XDSTopNav (#107)
Andrey Goder3a8433600dad
diff --git a/apps/storybook/stories/TopNav.stories.tsx b/apps/storybook/stories/TopNav.stories.tsxnew file mode 100644index 0000000000..bb79e3eb51--- /dev/null+++ b/apps/storybook/stories/TopNav.stories.tsx@@ -0,0 +1,253 @@+import type {Meta, StoryObj} from '@storybook/react';+import {+ XDSTopNav,+ XDSTopNavTitle,+ XDSTopNavTitleIcon,+ XDSTopNavItem,+} from '@xds/core/TopNav';+import {XDSButton} from '@xds/core/Button';+import {+ HomeIcon,+ Cog6ToothIcon,+ MagnifyingGlassIcon,+ BellIcon,+ UserCircleIcon,+ CubeIcon,+ DocumentTextIcon,+ ChartBarIcon,+} from '@heroicons/react/24/outline';++const meta: Meta<typeof XDSTopNav> = {+ title: 'Core/XDSTopNav',+ component: XDSTopNav,+ tags: ['autodocs'],+ parameters: {+ layout: 'fullscreen',+ },+ argTypes: {+ position: {+ control: 'select',+ options: ['static', 'sticky', 'fixed'],+ description: 'Position behavior',+ },+ label: {+ control: 'text',+ description: 'Accessible label for navigation landmark',+ },+ },+};++export default meta;+type Story = StoryObj<typeof XDSTopNav>;++export const Default: Story = {+ args: {+ label: 'Main navigation',+ title: <XDSTopNavTitle title="My App" />,+ startContent: (+ <>+ <XDSTopNavItem label="Home" href="#" isSelected />+ <XDSTopNavItem label="Products" href="#" />+ <XDSTopNavItem label="About" href="#" />+ </>+ ),+ endContent: (+ <>+ <XDSButton+ label="Search"+ variant="ghost"+ icon={<MagnifyingGlassIcon style={{width: 16, height: 16}} />}+ />+ <XDSButton+ label="Notifications"+ variant="ghost"+ icon={<BellIcon style={{width: 16, height: 16}} />}+ />+ <XDSButton+ label="Profile"+ variant="ghost"+ icon={<UserCircleIcon style={{width: 16, height: 16}} />}+ />+ </>+ ),+ },+};++export const WithLogo: Story = {+ args: {+ label: 'Main navigation',+ title: (+ <XDSTopNavTitle+ title="Dashboard"+ logo={+ <XDSTopNavTitleIcon+ icon={<CubeIcon style={{width: 16, height: 16}} />}+ />+ }+ href="#"+ />+ ),+ startContent: (+ <>+ <XDSTopNavItem label="Overview" href="#" isSelected />+ <XDSTopNavItem label="Analytics" href="#" />+ <XDSTopNavItem label="Reports" href="#" />+ </>+ ),+ endContent: (+ <XDSButton+ label="Profile"+ variant="ghost"+ icon={<UserCircleIcon style={{width: 16, height: 16}} />}+ />+ ),+ },+};++export const TitleOnly: Story = {+ args: {+ label: 'Main navigation',+ title: (+ <XDSTopNavTitle+ title="Simple App"+ logo={+ <XDSTopNavTitleIcon+ icon={<HomeIcon style={{width: 16, height: 16}} />}+ size="sm"+ />+ }+ />+ ),+ endContent: <XDSButton label="Sign in" variant="primary" />,+ },+};++export const NavItemStates: Story = {+ render: () => (+ <XDSTopNav+ label="Navigation states demo"+ title={<XDSTopNavTitle title="States" />}+ startContent={+ <>+ <XDSTopNavItem label="Selected" href="#" isSelected />+ <XDSTopNavItem label="Default" href="#" />+ <XDSTopNavItem label="Disabled" href="#" isDisabled />+ <XDSTopNavItem+ label="With Icon"+ href="#"+ icon={<Cog6ToothIcon style={{width: 16, height: 16}} />}+ />+ </>+ }+ />+ ),+};++export const TitleIconSizes: Story = {+ render: () => (+ <div style={{display: 'flex', flexDirection: 'column', gap: 16}}>+ <XDSTopNav+ label="Small icon"+ title={+ <XDSTopNavTitle+ title="Small"+ logo={+ <XDSTopNavTitleIcon+ icon={<CubeIcon style={{width: 14, height: 14}} />}+ size="sm"+ />+ }+ />+ }+ />+ <XDSTopNav+ label="Medium icon"+ title={+ <XDSTopNavTitle+ title="Medium"+ logo={+ <XDSTopNavTitleIcon+ icon={<CubeIcon style={{width: 16, height: 16}} />}+ size="md"+ />+ }+ />+ }+ />+ <XDSTopNav+ label="Large icon"+ title={+ <XDSTopNavTitle+ title="Large"+ logo={+ <XDSTopNavTitleIcon+ icon={<CubeIcon style={{width: 18, height: 18}} />}+ size="lg"+ />+ }+ />+ }+ />+ </div>+ ),+};++export const FullExample: Story = {+ render: () => (+ <XDSTopNav+ label="Main navigation"+ position="sticky"+ title={+ <XDSTopNavTitle+ title="Enterprise Dashboard"+ logo={+ <XDSTopNavTitleIcon+ icon={<ChartBarIcon style={{width: 16, height: 16}} />}+ />+ }+ href="#"+ />+ }+ startContent={+ <>+ <XDSTopNavItem+ label="Dashboard"+ href="#"+ isSelected+ icon={<HomeIcon style={{width: 16, height: 16}} />}+ />+ <XDSTopNavItem+ label="Reports"+ href="#"+ icon={<DocumentTextIcon style={{width: 16, height: 16}} />}+ />+ <XDSTopNavItem+ label="Analytics"+ href="#"+ icon={<ChartBarIcon style={{width: 16, height: 16}} />}+ />+ <XDSTopNavItem+ label="Settings"+ href="#"+ icon={<Cog6ToothIcon style={{width: 16, height: 16}} />}+ />+ </>+ }+ endContent={+ <>+ <XDSButton+ label="Search"+ variant="ghost"+ icon={<MagnifyingGlassIcon style={{width: 16, height: 16}} />}+ />+ <XDSButton+ label="Notifications"+ variant="ghost"+ icon={<BellIcon style={{width: 16, height: 16}} />}+ />+ <XDSButton label="Upgrade" variant="primary" />+ </>+ }+ />+ ),+};diff --git a/packages/core/src/TopNav/README.md b/packages/core/src/TopNav/README.mdnew file mode 100644index 0000000000..112fce043f--- /dev/null+++ b/packages/core/src/TopNav/README.md@@ -0,0 +1,131 @@+# /packages/core/src/TopNav++Top navigation bar component for application headers.++<!-- SYNC: When files in this directory change, update this document. -->++## Features++- **Slot-based layout**: `title`, `startContent`, `endContent` for flexible organization+- **Position modes**: Static, sticky, or fixed positioning+- **Companion components**: XDSTopNavTitle, XDSTopNavTitleIcon, XDSTopNavItem+- **Accessible**: Proper ARIA roles and keyboard navigation+- **Themeable**: Uses XDS design tokens for styling++## Usage++```tsx+import {+ XDSTopNav,+ XDSTopNavTitle,+ XDSTopNavTitleIcon,+ XDSTopNavItem,+} from '@xds/core/TopNav';+import {XDSButton} from '@xds/core/Button';+import {HomeIcon, BellIcon, UserCircleIcon} from '@heroicons/react/24/outline';++<XDSTopNav+ label="Main navigation"+ position="sticky"+ title={+ <XDSTopNavTitle+ title="My App"+ logo={+ <XDSTopNavTitleIcon+ icon={<HomeIcon style={{width: 16, height: 16}} />}+ />+ }+ href="/"+ />+ }+ startContent={+ <>+ <XDSTopNavItem label="Dashboard" href="/dashboard" isSelected />+ <XDSTopNavItem label="Products" href="/products" />+ <XDSTopNavItem label="Reports" href="/reports" />+ </>+ }+ endContent={+ <>+ <XDSButton+ label="Notifications"+ variant="ghost"+ icon={<BellIcon style={{width: 16, height: 16}} />}+ />+ <XDSButton+ label="Profile"+ variant="ghost"+ icon={<UserCircleIcon style={{width: 16, height: 16}} />}+ />+ </>+ }+/>;+```++## Props++### XDSTopNav++| Prop | Type | Default | Description |+| -------------- | --------------------------------- | ---------- | ----------------------------------------------------- |+| `title` | `ReactNode` | — | Title slot (logo, brand) - left aligned |+| `startContent` | `ReactNode` | — | Start content (nav items, breadcrumbs) - left aligned |+| `endContent` | `ReactNode` | — | End content (search, icons, profile) - right aligned |+| `position` | `'static' \| 'sticky' \| 'fixed'` | `'static'` | Position behavior |+| `label` | `string` | — | Accessible label for navigation landmark |++### XDSTopNavTitle++| Prop | Type | Default | Description |+| ------- | ----------- | ------- | ---------------------------------------- |+| `title` | `string` | — | Title text to display |+| `logo` | `ReactNode` | — | Logo element (image, XDSTopNavTitleIcon) |+| `href` | `string` | — | URL to navigate to when clicked |++### XDSTopNavTitleIcon++| Prop | Type | Default | Description |+| ------ | ---------------------- | ------- | -------------------------- |+| `icon` | `ReactNode` | — | Icon element (required) |+| `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | Size of circular container |++### XDSTopNavItem++| Prop | Type | Default | Description |+| ------------ | ----------- | ------- | ------------------------------- |+| `label` | `string` | — | Accessible label (required) |+| `href` | `string` | — | Navigation target URL |+| `isSelected` | `boolean` | `false` | Selected/highlighted state |+| `isDisabled` | `boolean` | `false` | Disabled state |+| `icon` | `ReactNode` | — | Optional icon element |+| `children` | `ReactNode` | — | Custom content instead of label |++## Files++| File | Role | Purpose |+| ------------------------ | ----- | ---------------------------- |+| `index.ts` | Entry | Exports components and types |+| `XDSTopNav.tsx` | Core | Main navigation container |+| `XDSTopNavTitle.tsx` | Core | Title with logo and text |+| `XDSTopNavTitleIcon.tsx` | Core | Circular icon container |+| `XDSTopNavItem.tsx` | Core | Navigation link item |+| `XDSTopNav.test.tsx` | Test | Unit tests |++## Layout Structure++```+┌─────────────────────────────────────────────────────────────┐+│ [title] [startContent ...] [...endContent] │+│ └─ left aligned ─────────────────────────── right aligned ─┤+└─────────────────────────────────────────────────────────────┘+```++## Implementation Notes++- XDSTopNav uses `role="navigation"` and accepts `aria-label` via the `label` prop+- Title and startContent are in a flex container that grows to push endContent right+- XDSTopNavItem supports `aria-current="page"` when `isSelected` is true+- XDSTopNavTitleIcon uses `--color-accent` background with `--color-icon-on-media` for contrast+- Default height is 48px with 16px horizontal padding+- Always displays a bottom divider using `--color-divider` token+- Uses `--color-navbar` token for background (defaults to white)diff --git a/packages/core/src/TopNav/XDSTopNav.test.tsx b/packages/core/src/TopNav/XDSTopNav.test.tsxnew file mode 100644index 0000000000..04f90898c6--- /dev/null+++ b/packages/core/src/TopNav/XDSTopNav.test.tsx@@ -0,0 +1,219 @@+/**+ * @file XDSTopNav.test.tsx+ * @input Uses vitest, @testing-library/react, TopNav components+ * @output Unit tests for XDSTopNav component suite+ * @position Testing; validates TopNav implementations+ *+ * SYNC: When TopNav components change, update tests to match new behavior+ */++import {describe, it, expect, vi} from 'vitest';+import {render, screen} from '@testing-library/react';+import userEvent from '@testing-library/user-event';+import {XDSTopNav} from './XDSTopNav';+import {XDSTopNavTitle} from './XDSTopNavTitle';+import {XDSTopNavTitleIcon} from './XDSTopNavTitleIcon';+import {XDSTopNavItem} from './XDSTopNavItem';++describe('XDSTopNav', () => {+ it('renders with navigation role', () => {+ render(<XDSTopNav label="Main navigation" />);+ expect(screen.getByRole('navigation')).toBeInTheDocument();+ });++ it('renders aria-label from label prop', () => {+ render(<XDSTopNav label="Primary navigation" />);+ expect(screen.getByRole('navigation')).toHaveAttribute(+ 'aria-label',+ 'Primary navigation',+ );+ });++ it('renders title slot content', () => {+ render(<XDSTopNav title={<span data-testid="title-content">Logo</span>} />);+ expect(screen.getByTestId('title-content')).toBeInTheDocument();+ });++ it('renders startContent slot', () => {+ render(+ <XDSTopNav+ startContent={<span data-testid="start-content">Nav Items</span>}+ />,+ );+ expect(screen.getByTestId('start-content')).toBeInTheDocument();+ });++ it('renders endContent slot', () => {+ render(+ <XDSTopNav endContent={<span data-testid="end-content">Actions</span>} />,+ );+ expect(screen.getByTestId('end-content')).toBeInTheDocument();+ });++ it('renders all slots together', () => {+ render(+ <XDSTopNav+ title={<span data-testid="title">Title</span>}+ startContent={<span data-testid="start">Start</span>}+ endContent={<span data-testid="end">End</span>}+ />,+ );+ expect(screen.getByTestId('title')).toBeInTheDocument();+ expect(screen.getByTestId('start')).toBeInTheDocument();+ expect(screen.getByTestId('end')).toBeInTheDocument();+ });++ it('forwards ref correctly', () => {+ const ref = vi.fn();+ render(<XDSTopNav ref={ref} />);+ expect(ref).toHaveBeenCalledWith(expect.any(HTMLElement));+ });+});++describe('XDSTopNavTitle', () => {+ it('renders title text', () => {+ render(<XDSTopNavTitle title="My App" />);+ expect(screen.getByText('My App')).toBeInTheDocument();+ });++ it('renders logo element', () => {+ render(<XDSTopNavTitle logo={<span data-testid="logo">Logo</span>} />);+ expect(screen.getByTestId('logo')).toBeInTheDocument();+ });++ it('renders both logo and title', () => {+ render(+ <XDSTopNavTitle+ title="Dashboard"+ logo={<span data-testid="logo">Logo</span>}+ />,+ );+ expect(screen.getByText('Dashboard')).toBeInTheDocument();+ expect(screen.getByTestId('logo')).toBeInTheDocument();+ });++ it('renders as anchor when href is provided', () => {+ render(<XDSTopNavTitle title="Home" href="/" />);+ const link = screen.getByRole('link');+ expect(link).toHaveAttribute('href', '/');+ });++ it('renders as div when no href', () => {+ render(<XDSTopNavTitle title="Home" />);+ expect(screen.queryByRole('link')).not.toBeInTheDocument();+ });++ it('forwards ref correctly', () => {+ const ref = vi.fn();+ render(<XDSTopNavTitle title="Test" ref={ref} />);+ expect(ref).toHaveBeenCalledWith(expect.any(HTMLElement));+ });+});++describe('XDSTopNavTitleIcon', () => {+ it('renders icon content', () => {+ render(<XDSTopNavTitleIcon icon={<span data-testid="icon">Icon</span>} />);+ expect(screen.getByTestId('icon')).toBeInTheDocument();+ });++ it('renders with different sizes', () => {+ const {rerender} = render(+ <XDSTopNavTitleIcon+ icon={<span>Icon</span>}+ size="sm"+ data-testid="icon-wrapper"+ />,+ );+ expect(screen.getByTestId('icon-wrapper')).toBeInTheDocument();++ rerender(+ <XDSTopNavTitleIcon+ icon={<span>Icon</span>}+ size="md"+ data-testid="icon-wrapper"+ />,+ );+ expect(screen.getByTestId('icon-wrapper')).toBeInTheDocument();++ rerender(+ <XDSTopNavTitleIcon+ icon={<span>Icon</span>}+ size="lg"+ data-testid="icon-wrapper"+ />,+ );+ expect(screen.getByTestId('icon-wrapper')).toBeInTheDocument();+ });++ it('forwards ref correctly', () => {+ const ref = vi.fn();+ render(<XDSTopNavTitleIcon icon={<span>Icon</span>} ref={ref} />);+ expect(ref).toHaveBeenCalledWith(expect.any(HTMLSpanElement));+ });+});++describe('XDSTopNavItem', () => {+ it('renders label as visible text', () => {+ render(<XDSTopNavItem label="Home" />);+ expect(screen.getByText('Home')).toBeInTheDocument();+ });++ it('renders as anchor element', () => {+ render(<XDSTopNavItem label="Home" href="/" />);+ const link = screen.getByRole('link', {name: 'Home'});+ expect(link).toHaveAttribute('href', '/');+ });++ it('renders children instead of label when provided', () => {+ render(+ <XDSTopNavItem label="Accessible name">Custom content</XDSTopNavItem>,+ );+ expect(screen.getByText('Custom content')).toBeInTheDocument();+ });++ it('applies aria-current when isSelected', () => {+ render(<XDSTopNavItem label="Home" href="#" isSelected />);+ expect(screen.getByRole('link')).toHaveAttribute('aria-current', 'page');+ });++ it('does not have aria-current when not selected', () => {+ render(<XDSTopNavItem label="Home" href="#" />);+ expect(screen.getByRole('link')).not.toHaveAttribute('aria-current');+ });++ it('applies aria-disabled when isDisabled', () => {+ render(<XDSTopNavItem label="Home" href="#" isDisabled />);+ expect(screen.getByRole('link')).toHaveAttribute('aria-disabled', 'true');+ });++ it('sets tabIndex to -1 when disabled', () => {+ render(<XDSTopNavItem label="Home" href="#" isDisabled />);+ expect(screen.getByRole('link')).toHaveAttribute('tabIndex', '-1');+ });++ it('renders icon with label', () => {+ render(+ <XDSTopNavItem+ label="Settings"+ icon={<span data-testid="icon">Icon</span>}+ />,+ );+ expect(screen.getByTestId('icon')).toBeInTheDocument();+ expect(screen.getByText('Settings')).toBeInTheDocument();+ });++ it('handles click events', async () => {+ const user = userEvent.setup();+ const handleClick = vi.fn();+ render(<XDSTopNavItem label="Click me" href="#" onClick={handleClick} />);++ await user.click(screen.getByRole('link'));+ expect(handleClick).toHaveBeenCalledTimes(1);+ });++ it('forwards ref correctly', () => {+ const ref = vi.fn();+ render(<XDSTopNavItem label="Test" ref={ref} />);+ expect(ref).toHaveBeenCalledWith(expect.any(HTMLAnchorElement));+ });+});diff --git a/packages/core/src/TopNav/XDSTopNav.tsx b/packages/core/src/TopNav/XDSTopNav.tsxnew file mode 100644index 0000000000..187d4eb541--- /dev/null+++ b/packages/core/src/TopNav/XDSTopNav.tsx@@ -0,0 +1,160 @@+/**+ * @file XDSTopNav.tsx+ * @input Uses React forwardRef, HTMLAttributes, ReactNode+ * @output Exports XDSTopNav component and XDSTopNavProps+ * @position Core implementation; consumed by index.ts+ *+ * SYNC: When modified, update these files to stay in sync:+ * - /packages/core/src/TopNav/README.md+ * - /packages/core/src/TopNav/XDSTopNav.test.tsx+ * - /packages/core/src/TopNav/index.ts+ * - /apps/storybook/stories/TopNav.stories.tsx+ */++import {forwardRef, type HTMLAttributes, type ReactNode} from 'react';+import * as stylex from '@stylexjs/stylex';+import {colorVars, spacingVars} from '../theme/tokens.stylex';++/**+ * Base TopNav styles+ */+const styles = stylex.create({+ base: {+ display: 'flex',+ alignItems: 'center',+ width: '100%',+ height: '48px',+ paddingInline: spacingVars['--spacing-4'],+ backgroundColor: colorVars['--color-navbar'],+ borderBlockEnd: `1px solid ${colorVars['--color-divider']}`,+ boxSizing: 'border-box',+ },+ sticky: {+ position: 'sticky',+ top: 0,+ zIndex: 100,+ },+ fixed: {+ position: 'fixed',+ top: 0,+ left: 0,+ right: 0,+ zIndex: 100,+ },+ leftSection: {+ display: 'flex',+ alignItems: 'center',+ gap: spacingVars['--spacing-4'],+ flex: '1 1 auto',+ },+ title: {+ display: 'flex',+ alignItems: 'center',+ flexShrink: 0,+ },+ startContent: {+ display: 'flex',+ alignItems: 'center',+ gap: spacingVars['--spacing-1'],+ },+ endContent: {+ display: 'flex',+ alignItems: 'center',+ gap: spacingVars['--spacing-2'],+ flexShrink: 0,+ marginInlineStart: 'auto',+ },+});++export interface XDSTopNavProps extends Omit<+ HTMLAttributes<HTMLElement>,+ 'style' | 'className' | 'title'+> {+ /**+ * Title slot content - typically XDSTopNavTitle with logo and text.+ * Positioned at the left edge of the nav bar.+ */+ title?: ReactNode;+ /**+ * Start content slot - typically navigation items or breadcrumbs.+ * Positioned after the title, left-aligned.+ */+ startContent?: ReactNode;+ /**+ * End content slot - typically search, icons, user profile, utility menus.+ * Positioned at the right edge of the nav bar.+ */+ endContent?: ReactNode;+ /**+ * Position behavior of the nav bar.+ * - `static`: Normal document flow (default)+ * - `sticky`: Sticks to top on scroll+ * - `fixed`: Fixed to viewport top+ * @default 'static'+ */+ position?: 'static' | 'sticky' | 'fixed';+ /**+ * Accessible label for the navigation landmark.+ * Helps screen readers identify the navigation area.+ */+ label?: string;+}++/**+ * Top navigation bar component for application headers.+ *+ * Uses a slot-based API with `title`, `startContent`, and `endContent` props+ * for flexible layout. Title and startContent are left-aligned, endContent+ * is right-aligned.+ *+ * @example+ * ```tsx+ * <XDSTopNav+ * label="Main navigation"+ * title={<XDSTopNavTitle title="My App" logo={<Logo />} />}+ * startContent={+ * <>+ * <XDSTopNavItem label="Home" href="/" isSelected />+ * <XDSTopNavItem label="Products" href="/products" />+ * </>+ * }+ * endContent={+ * <>+ * <XDSButton label="Search" icon={<SearchIcon />} variant="ghost" />+ * <Avatar />+ * </>+ * }+ * />+ * ```+ */+export const XDSTopNav = forwardRef<HTMLElement, XDSTopNavProps>(+ function XDSTopNav(+ {title, startContent, endContent, position = 'static', label, ...props},+ ref,+ ) {+ return (+ <nav+ ref={ref}+ role="navigation"+ aria-label={label}+ {...stylex.props(+ styles.base,+ position === 'sticky' && styles.sticky,+ position === 'fixed' && styles.fixed,+ )}+ {...props}>+ <div {...stylex.props(styles.leftSection)}>+ {title && <div {...stylex.props(styles.title)}>{title}</div>}+ {startContent && (+ <div {...stylex.props(styles.startContent)}>{startContent}</div>+ )}+ </div>+ {endContent && (+ <div {...stylex.props(styles.endContent)}>{endContent}</div>+ )}+ </nav>+ );+ },+);++XDSTopNav.displayName = 'XDSTopNav';diff --git a/packages/core/src/TopNav/XDSTopNavItem.tsx b/packages/core/src/TopNav/XDSTopNavItem.tsxnew file mode 100644index 0000000000..a6a0a5ea56--- /dev/null+++ b/packages/core/src/TopNav/XDSTopNavItem.tsx@@ -0,0 +1,157 @@+/**+ * @file XDSTopNavItem.tsx+ * @input Uses React forwardRef, AnchorHTMLAttributes, ReactNode+ * @output Exports XDSTopNavItem component and XDSTopNavItemProps+ * @position Navigation item component for XDSTopNav startContent+ *+ * SYNC: When modified, update these files to stay in sync:+ * - /packages/core/src/TopNav/README.md+ * - /packages/core/src/TopNav/XDSTopNav.test.tsx+ * - /packages/core/src/TopNav/index.ts+ * - /apps/storybook/stories/TopNav.stories.tsx+ */++import {forwardRef, type AnchorHTMLAttributes, type ReactNode} from 'react';+import * as stylex from '@stylexjs/stylex';+import {+ colorVars,+ spacingVars,+ radiusVars,+ transitionVars,+ textSizeVars,+ fontWeightVars,+ lineHeightVars,+} from '../theme/tokens.stylex';++/**+ * NavItem styles with hover/selected states+ */+const styles = stylex.create({+ base: {+ display: 'inline-flex',+ alignItems: 'center',+ gap: spacingVars['--spacing-2'],+ paddingBlock: spacingVars['--spacing-2'],+ paddingInline: spacingVars['--spacing-3'],+ borderRadius: radiusVars['--radius-element'],+ fontSize: textSizeVars['--text-base'],+ lineHeight: lineHeightVars['--leading-base'],+ fontWeight: fontWeightVars['--font-weight-medium'],+ color: colorVars['--color-text-secondary'],+ textDecoration: 'none',+ cursor: 'pointer',+ transitionProperty: 'background-color, color',+ transitionDuration: transitionVars['--transition-fast'],+ backgroundColor: {+ default: 'transparent',+ ':hover': colorVars['--color-hover-overlay'],+ ':active': colorVars['--color-pressed-overlay'],+ },+ outline: {+ default: null,+ ':focus-visible': `2px solid ${colorVars['--color-focus-outline']}`,+ },+ outlineOffset: {+ default: '0',+ ':focus-visible': '2px',+ },+ },+ selected: {+ color: colorVars['--color-accent-text'],+ fontWeight: fontWeightVars['--font-weight-semibold'],+ backgroundColor: {+ default: colorVars['--color-accent-deemphasized'],+ ':hover': colorVars['--color-accent-deemphasized'],+ ':active': colorVars['--color-accent-deemphasized'],+ },+ },+ disabled: {+ color: colorVars['--color-text-disabled'],+ cursor: 'not-allowed',+ pointerEvents: 'none',+ },+ iconOnly: {+ paddingInline: spacingVars['--spacing-2'],+ },+});++export interface XDSTopNavItemProps extends Omit<+ AnchorHTMLAttributes<HTMLAnchorElement>,+ 'style' | 'className'+> {+ /**+ * The accessible label for the nav item.+ * Used as visible text, or as aria-label for icon-only items.+ */+ label: string;+ /**+ * Whether this nav item is currently selected/highlighted.+ * @default false+ */+ isSelected?: boolean;+ /**+ * Whether the nav item is disabled.+ * @default false+ */+ isDisabled?: boolean;+ /**+ * Optional icon to display before the label.+ * If provided without children, item becomes icon-only.+ */+ icon?: ReactNode;+ /**+ * Optional content to render instead of the label.+ * If omitted and icon is provided, item becomes icon-only.+ */+ children?: ReactNode;+}++/**+ * A navigation item for use within XDSTopNav startContent.+ *+ * Renders as an anchor element with hover/selected states.+ * Supports icons and selected state indication with highlighted appearance.+ *+ * @example+ * ```tsx+ * <XDSTopNav+ * startContent={+ * <>+ * <XDSTopNavItem label="Home" href="/" isSelected />+ * <XDSTopNavItem label="Products" href="/products" />+ * <XDSTopNavItem label="Settings" href="/settings" icon={<GearIcon />} />+ * </>+ * }+ * />+ * ```+ */+export const XDSTopNavItem = forwardRef<HTMLAnchorElement, XDSTopNavItemProps>(+ function XDSTopNavItem(+ {label, isSelected = false, isDisabled = false, icon, children, ...props},+ ref,+ ) {+ const isIconOnly = icon != null && children == null && !label;+ const showLabel = !isIconOnly;++ return (+ <a+ ref={ref}+ aria-label={isIconOnly ? label : undefined}+ aria-current={isSelected ? 'page' : undefined}+ aria-disabled={isDisabled || undefined}+ tabIndex={isDisabled ? -1 : undefined}+ {...stylex.props(+ styles.base,+ isSelected && styles.selected,+ isDisabled && styles.disabled,+ isIconOnly && styles.iconOnly,+ )}+ {...props}>+ {icon}+ {showLabel && (children ?? label)}+ </a>+ );+ },+);++XDSTopNavItem.displayName = 'XDSTopNavItem';diff --git a/packages/core/src/TopNav/XDSTopNavTitle.tsx b/packages/core/src/TopNav/XDSTopNavTitle.tsxnew file mode 100644index 0000000000..6b92acac8f--- /dev/null+++ b/packages/core/src/TopNav/XDSTopNavTitle.tsx@@ -0,0 +1,114 @@+/**+ * @file XDSTopNavTitle.tsx+ * @input Uses React forwardRef, HTMLAttributes, ReactNode+ * @output Exports XDSTopNavTitle component and XDSTopNavTitleProps+ * @position Companion component for XDSTopNav title slot+ *+ * SYNC: When modified, update these files to stay in sync:+ * - /packages/core/src/TopNav/README.md+ * - /packages/core/src/TopNav/XDSTopNav.test.tsx+ * - /packages/core/src/TopNav/index.ts+ * - /apps/storybook/stories/TopNav.stories.tsx+ */++import {forwardRef, type HTMLAttributes, type ReactNode} from 'react';+import * as stylex from '@stylexjs/stylex';+import {+ colorVars,+ spacingVars,+ textSizeVars,+ fontWeightVars,+ lineHeightVars,+} from '../theme/tokens.stylex';++/**+ * Title styles+ */+const styles = stylex.create({+ base: {+ display: 'flex',+ alignItems: 'center',+ gap: spacingVars['--spacing-2'],+ textDecoration: 'none',+ color: colorVars['--color-text-primary'],+ },+ titleText: {+ fontSize: textSizeVars['--text-lg'],+ fontWeight: fontWeightVars['--font-weight-semibold'],+ lineHeight: lineHeightVars['--leading-tight'],+ whiteSpace: 'nowrap',+ },+ logo: {+ display: 'flex',+ alignItems: 'center',+ justifyContent: 'center',+ flexShrink: 0,+ },+ clickable: {+ cursor: 'pointer',+ },+});++export interface XDSTopNavTitleProps extends Omit<+ HTMLAttributes<HTMLElement>,+ 'style' | 'className' | 'title'+> {+ /**+ * The title text to display.+ */+ title?: string;+ /**+ * Logo element to display before the title.+ * Can be an image, XDSTopNavTitleIcon, or any ReactNode.+ */+ logo?: ReactNode;+ /**+ * URL to navigate to when the title is clicked.+ * If provided, renders as an anchor element.+ */+ href?: string;+}++/**+ * Title component for XDSTopNav.+ *+ * Displays a logo and/or title text, optionally as a clickable link.+ * Use with XDSTopNavTitleIcon to create a circular icon background.+ *+ * @example+ * ```tsx+ * // Logo with text+ * <XDSTopNavTitle+ * title="My App"+ * logo={<img src="/logo.svg" alt="" width={24} height={24} />}+ * href="/"+ * />+ *+ * // With circular icon+ * <XDSTopNavTitle+ * title="Dashboard"+ * logo={<XDSTopNavTitleIcon icon={<HomeIcon />} />}+ * />+ *+ * // Logo only+ * <XDSTopNavTitle logo={<BrandLogo />} href="/" />+ * ```+ */+export const XDSTopNavTitle = forwardRef<HTMLElement, XDSTopNavTitleProps>(+ function XDSTopNavTitle({title, logo, href, ...props}, ref) {+ const Element = href ? 'a' : 'div';++ return (+ <Element+ ref={ref as React.Ref<HTMLAnchorElement & HTMLDivElement>}+ href={href}+ {...stylex.props(styles.base, href != null && styles.clickable)}+ {...props}>+ {logo && <span {...stylex.props(styles.logo)}>{logo}</span>}+ {title && <span {...stylex.props(styles.titleText)}>{title}</span>}+ </Element>+ );+ },+);++XDSTopNavTitle.displayName = 'XDSTopNavTitle';diff --git a/packages/core/src/TopNav/XDSTopNavTitleIcon.tsx b/packages/core/src/TopNav/XDSTopNavTitleIcon.tsxnew file mode 100644index 0000000000..c6847579d6--- /dev/null+++ b/packages/core/src/TopNav/XDSTopNavTitleIcon.tsx@@ -0,0 +1,97 @@+/**+ * @file XDSTopNavTitleIcon.tsx+ * @input Uses React forwardRef, HTMLAttributes, ReactNode+ * @output Exports XDSTopNavTitleIcon component and XDSTopNavTitleIconProps+ * @position Companion component for XDSTopNavTitle logo slot+ *+ * SYNC: When modified, update these files to stay in sync:+ * - /packages/core/src/TopNav/README.md+ * - /packages/core/src/TopNav/XDSTopNav.test.tsx+ * - /packages/core/src/TopNav/index.ts+ * - /apps/storybook/stories/TopNav.stories.tsx+ */++import {forwardRef, type HTMLAttributes, type ReactNode} from 'react';+import * as stylex from '@stylexjs/stylex';+import {colorVars, sizeVars} from '../theme/tokens.stylex';++/**+ * TitleIcon styles+ */+const styles = stylex.create({+ base: {+ display: 'flex',+ alignItems: 'center',+ justifyContent: 'center',+ borderRadius: '50%',+ backgroundColor: colorVars['--color-accent'],+ color: colorVars['--color-icon-on-media'],+ flexShrink: 0,+ },+ sm: {+ width: sizeVars['--size-sm'],+ height: sizeVars['--size-sm'],+ },+ md: {+ width: sizeVars['--size-md'],+ height: sizeVars['--size-md'],+ },+ lg: {+ width: sizeVars['--size-lg'],+ height: sizeVars['--size-lg'],+ },+});++/**+ * Size variants for the title icon+ */+export type XDSTopNavTitleIconSize = 'sm' | 'md' | 'lg';++export interface XDSTopNavTitleIconProps extends Omit<+ HTMLAttributes<HTMLSpanElement>,+ 'style' | 'className'+> {+ /**+ * The icon element to render inside the circular background.+ * Should be an XDSIcon or similar icon component.+ */+ icon: ReactNode;+ /**+ * Size of the circular icon container.+ * @default 'md'+ */+ size?: XDSTopNavTitleIconSize;+}++/**+ * Circular icon container for XDSTopNavTitle.+ *+ * Wraps an icon with a circular colored background, suitable for+ * use as a logo in the top navigation title area.+ *+ * @example+ * ```tsx+ * import {HomeIcon} from '@heroicons/react/24/solid';+ *+ * <XDSTopNavTitle+ * title="Dashboard"+ * logo={+ * <XDSTopNavTitleIcon+ * icon={<HomeIcon style={{width: 16, height: 16}} />}+ * />+ * }+ * />+ * ```+ */+export const XDSTopNavTitleIcon = forwardRef<+ HTMLSpanElement,+ XDSTopNavTitleIconProps+>(function XDSTopNavTitleIcon({icon, size = 'md', ...props}, ref) {+ return (+ <span ref={ref} {...stylex.props(styles.base, styles[size])} {...props}>+ {icon}+ </span>+ );+});++XDSTopNavTitleIcon.displayName = 'XDSTopNavTitleIcon';diff --git a/packages/core/src/TopNav/index.ts b/packages/core/src/TopNav/index.tsnew file mode 100644index 0000000000..4adcc6e240--- /dev/null+++ b/packages/core/src/TopNav/index.ts@@ -0,0 +1,23 @@+/**+ * @file index.ts+ * @input Imports from TopNav component files+ * @output Exports XDSTopNav and companion components+ * @position Entry point for TopNav module+ *+ * SYNC: When modified, update /packages/core/src/TopNav/README.md+ */++export {XDSTopNav} from './XDSTopNav';+export type {XDSTopNavProps} from './XDSTopNav';++export {XDSTopNavTitle} from './XDSTopNavTitle';+export type {XDSTopNavTitleProps} from './XDSTopNavTitle';++export {XDSTopNavTitleIcon} from './XDSTopNavTitleIcon';+export type {+ XDSTopNavTitleIconProps,+ XDSTopNavTitleIconSize,+} from './XDSTopNavTitleIcon';++export {XDSTopNavItem} from './XDSTopNavItem';+export type {XDSTopNavItemProps} from './XDSTopNavItem';diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex c1cf53ccfa..843d7ac73e 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -32,6 +32,7 @@ export * from './TimeInput';export * from './NumberInput';export * from './Table';export * from './Dialog';+export * from './TopNav';// Layout utilities and components (includes XDSHStack, XDSVStack)export * from './Layout';