Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(website): add Utilities > Highlight and Mark page #8367

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions packages/website/docs/components/utilities/highlight_and_mark.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
slug: /utilities/highlight-and-mark
id: utilities_highlight_and_mark
---

# Highlight and mark

## Highlight

Use **EuiHighlight** to highlight substrings within a string, typically in response to user input.

<Demo>
```tsx interactive
import React, { useState, useMemo } from 'react';

import {
EuiHighlight,
EuiFieldSearch,
EuiFormRow,
EuiSpacer,
EuiSwitch,
EuiFlexGroup,
} from '@elastic/eui';

export default () => {
const [searchInput, setSearchInput] = useState('jumped over');
const [isHighlightAll, setHighlightAll] = useState(false);
const [searchMultiple, setSearchMultiple] = useState(false);
const [caseSensitive, setCaseSensitive] = useState(false);

const searchValues = useMemo(() => {
return searchMultiple && isHighlightAll
? searchInput.split(' ')
: searchInput;
}, [searchMultiple, searchInput, isHighlightAll]);

return (
<>
<EuiFlexGroup>
<EuiSwitch
label="Case sensitive"
checked={caseSensitive}
onChange={(e) => setCaseSensitive(e.target.checked)}
/>
<EuiSwitch
label="Highlight all"
checked={isHighlightAll}
onChange={(e) => setHighlightAll(e.target.checked)}
/>
{isHighlightAll && (
<EuiSwitch
label="Search for an array of separate words"
checked={searchMultiple}
onChange={(e) => setSearchMultiple(e.target.checked)}
/>
)}
</EuiFlexGroup>
<EuiSpacer size="xl" />
<EuiFormRow label="Enter text to highlight substrings within a string">
<EuiFieldSearch
value={searchInput}
onChange={(e) => setSearchInput(e.target.value)}
/>
</EuiFormRow>
<EuiSpacer size="m" />
<EuiHighlight
strict={caseSensitive}
highlightAll={isHighlightAll}
search={searchValues}
>
The quick brown fox jumped over the lazy dog
</EuiHighlight>
</>
);
};
```
</Demo>

## Mark

Use **EuiMark** to wrap a string in a `mark` element.

<Demo>
```tsx interactive
import React from 'react';

import { EuiMark } from '@elastic/eui';

export default () => {
return (
<>
The quick brown fox <EuiMark>jumped over</EuiMark> the lazy dog
</>
);
};
```
</Demo>

## Props

import highlightDocgen from '@elastic/eui-docgen/dist/components/highlight';
import markDocgen from '@elastic/eui-docgen/dist/components/mark';

<PropTable definition={highlightDocgen.EuiHighlight} />
<PropTable definition={markDocgen.EuiMark} />