Skip to Content

Highlight

Highlight a substring within a string with customizable styles.

Import

import { Highlight } from '@tidbcloud/uikit'

Basic Usage

Use Highlight to highlight a substring in a given string with a mark tag. Pass the main string as children and the substring to highlight via the highlight prop.

import { Highlight } from '@tidbcloud/uikit' function Demo() { return <Highlight highlight="important">This is an important message</Highlight> }

Highlight Multiple Substrings

Provide an array of values to highlight multiple substrings:

import { Highlight } from '@tidbcloud/uikit' function Demo() { return <Highlight highlight={['this', 'that']}>Highlight this and also that</Highlight> }

Custom Highlight Styles

Override default styles with the highlightStyles prop:

import { Highlight } from '@tidbcloud/uikit' function Demo() { return ( <Highlight highlight={['highlighted', 'default']} highlightStyles={{ backgroundImage: 'linear-gradient(45deg, var(--mantine-color-cyan-5), var(--mantine-color-indigo-5))', fontWeight: 700, WebkitBackgroundClip: 'text', WebkitTextFillColor: 'transparent' }} > You can change styles of highlighted part if you do not like default styles </Highlight> ) }

Key Props

PropTypeDescription
childrenstringString to search for highlight matches
highlightstring | string[]Substring or list of substrings to highlight
highlightStylesCSSPropertiesCustom styles for highlighted text
colorstringColor key from theme or any valid CSS color
sizeMantineSizeControls font-size and line-height
inheritbooleanInherit font properties from parent
Last updated on