This browser is not supported. The glass needs a Chromium browser or Electron. Why

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

PropTypeDefaultDescription
rootReactElement<NavigationPageProps>-Required. The root page.
destination(value: never) => ReactElement<NavigationPageProps>-The page for a value on the path.
pathunknown[]-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.
metricsMetricsPHONEBar 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.
backIconComponentTypeLucide ChevronLeftThe back button's glyph; SystemBackChevron is what a stock app has.
inlineTitleOffsetnumber0Moves the inline title down by this many px.
className, stylestring, CSSProperties-On the stack's box. It fills its parent.

NavigationPage

PropTypeDefaultDescription
titlestring-The page's title.
subtitlestring-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.
scrollEdgeEffectHiddenboolean-No edge effect.
toolbarReactNode-ToolbarItem, ToolbarItemGroup, ToolbarSpacer.
searchableboolean-Places and draws a search field's capsule (phone: bottom bar; pad: last in the top bar).
backButtonHiddenboolean-No back button on this page.
backgroundstringsystem backgroundA colour behind the content (a List sets its own).
backdropReactNode-Fixed behind the scrolling content.
childrenReactNode-Scrolls under the bar; a List here uses the page's scroll view.

ToolbarItem

PropTypeDefaultDescription
placement"topBarLeading" | "topBarTrailing" | "principal" | "bottomBar" | "status""topBarTrailing"Where in the bars it goes.
titlestring-The title, or the accessible name of an icon item.
iconComponentType-A Lucide icon component (Plus, not <Plus />), drawn at 24 px.
onAction() => void-Runs on press.
disabledboolean-Dimmed; doesn't respond.
tintstring-The item's colour.
prominentboolean-A tinted capsule of its own (.borderedProminent).
sharedBackgroundbooleantruefalse: no glass, out of its neighbours' capsule.
idstringits titleKeeps an item across pages so it moves with the morph.
menuMenuNode[]-A press opens this menu from the capsule (see Menu).

ToolbarItemGroup, ToolbarSpacer

PropTypeDefaultDescription
placementPlacement-Both: where the group or spacer goes.
childrenReactNode-ToolbarItemGroup: its items, placed together.
sizing"flexible" | "fixed""flexible"ToolbarSpacer: a gap that grows to fill, or a fixed one.

NavigationStackLink

PropTypeDefaultDescription
valueunknown-Required. Pushed on the stack when pressed.
childrenReactNode-The label, laid out as a 72 px row.
className, stylestring, 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()

PropTypeDefaultDescription
pathunknown[]-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 toolbarprominent
.sharedBackgroundVisibility(.hidden)sharedBackground={false}
Menu in a ToolbarItemmenu={[...]}
.navigationBarBackButtonHidden()backButtonHidden
.searchable(text:) (its place in the bar)searchable
NavigationLink(value:)<NavigationLink value> in a List, <NavigationStackLink value> outside
@Environment(\.dismiss) / path accessuseNavigation()