import React, { useEffect, useMemo, useState } from 'react'; import Wrap from '../wrap/Wrap'; import Icon from '../../Icon/index'; import { Tooltip } from 'antd'; import '../g.scss'; let timer = null; function Icons(props: IIcons) { const { change, wrapStyle = { padding: '6px 20px 6px 20px' }, fontLine, alignmentList, value } = props; const [currentIndex, setCurrentIndex] = useState(-1); //高亮 useEffect(() => { //取消高亮 if (currentIndex > -1) { clearTimeout(timer); timer = setTimeout(() => { setCurrentIndex(-1); }, 1000); } return () => { clearTimeout(timer); }; }, [currentIndex]); const Dom = useMemo(() => { return (
{Array.isArray(fontLine) && fontLine.length > 0 && fontLine.map((item, index) => { return (
{ e.preventDefault(); change?.(item?.key); setCurrentIndex(index); }} >
); })}
{Array.isArray(alignmentList) && alignmentList.length > 0 && alignmentList.map((item) => { return (
{ e.preventDefault(); change?.(item?.key); }} >
); })}
); }, [fontLine, alignmentList, value, currentIndex]); return Dom; } export default Icons; export interface IIcons { fontLine?: IFontLine[]; alignmentList?: IFontLine[]; size?: string; change?: Function; wrapStyle?: React.CSSProperties; value?: IFontAlign; } export interface IFontLine { key: string; icon: string; title: string; } export interface IFontAlign { align?: string; bold?: string; underLine?: string; deleteLine?: string; }