import React, {useMemo} from 'react' import {Block, Text} from './Components' interface Highlight{ /** 文本内容 */ content: string, /** 要高亮的关键字 */ keyword?: string, padding?: string, margin?: string, /** 字体大小 */ fontSize?: string, /** 文本字体颜色 */ color?: string, /** 深色文本字体颜色 */ _color?: string, /** 高亮字体颜色 */ highColor?: string, } const Highlight = (props: Highlight) => { const {content, keyword, margin='0', padding='0', fontSize='32', color='#121212', _color='rgba(255,255,255,0.85)', highColor='#ff2c2c'} = props const txtList = useMemo(() => { if(!keyword){ return [content] } let all: string[] = [] let arr1 = content.split(keyword) for(let i = 0; i < arr1.length; i++){ all.push(arr1[i]) if(i < arr1.length - 1){ all.push(keyword) } } return all }, [content, keyword]) return ( { txtList.map((item, index) => { if(item === keyword){ return ( {item} ) }else{ return( {item} ) } }) } ) } export default Highlight