Skip to content

Navbar ​

The top navigation bar for a page. A centered title with content on both sides, a bottom divider, and a stacking order from zIndex.sticky.

Spec source: lh-ui-core/specs/navbar.json · Golden cases: lh-ui-core/cases/navbar.json (6 entries, translated into XCTest, runnable on the macOS host)

Basic usage ​

title is centered (absolutely positioned, so it never overlaps the content on either side); leftText / rightText hug the left and right edges respectively.

9:41Navbar basic
Back青花瓷 (ceramic blue)More
Page content

HTML mock preview (iOS / SwiftUI appearance), not an on-device render

swift
LhNavbar(
  title: "青花瓷 (ceramic blue)",
  leftText: "Back",
  rightText: "More",
  onLeftClick: { /* Back */ },
  onRightClick: { /* More */ }
)

Icons and border ​

leftIcon / rightIcon go through the LhIconMap mapping and are displayed alongside the text; bordered = false removes the bottom divider.

9:41Navbar icons
BackTitleSettings
Borderless navbar

HTML mock preview (iOS / SwiftUI appearance), not an on-device render

Tap gate ​

When neither leftText nor leftIcon is provided, the left side does not respond to taps (golden case no-left-content-no-onleftclick); the same holds for the right side. Floating positioning is mounted by the caller with .overlay (the SwiftUI convention), while the component itself supplies the zIndex.sticky stacking order.

swift
ZStack {
  contentView
    .padding(.top, LhTokens.Navbar.height)
  LhNavbar(title: "青花瓷 (ceramic blue)", leftText: "Back", onLeftClick: { dismiss() })
    .overlay(alignment: .top) { ... }
}

API ​

Props ​

PropDescriptionTypeDefault
titleCentered titleString""
leftTextLeft-side text (not tappable when empty and there is no leftIcon)String""
leftIconLogical name of the left icon (mapped via LhIconMap)String?nil
rightTextRight-side text (not tappable when empty and there is no rightIcon)String""
rightIconLogical name of the right iconString?nil
borderedWhether to show the bottom dividerBooltrue
onLeftClickLeft-side tap callback(() -> Void)?nil
onRightClickRight-side tap callback(() -> Void)?nil

Colors ​

AreaColor
Backgroundcolor.background.default
Title / side texts / iconscolor.text.primary
Dividercolor.border.lighter (width from navbar.borderWidth)

Token Reference ​

TokenPurpose
navbar.heightNavbar height (44pt)
navbar.paddingHorizontalHorizontal padding on both sides (12pt)
navbar.titleFontSizeTitle and side text font size (16pt)
navbar.iconSizeSide icon size (20pt)
navbar.borderWidthBottom divider width
color.border.lighterDivider color
color.text.primaryTitle and side content color
color.background.defaultBackground
zIndex.stickyFloating stacking order

Golden Case Mapping ​

case idAssertionLocal test
title-renders-textThe title renders correctlytestTitleUsesNavbarTokens
leftclick-emits-onleftclickA left tap fires onLeftClicktestLeftContentIsClickable
rightclick-emits-onrightclickA right tap fires onRightClicktestRightContentIsClickable
no-left-content-no-onleftclickWith no left content, nothing is firedtestNoLeftContentIsNotClickable
bordered-uses-border-tokenThe divider consumes the border.lighter tokentestBorderedUsesBorderToken
height-uses-navbar-height-tokenThe height consumes the navbar.height tokentestHeightUsesNavbarHeightToken

Plus dedicated tests: testContainerUsesBackgroundToken / testDarkColorsComeFromDarkTokens / testDimensionsAreIdenticalInDarkMode / testNavbarInitAndRender.

bash
swift test --filter LhNavbarTests    # Runs on the macOS host, no simulator required

lh-ui native bloodline · iOS (Swift + SwiftUI)