mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-28 17:55:15 +02:00
* fix: add highlight and hover colors, fix them * misc ui adjustments * test isGrow prop in table cols * fix: revert typography changes, update snaps * Update src/themes/themeTypes.ts Co-authored-by: Tymoteusz Czech <2625371+Tymek@users.noreply.github.com> * fix: misc ui adjustments * fix: backButton color * refactor: color not needed, can be inherited * fix: project roles case, new borderRadius values * fix: color green * fix: feature form link * update snaps * fix: formatting * update snap Co-authored-by: Tymoteusz Czech <2625371+Tymek@users.noreply.github.com>
37 lines
823 B
TypeScript
37 lines
823 B
TypeScript
import { VFC } from 'react';
|
|
import { useStyles } from './Highlighter.styles';
|
|
|
|
interface IHighlighterProps {
|
|
search?: string;
|
|
children?: string;
|
|
caseSensitive?: boolean;
|
|
}
|
|
|
|
const escapeRegex = (str: string) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
|
|
export const Highlighter: VFC<IHighlighterProps> = ({
|
|
search,
|
|
children,
|
|
caseSensitive,
|
|
}) => {
|
|
const { classes } = useStyles();
|
|
if (!children) {
|
|
return null;
|
|
}
|
|
|
|
if (!search) {
|
|
return <>{children}</>;
|
|
}
|
|
|
|
const regex = new RegExp(escapeRegex(search), caseSensitive ? 'g' : 'gi');
|
|
|
|
return (
|
|
<span
|
|
className={classes.highlighter}
|
|
dangerouslySetInnerHTML={{
|
|
__html: children?.replaceAll(regex, '<mark>$&</mark>') || '',
|
|
}}
|
|
/>
|
|
);
|
|
};
|