跳转到内容
Nacre
组件配色
EN

高亮 Highlight

stableHighlight在画廊运行
Highlight
在浏览器里运行真实组件。

搜索结果里命中关键字的部分换品牌文字色(brand-text)并加到 500,不加底色;单行,放不下截断。

状态:stable · 组件:Highlight

import { Highlight } from 'nacre'
import { View } from 'nsh'
import { Highlight, TEXT_SIZE } from 'nacre'
export function HighlightUsage() {
return (
<View class="w-[320px] max-w-full">
<Highlight
class={`${TEXT_SIZE.body} text-muted-foreground`}
text="港股开户需要准备身份证与地址证明"
keyword="开户"
/>
</View>
)
}

keyword 直接接搜索框的值,结果边输边高亮;关键字为空时整行原样显示。

import { View, signal } from 'nsh'
import { Highlight, SearchField, TEXT_SIZE } from 'nacre'
const faq = () => [
'港股开户需要准备身份证与地址证明',
'美股账户的资金何时到账',
'资金转出后多久可以到银行卡',
'如何修改绑定的手机号',
]
export function HighlightSearch() {
const keyword = signal('资金')
return (
<View class="w-[360px] max-w-full gap-2">
<SearchField value={keyword()} onChange={(v) => keyword.set(v)} placeholder="搜索常见问题" />
<View class="gap-1.5">
{faq().map((text) => (
<Highlight class={`${TEXT_SIZE.small} text-muted-foreground`} text={text} keyword={keyword()} />
))}
</View>
</View>
)
}

同一行里每一处命中都高亮,不区分大小写,显示的仍是原文的大小写。

import { View } from 'nsh'
import { Highlight, TEXT_SIZE } from 'nacre'
export function HighlightMatches() {
return (
<View class="w-[320px] max-w-full gap-2">
<Highlight
class={`${TEXT_SIZE.body} text-muted-foreground`}
text="VIP 客户升级为 vip 专线后由专人跟进"
keyword="vip"
/>
<Highlight
class={`${TEXT_SIZE.body} text-muted-foreground`}
text="转入资金、转出资金都需要先完成认证"
keyword="资金"
/>
</View>
)
}
  • 读屏读整行原文,高亮只是视觉强调,不单独念。

该用

  • 只高亮用户输入的关键字
  • 其余文字用 muted-foreground,命中段才跳出来

不该用

  • 用来强调普通文案
  • 在多行正文里用(Highlight 是单行,会截断)
属性 类型 默认 说明
text * string —
keyword string —
class string —
testID string —

* 必填