JGuang

TopNav

TopNav · Astryx

Preview
npm install @astryxdesign/core@0.7.1 @astryxdesign/theme-neutral@0.7.1 @stylexjs/stylex@0.19.0

TopNav

TopNav is a horizontal navigation bar for product-level navigation in application headers. Use TopNav for 5 or fewer always-visible navigation items, or minimal navigation paired with search and controls. For complex navigation hierarchies, use a sidebar; to filter content, use tabs or filter buttons instead.

Installation

npm install @astryxdesign/core@0.7.1 @astryxdesign/theme-neutral@0.7.1 @stylexjs/stylex@0.19.0

Requires React 19+, base CSS and a Theme provider. See Setup.

Top Nav

TopNav is a horizontal navigation bar for product-level navigation in application headers. Use TopNav for 5 or fewer always-visible navigation items, or minimal navigation paired with search and controls. For complex navigation hierarchies, use a sidebar; to filter content, use tabs or filter buttons instead.

PropTypeDefaultDescription
headingReactNodeHeading slot content (logo, brand): positioned at the left edge of the nav bar.
startContentReactNodeStart content slot for navigation items or breadcrumbs: positioned after the heading, left-aligned.
childrenReactNodeAlias for startContent. Prefer startContent when composing with heading, centerContent, or endContent; children keeps the common React nav-item pattern from silently dropping items.
centerContentReactNodeCenter content slot (tabs, search bar, primary navigation): when provided, switches the layout to a three-column CSS grid for true horizontal centering.
endContentReactNodeEnd content slot for search, icons, or user profile: positioned at the right edge.
labelstring'Top navigation'Accessible label for the navigation landmark, applied as aria-label on the <nav> element.
xstyleStyleXStylesStyleX styles for layout customization (margins, positioning, sizing). Must be a stylex.create() value: not an inline style object like style={{}}.

Usage guidance

  • Include a product logo and name in the heading slot to clearly identify the application.
  • Limit primary navigation items to 5 or fewer for quick scanning and minimal cognitive load.
  • Avoid: Avoid using TopNav to filter page content; use Tabs or filter controls instead.
  • Avoid: Avoid deeply nested navigation hierarchies; keep menus to one level of depth.

Theming API

{
  "targets": [
    {
      "className": "astryx-top-nav",
      "states": [
        "mode"
      ]
    },
    {
      "className": "astryx-top-nav-item",
      "states": [
        "mode",
        "selected"
      ]
    },
    {
      "className": "astryx-top-nav-heading"
    },
    {
      "className": "astryx-top-nav-mega-menu",
      "states": [
        "mode"
      ]
    },
    {
      "className": "astryx-top-nav-mega-menu-item",
      "states": [
        "mode"
      ]
    },
    {
      "className": "astryx-top-nav-mega-menu-featured-card"
    },
    {
      "className": "astryx-top-nav-menu"
    }
  ]
}

TopNavHeading

TopNavItem

TopNavMenu

TopNavMegaMenu

TopNavMegaMenuItem

TopNavMegaMenuFeaturedCard

Anatomy

  • Product icon and name: Identifies the product in the navigation bar.
  • Navigation items: Primary links for product-level destinations.
  • More menu: Overflow menu for additional navigation items.
  • Flex area: Flexible region for search, primary action buttons, or other controls.

Top Nav Heading

Product/suite/account heading for the TopNav heading slot. Supports smart interaction boundary logic: logo, heading text, superheading/subheading with independent links, and an optional menu popover with automatic chevron indicator.

PropTypeDefaultDescription
logoReactNodeLogo element to display before the heading text. Can be an image, NavIcon, or any ReactNode.
headingstringProduct/app name displayed as the primary heading text.
headingHrefstringLink for the heading text (e.g. product home). When no menu is present and this is the only href, the whole heading becomes one clickable link.
superheadingstringText above the heading (e.g. suite name). Rendered in a smaller secondary style.
superheadingHrefstringLink for the superheading text (e.g. suite home). When provided alongside a menu, renders as an independent inline link.
subheadingstringText below the heading (e.g. account context). Rendered in a smaller secondary style.
subheadingHrefstringLink for the subheading text. When provided alongside a menu, renders as an independent inline link.
headerEndContentReactNodeContent rendered at the trailing edge of the heading row (e.g. a badge or status indicator).
menuReactNodeMenu content shown in a popover dropdown. When provided, a chevron indicator appears automatically. Interaction boundary is determined by the presence of hrefs: no hrefs means the whole header is the trigger; with hrefs, links are independent and the chevron area is the trigger.
asLinkComponentTypeCustom component to render instead of <a>. Overrides the provider-level default set by LinkProvider. Must accept href, className, style, and children props.
xstyleStyleXStylesStyleX styles for layout customization. Must be a stylex.create() value.

Top Nav Item

Navigation link item for use in TopNav startContent: renders as an anchor with hover and selected states.

PropTypeDefaultDescription
label *stringAccessible label for the nav item. Rendered as visible text by default. When isIconOnly is true, used as aria-label instead.
hrefstringNavigation target URL.
isSelectedbooleanfalseWhether this nav item is currently selected. Sets aria-current="page" and applies highlighted styles.
isDisabledbooleanfalseWhether the nav item is disabled. Sets aria-disabled, drops href/target so the item cannot navigate, and prevents interaction.
isIconOnlybooleanfalseRenders the item as a square icon-only element. When true, label becomes the aria-label and visible text is hidden. Requires icon to be set.
iconReactNodeOptional icon to display before the label.
childrenReactNodeCustom content to render instead of the label text.
asLinkComponentTypeCustom component to render instead of <a>. Overrides the provider-level default set by LinkProvider. Must accept href, className, style, and children props.

Top Nav Mega Menu

Navigation item that displays a full-width mega menu panel on hover. Uses a slots API with items and featured props. TopNavMegaMenuItem renders itself in both desktop and mobile drawer modes. Supports inline collapsible drawer via render mode context.

PropTypeDefaultDescription
label *stringVisible label for the trigger button.
itemsReactNodeMenu items slot: typically TopNavMegaMenuItem components, but accepts any ReactNode.
featuredReactNodeFeatured content slot: rendered in the right panel on desktop, below items in the mobile drawer.
delaynumber150Delay in milliseconds before showing the menu on hover.
hideDelaynumber250Delay in milliseconds before hiding the menu after the mouse leaves.
onOpenChange(isOpen: boolean) => voidCallback fired when the mega menu opens or closes. Useful for coordinating wrapper styles.

Standard featured card for the TopNavMegaMenu featured slot. Provides a consistent card with optional image, title, description, and CTA link.

PropTypeDefaultDescription
title *stringCard title.
descriptionstringDescription text below the title.
imagestringOptional image URL displayed above the body.
imageAltstringAlt text for the image. When omitted, the image is explicitly decorative (alt="", role="presentation", aria-hidden), usually correct since the card already has a visible title. Provide it only when the image conveys information beyond the title and description.
linkLabelstringCTA link text.
linkHrefstringCTA link URL.
childrenReactNodeCustom content rendered below the standard body.

Top Nav Mega Menu Item

An individual item inside an TopNavMegaMenu. Renders itself in both desktop (popover grid) and mobile drawer modes via render mode context.

PropTypeDefaultDescription
title *stringDisplay title for the menu item.
descriptionstringOptional description text displayed below the title.
iconReactNodeOptional icon element displayed to the left.
hrefstringURL to navigate to when clicked.
onClick() => voidCallback when item is clicked.
asLinkComponentTypeCustom component to render instead of <a> for link items. Overrides the provider-level default set by LinkProvider.

Top Nav Menu

Navigation item that displays a hover-triggered popover menu with rich items containing an icon, title, and optional description.

PropTypeDefaultDescription
label *stringVisible label for the trigger button.
items *TopNavMenuItemData[]Menu items to display in the hover popover. Item href values follow the shared navigation rule described on Link; rejected destinations remain visible without navigation.
delaynumber150Delay in milliseconds before showing the menu on hover.
hideDelaynumber200Delay in milliseconds before hiding the menu after the mouse leaves.

Examples

  • Top Nav Heading: Demonstrates TopNavHeading with a logo and text, both as a plain display and as a clickable link.
  • Top Nav Item: Demonstrates TopNavItem with selected, icon, disabled, and default states.
  • Top Nav Mega Menu Featured Card: Demonstrates TopNavMegaMenuFeaturedCard with a title, description, and CTA link inside a mega menu.
  • Top Nav Mega Menu Item: Demonstrates TopNavMegaMenuItem with icons, titles, and descriptions inside a mega menu.
  • Top Nav Mega Menu: Demonstrates TopNavMegaMenu with items and a featured card in the mega menu panel.
  • Top Nav Menu: Demonstrates TopNavMenu with a hover-triggered dropdown containing items with icons and descriptions.
  • Top Nav:
  • TopNav — Centered Navigation: Navigation layout with center-aligned nav items flanked by a logo heading and end actions.
  • TopNav — Enterprise Dashboard: Full-featured navigation bar with icon-labeled nav items, search, notifications, and a primary CTA.
  • TopNavHeading — Basic: A product heading with a logo inside a TopNav, linked to the home page. Use as the leading brand element of a top navigation bar.
  • TopNav — Hover Menu: Navigation bar with a hover-triggered dropdown menu showing product items with icons and descriptions.
  • TopNavItem — Basic: Navigation links inside a TopNav with one item marked as selected. Use for top-level pages of an application.
  • TopNav — Mega Menu: Marketing-style navigation with a full-width mega menu featuring product items and a promotional featured card.
  • TopNavMegaMenu — Basic: A mega menu trigger inside a TopNav that opens a panel of rich link items. Use when a navigation section has multiple destinations worth describing.
  • TopNavMegaMenuFeaturedCard — Basic: A promotional card with a title, description, and call-to-action link. Pass it to the featured slot of a TopNavMegaMenu to highlight announcements.
  • TopNavMegaMenuItem — Basic: Rich link items with an icon, title, and description. Use inside the items slot of a TopNavMegaMenu to describe each destination.
  • TopNavMenu — Basic: A dropdown menu inside a TopNav built from an items array with icons and descriptions. Use to group related destinations under a single trigger.
  • TopNav — Multiple Dropdowns: Navigation bar with multiple hover-triggered dropdown menus that auto-close when switching between them.
  • TopNav — With Logo: Navigation bar with a branded logo icon, heading link, nav items, and a profile action.

Complete example dependencies

Some examples import optional icons. The per-example install command in the examples list identifies exactly what that example needs. For all examples on this page:

npm install @heroicons/react@2.2.0