一栏或一块面板顶上的标题行:高 48,左右 13,底部 1pt 线;左返回、标题与次要信息、右侧动作与关闭。布局里的栏用 pane(13 号),浮层与抽屉用 panel(16 号)。
状态:experimental · 组件:PaneHeader
引入
定位到「引入」import { PaneHeader } from 'nacre'用法
定位到「用法」布局里的一栏(右栏、通话信息栏)用默认的 pane:标题 13 medium,与正文同号;detail 放计数这类小元素,actions 放 sm 档的按钮。
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">面板内容</Text> </View> )}
export function PaneHeaderUsage() { const n = signal(0) return ( <Frame> <PaneHeader testID="demo-pane" title="服务小记" detail={<Badge count={3} />} actions={ <Button testID="demo-pane-new" size="sm" variant="secondary" icon="plus" onPress={() => n.set(n() + 1)}> 新建 </Button> } /> <If when={n() > 0}> <Text testID="demo-pane-count" class="px-[13px] pt-2 text-small text-muted-foreground">已新建 {n()}</Text> </If> </Frame> )}示例
定位到「示例」浮层面板
定位到「浮层面板」size=“panel”:标题 16 medium,同标题条的页面标题。close 给最右的关闭钮,右内边随之收到 8;back.compact 只显示箭头。下面紧接页签或列表自带上边线时 divider={false}。
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">面板内容</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)}> 重新打开 </Button> } > <Frame width={360}> <PaneHeader size="panel" testID="demo-panel" title="下载中心" back={view() === 'history' ? { label: '返回', 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')}> 查看全部 </Button> </If> } close={{ label: '关闭', onPress: () => open.set(false) }} /> </Frame> </If> )}返回上一层
定位到「返回上一层」多级面板的「返回 上一层」显示上一层标题,太长时先截断返回、再截断 detail,标题与右侧按钮不被挤出;完整文字在悬停提示与读屏名里。DrawerHeader 就是这样搭在 PaneHeader 上的。
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 ? '客诉工单' : '通话详情'} detail={level() === 2 ? 'CS-20261126-0042' : undefined} back={level() === 2 ? { label: '返回 通话详情', onPress: () => go(1) } : undefined} actions={ <If when={level() === 1}> <Button testID="demo-back-open" size="xs" variant="ghost" onPress={() => go(2)}> 打开工单 </Button> </If> } /> <Text class="p-[13px] text-body text-muted-foreground"> {level() === 2 ? '工单内容' : '通话内容'} </Text> </Swap> </View> )}自定义标题区
定位到「自定义标题区」不给 title 时 children 占标题区:会话列表栏的搜索框、会话头的头像与身份。高度、内边和分隔线仍由栏头给。
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">面板内容</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> )}键盘
定位到「键盘」| 键 | 行为 |
|---|---|
| Tab | 依次到返回、动作、关闭;标题不可聚焦 |
无障碍
定位到「无障碍」- 返回与关闭都是带读屏名的按钮,compact 返回只显示箭头时读屏名就是 label。
- 标题是普通文字,页面的标题层级由所在面板决定,不额外标 heading。
该用 / 不该用
定位到「该用 / 不该用」该用
- 一栏、一块浮层或抽屉的顶部都用它,保证 48 高、13 内边、1pt 线一致
- 布局里的栏用 pane,浮层与抽屉用 panel
- 关闭用 close,不放进 actions
- testID 给前缀,部件是 -bar(整行)、-return、-title、-detail、-close
不该用
- 自己写 h-12 px-[13px] border-b 的标题行
- 同一层级的栏一处 13 号、一处 16 号
- 在 actions 里放两个以上的主要按钮(收进更多菜单)
- 用它做卡片里的小节标题(用 SectionHeader)
API
定位到「API」PaneHeader
定位到「PaneHeader」| 属性 | 类型 | 默认 | 说明 |
|---|---|---|---|
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 |
* 必填