NavigationStack
Pages that push over a dimmed, parallaxed parent and swipe back. The bar is glass: toolbar items run into capsules that morph between pages, and a large title hands over to the inline one as it scrolls under the bar.
import { NavigationPage, NavigationStack, ToolbarItem } from "@adamexu/glass";Push, swipe back, toolbars
Tap a row to push its page. Drag right from anywhere on a pushed page (not the bar's buttons) to go back; let go past half or with a flick to finish. Scroll the root page to see the large title hand over to the bar, and press Add for its menu.
const [path, setPath] = useState<Route[]>([]);
const root = (
<NavigationPage
title="Settings"
toolbar={
<ToolbarItem title="Add" icon={Plus} menu={[
{ kind: "button", title: "New folder", icon: <Folder size={20} /> },
{ kind: "button", title: "New favorite", icon: <Star size={20} /> },
]} />
}
>
<List>
<Section>
<NavigationLink key="display" value="display"><Label title="Display" icon={<Palette size={20} />} /></NavigationLink>
<NavigationLink key="alerts" value="alerts"><Label title="Alerts" icon={<Bell size={20} />} /></NavigationLink>
<NavigationLink key="privacy" value="privacy"><Label title="Privacy" icon={<Shield size={20} />} /></NavigationLink>
</Section>
<Section header="About">
{Array.from({ length: 10 }, (_, i) => (
<LabeledContent key={i} title={`Setting ${i + 1}`} value={i % 2 ? "On" : "Off"} />
))}
</Section>
</List>
</NavigationPage>
);
const destination = (route: Route) => (
<NavigationPage
title={TITLES[route]}
titleDisplayMode="inline"
toolbar={
<>
<ToolbarItemGroup placement="topBarTrailing">
<ToolbarItem title="Favorite" icon={Star} />
<ToolbarItem title="Share" icon={Share} />
</ToolbarItemGroup>
<ToolbarItem placement="bottomBar" title="Filter" icon={SlidersHorizontal} />
<ToolbarSpacer placement="bottomBar" />
<ToolbarItem placement="bottomBar" title="Done" prominent onAction={() => setPath([])} />
</>
}
>
<List>
<Section header="Details">
<LabeledContent key="status" title="Status" value="On" />
<LabeledContent key="updated" title="Updated" value="Today" />
</Section>
<Section>
<Button key="reset" role="destructive" onClick={() => setPath([])}>Back to Settings</Button>
</Section>
</List>
</NavigationPage>
);
<NavigationStack root={root} destination={destination} path={path} onPathChange={(next) => setPath(next as Route[])} />The bar
Items run into capsules, leading from the left and trailing from the right. A title centres when it clears them and leads otherwise; items that do not fit go under a More menu. A push slides the new page in and the bar's capsules morph to its items; give an item the same id (or title) on both pages and it moves with the morph instead of crossfading. The scroll edge effect under the bar is a blur at the top of the page and turns hard once content is under the bar. The stack is an iPhone's by default; pass idiom and metrics (padMetrics, duoMetrics) for the other devices.
Props
NavigationStack
| Prop | Type | Default | Description |
|---|---|---|---|
| root | ReactElement<NavigationPageProps> | - | Required. The root page. |
| destination | (value: never) => ReactElement<NavigationPageProps> | - | The page for a value on the path. |
| path | unknown[] | - | The path past the root; controlled when given, else the stack keeps its own. |
| onPathChange | (path: unknown[]) => void | - | Push, pop, back button, swipe back. |
| idiom | "phone" | "pad" | "duo" | "phone" | The device whose bar layout to use. |
| metrics | Metrics | PHONE | Bar metrics of this window: PHONE, padMetrics(fullScreen), duoMetrics(screen). |
| tabBar | "top" | "bottom" | - | Under a TabView's bar: at the top (iPad) a root title goes and content scrolls under with no edge effect. |
| backIcon | ComponentType | Lucide ChevronLeft | The back button's glyph; SystemBackChevron is what a stock app has. |
| inlineTitleOffset | number | 0 | Moves the inline title down by this many px. |
| className, style | string, CSSProperties | - | On the stack's box. It fills its parent. |
NavigationPage
| Prop | Type | Default | Description |
|---|---|---|---|
| title | string | - | The page's title. |
| subtitle | string | - | A line under the title. |
| titleDisplayMode | "automatic" | "inline" | "large" | "automatic" | automatic: the page beneath's (the root's is large). |
| scrollEdgeEffectStyle | "automatic" | "soft" | "hard" | "automatic" | automatic: a blur at the top, hard once content is under the bar. |
| scrollEdgeEffectHidden | boolean | - | No edge effect. |
| toolbar | ReactNode | - | ToolbarItem, ToolbarItemGroup, ToolbarSpacer. |
| searchable | boolean | - | Places and draws a search field's capsule (phone: bottom bar; pad: last in the top bar). |
| backButtonHidden | boolean | - | No back button on this page. |
| background | string | system background | A colour behind the content (a List sets its own). |
| backdrop | ReactNode | - | Fixed behind the scrolling content. |
| children | ReactNode | - | Scrolls under the bar; a List here uses the page's scroll view. |
ToolbarItem
| Prop | Type | Default | Description |
|---|---|---|---|
| placement | "topBarLeading" | "topBarTrailing" | "principal" | "bottomBar" | "status" | "topBarTrailing" | Where in the bars it goes. |
| title | string | - | The title, or the accessible name of an icon item. |
| icon | ComponentType | - | A Lucide icon component (Plus, not <Plus />), drawn at 24 px. |
| onAction | () => void | - | Runs on press. |
| disabled | boolean | - | Dimmed; doesn't respond. |
| tint | string | - | The item's colour. |
| prominent | boolean | - | A tinted capsule of its own (.borderedProminent). |
| sharedBackground | boolean | true | false: no glass, out of its neighbours' capsule. |
| id | string | its title | Keeps an item across pages so it moves with the morph. |
| menu | MenuNode[] | - | A press opens this menu from the capsule (see Menu). |
ToolbarItemGroup, ToolbarSpacer
| Prop | Type | Default | Description |
|---|---|---|---|
| placement | Placement | - | Both: where the group or spacer goes. |
| children | ReactNode | - | ToolbarItemGroup: its items, placed together. |
| sizing | "flexible" | "fixed" | "flexible" | ToolbarSpacer: a gap that grows to fill, or a fixed one. |
NavigationStackLink
| Prop | Type | Default | Description |
|---|---|---|---|
| value | unknown | - | Required. Pushed on the stack when pressed. |
| children | ReactNode | - | The label, laid out as a 72 px row. |
| className, style | string, CSSProperties | - | On the link's button. |
In a List, push with the List's own NavigationLink row (a chevron, the press, and the highlight that stays under the new page). Outside one, NavigationStackLink is a plain button that pushes its value.
useNavigation()
| Prop | Type | Default | Description |
|---|---|---|---|
| path | unknown[] | - | The current path past the root. |
| push | (value: unknown) => void | - | Pushes a value. |
| pop | () => void | - | Goes back one page. |
useNavigation() returns null outside a NavigationStack.
Behaviour
Pages stay mounted down the stack, so each keeps its scroll; the top two draw. The bars wait for the stack's real size, so they don't morph across on first show, and lay out again once Inter has loaded.
SwiftUI
| SwiftUI | @adamexu/glass |
|---|---|
| NavigationStack(path:) { root }.navigationDestination(for:) | <NavigationStack root path onPathChange destination> |
| .navigationTitle / .navigationSubtitle | <NavigationPage title subtitle> |
| .navigationBarTitleDisplayMode(.inline) | titleDisplayMode="inline" |
| .scrollEdgeEffectStyle(.soft, for: .top) / .scrollEdgeEffectHidden() | scrollEdgeEffectStyle="soft" / scrollEdgeEffectHidden |
| .toolbar { ToolbarItem(placement: .topBarTrailing) { Button } } | toolbar={<ToolbarItem placement="topBarTrailing" title icon onAction />} |
| ToolbarItemGroup / ToolbarSpacer(.fixed) | <ToolbarItemGroup> / <ToolbarSpacer sizing="fixed"> |
| .buttonStyle(.borderedProminent) in a toolbar | prominent |
| .sharedBackgroundVisibility(.hidden) | sharedBackground={false} |
| Menu in a ToolbarItem | menu={[...]} |
| .navigationBarBackButtonHidden() | backButtonHidden |
| .searchable(text:) (its place in the bar) | searchable |
| NavigationLink(value:) | <NavigationLink value> in a List, <NavigationStackLink value> outside |
| @Environment(\.dismiss) / path access | useNavigation() |