Skip to Content
文档

高亮

用于高亮文本的子字符串。

SourceStorybookRecipeArk
With the Highlight component, you can spotlight words.

用法

¥Usage

import { Highlight } from "@chakra-ui/react"
<Highlight query="Hello">Hello World</Highlight>

示例

¥Examples

多个

¥Multiple

将字符串数组传递给 query 属性,以高亮显示多个子字符串。

¥Pass an array of strings to the query prop to highlight multiple substrings.

With the Highlight component, you can spotlight, emphasize and accentuate words.

自定义样式

¥Custom Style

使用 styles 属性自定义高亮文本的样式。

¥Use the styles prop to customize the style of the highlighted text.

With the Highlight component, you can spotlight words.

搜索查询

¥Search Query

使用高亮组件高亮搜索查询结果。

¥Use the highlight component to highlight search query results.

Search result for: spot

Spotlight bulb

Spot cleaner

Spot ceiling

包含波浪线

¥With Squiggle

以下是如何在高亮文本周围渲染自定义波浪线图片的示例。用于实现更美观的效果。

¥Here's an example of how to render a custom squiggle image around the highlighted text. Useful for a more fancy effect.

Endless scale, powered by real humans.

属性

¥Props

PropDefaultType
query *
string | string[]

The query to highlight in the text

text *
string

The text to highlight

styles
SystemStyleObject | undefined

ignoreCase
boolean

Whether to ignore case while matching

matchAll
boolean

Whether to match multiple instances of the query

as
React.ElementType

The underlying element to render.

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.

Previous

标题

Next

Kbd