Skip to content
Nacre
Color palette
中文

PaneHeader

experimentalPaneHeaderOpen in playground
PaneHeader
Runs the real component in your browser.

The title row at the top of a pane or panel: 48 tall, 13 side insets, a 1pt line below; back on the left, title and secondary detail, actions and close on the right. Panes in the layout use pane (13pt), popovers and drawers use panel (16pt).

Status: experimental · Components: PaneHeader

import { PaneHeader } from 'nacre'

A pane in the layout (the right panel, the call info pane) uses the default pane: a 13pt medium title, the same size as body text. detail holds small elements such as a count; actions holds sm buttons.

import { Text, View, signal } from 'nsh'
import type { JSX } from 'nsh'
import { Badge, Button, PaneHeader } from 'nacre'
function Frame(props: { width?: number; children?: JSX.Element }) {
return (
// 宽度是上限:手机画廊只有 320 宽,按钮不能被挤出屏幕
<View class="w-full rounded-lg border border-border bg-background overflow-hidden" style={{ maxWidth: props.width ?? 380 }}>
{props.children}
<Text class="p-[13px] text-body text-muted-foreground">Panel content</Text>
</View>
)
}
export function PaneHeaderUsage() {
const n = signal(0)
return (
<Frame>
<PaneHeader
testID="demo-pane"
title="Service notes"
detail={<Badge count={3} />}
actions={
<Button testID="demo-pane-new" size="sm" variant="secondary" icon="plus" onPress={() => n.set(n() + 1)}>
New
</Button>
}
/>
<If when={n() > 0}>
<Text testID="demo-pane-count" class="px-[13px] pt-2 text-small text-muted-foreground">Created {n()}</Text>
</If>
</Frame>
)
}

size=“panel”: a 16pt medium title, matching the page title in the title bar. close adds the rightmost close button and tightens the right inset to 8; back.compact shows only the arrow. Turn divider off when tabs follow directly or the list draws its own top line.

import { Text, View, signal } from 'nsh'
import type { JSX } from 'nsh'
import { Button, PaneHeader } from 'nacre'
function Frame(props: { width?: number; children?: JSX.Element }) {
return (
// 宽度是上限:手机画廊只有 320 宽,按钮不能被挤出屏幕
<View class="w-full rounded-lg border border-border bg-background overflow-hidden" style={{ maxWidth: props.width ?? 380 }}>
{props.children}
<Text class="p-[13px] text-body text-muted-foreground">Panel content</Text>
</View>
)
}
export function PaneHeaderPanel() {
const open = signal(true)
const view = signal<'recent' | 'history'>('recent')
return (
<If
when={open()}
else={
<Button testID="demo-panel-reopen" size="sm" variant="secondary" onPress={() => open.set(true)}>
Reopen
</Button>
}
>
<Frame width={360}>
<PaneHeader
size="panel"
testID="demo-panel"
title="Downloads"
back={view() === 'history' ? { label: 'Back', compact: true, onPress: () => view.set('recent') } : undefined}
actions={
<If when={view() === 'recent'}>
<Button testID="demo-panel-all" variant="ghost" size="xs" onPress={() => view.set('history')}>
View all
</Button>
</If>
}
close={{ label: 'Close', onPress: () => open.set(false) }}
/>
</Frame>
</If>
)
}

In a stacked panel, Back shows the previous level’s title. When space runs out the back label truncates first, then detail, so the title and right-hand buttons stay visible; the full text is in the tooltip and screen reader name. DrawerHeader is built on PaneHeader this way.

import { Text, View, signal } from 'nsh'
import { Button, PaneHeader, Swap } from 'nacre'
export function PaneHeaderBack() {
const level = signal(2)
// 前进 / 返回换层:整层(栏头 + 内容)用 Swap 按方向滑入,进下一级从右、返回从左,不瞬切(component-standard §7)
let direction: 'forward' | 'back' = 'forward'
const go = (to: number) => {
direction = to > level() ? 'forward' : 'back'
level.set(to)
}
return (
<View class="w-full rounded-lg border border-border bg-background overflow-hidden" style={{ maxWidth: 420 }}>
<Swap value={level()} motion={() => direction}>
<PaneHeader
size="panel"
testID="demo-back"
title={level() === 2 ? 'Complaint ticket' : 'Call details'}
detail={level() === 2 ? 'CS-20261126-0042' : undefined}
back={level() === 2 ? { label: 'Back to Call details', onPress: () => go(1) } : undefined}
actions={
<If when={level() === 1}>
<Button testID="demo-back-open" size="xs" variant="ghost" onPress={() => go(2)}>
Open ticket
</Button>
</If>
}
/>
<Text class="p-[13px] text-body text-muted-foreground">
{level() === 2 ? 'Ticket content' : 'Call content'}
</Text>
</Swap>
</View>
)
}

Without title, children fill the title area: the search field of the conversation list, the avatar and identity of the conversation header. Height, insets and the divider still come from the header.

import { Text, View, signal } from 'nsh'
import type { JSX } from 'nsh'
import { PaneHeader, SearchField } from 'nacre'
function Frame(props: { width?: number; children?: JSX.Element }) {
return (
// 宽度是上限:手机画廊只有 320 宽,按钮不能被挤出屏幕
<View class="w-full rounded-lg border border-border bg-background overflow-hidden" style={{ maxWidth: props.width ?? 380 }}>
{props.children}
<Text class="p-[13px] text-body text-muted-foreground">Panel content</Text>
</View>
)
}
export function PaneHeaderCustom() {
const q = signal('')
return (
<Frame width={264}>
<PaneHeader>
<SearchField testID="demo-custom-search" class="flex-1" value={q()} onChange={(v) => q.set(v)} />
</PaneHeader>
</Frame>
)
}
Key Action
Tab Tab moves through back, actions and close; the title is not focusable
  • Back and Close are buttons with screen reader names; a compact Back reads its label.
  • The title is plain text; the heading level belongs to the surrounding panel.

Do

  • Use it at the top of every pane, popover panel and drawer so height, insets and the line stay consistent
  • Use pane in the layout, panel in popovers and drawers
  • Put Close in close, not in actions
  • Give testID as a prefix; parts are -bar (the row), -return, -title, -detail, -close

Don’t

  • Hand-write an h-12 px-[13px] border-b title row
  • Mix 13pt and 16pt titles across panes of the same level
  • Put more than one primary button in actions (move the rest into a More menu)
  • Use it for section titles inside a card (use SectionHeader)

Property descriptions follow the Chinese source comments.

Prop Type Default Description
title string — 标题;不给时由 children 占标题区(会话头的身份、列表栏的搜索框)
size PaneHeaderSize —
detail string | number | JSX.Element — 标题后的次要信息:文字与数字 muted、等宽,空间不够先截断它;也可以放计数等小元素(同样可收缩)
back PaneHeaderBack —
actions JSX.Element — 右侧动作,按 sm 档放 Button / IconButton;关闭钮用 close,不放这里
close { label: string; onPress: () => void } — 最右的关闭钮;有它时右内边收到 8,让 28 的图标钮正对下面内容的右缘
divider boolean — 底部 1pt 分隔线,默认有;浮层里紧接着页签或内容自带上边线时关掉
children JSX.Element — 自定义标题区,替换 title 与 detail
testID string — 前缀:生成 -bar(整行)、-return、-title、-detail、-close

* required