// @flow import React from 'react'; import replace from 'string-replace-to-array'; import styled from 'styled-components'; import { color } from 'shared/styles/constants'; type Props = { highlight: ?string, text: string, caseSensitive?: boolean, }; function Highlight({ highlight, caseSensitive, text, ...rest }: Props) { return ( {highlight ? replace( text, new RegExp( (highlight || '').replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&'), caseSensitive ? 'g' : 'gi' ), (tag, index) => {tag} ) : text} ); } const Mark = styled.mark` background: ${color.yellow}; `; export default Highlight;