import { Tooltip } from "antd"
import React, { useEffect, useRef, useState } from "react"
import style from './index.less'

interface Props {
    value?: string | number
}
/**
 * 表格溢出展示
 * @returns 
 */
const WidthEllipsis: React.FC<Props> = (props) => {

    /*********************************/
    const { value } = props
    const ref: any = useRef(null)
    const ref1: any = useRef(null)
    const [data, setData] = useState<{ open?: boolean }>({})
    /*********************************/

    useEffect(() => {
        // 容器宽度
        let width = ref.current.clientWidth
        // 文字实际宽度
        let actualWidth = ref1.current.childNodes[0].getBoundingClientRect().width
        if (actualWidth > width) {
            setData({})
        } else {
            setData({ open: false })
        }
    }, [ref, ref1])

    return <Tooltip title={value} {...data}>
        <div className={style.myEll}>
            <div ref={ref} className="ellipsisOne">{value}</div>
            <div ref={ref1} className={style.hiddenCon}><span>{value}</span></div>
        </div>
    </Tooltip>
}

export default React.memo(WidthEllipsis)