Highlight

A component that highlights matching substrings within text using fuzzy search.

Anatomy

<Highlight>
  {children}
</Highlight>

Usage

import { Highlight } from '@ivaldi/ui'
<Highlight term="world">
  Hello world! How are you doing today?
</Highlight>

With Search Results

const results = ['Apple Pie', 'Orange Juice', 'Grape Soda']
const searchTerm = 'ap'

return (
  <ul>
    {results.map((result) => (
      <li key={result}>
        <Highlight term={searchTerm}>{result}</Highlight>
      </li>
    ))}
  </ul>
)

Custom Mark Style

<Highlight term="important">
  This is a very important message.
</Highlight>

// With custom mark styling:
<Mark className="bg-warning-bg text-warning-text">
  Important text
</Mark>

In List Context

const items = [
  'Documentation',
  'Components',
  'Examples',
  'Tutorials',
  'API Reference'
]
const searchTerm = 'doc'

return (
  <ul className="space-y-2">
    {items.map((item) => (
      <li key={item} className="px-4 py-2 rounded hover:bg-bg-hover">
        <Highlight term={searchTerm}>{item}</Highlight>
      </li>
    ))}
  </ul>
)

Highlight Props

PropTypeDefault
children*string
termstring""