import React, { FC, MouseEventHandler, useLayoutEffect, useRef, useState } from 'react' import { PopupProps } from './types' import classNames from 'classnames' import { Flex } from '../flex' import A from './a' const Popup: FC = ({ parentRect, data, selected, onSelect, onPushCreate, }) => { const refDom = useRef(null) const [marginTop, setMarginTop] = useState(0) useLayoutEffect(() => { const { offsetHeight } = refDom.current! const diff = parentRect.y + offsetHeight - document.documentElement.clientHeight if (diff > 0) { setMarginTop(-diff) } }, [parentRect]) /** * 在 对应的 div 设置了 最大宽度 900 px * @description UI 图是超过五个换行, 现在无论多少模块都在一行, 根据UI图对宽度进行处理 * @param number 二级菜单的个数 * @returns popup 的宽度 */ const setPopupWidth = (number: number): string => { // 只有一个的基本宽度, 根据 UI图, 一个三级路由占据的 宽度 + 左右margin const baseWidth = 212 // 有多个模块 半句的最大宽段, 超出 900 换行 const maxWidth = baseWidth + (number - 1) * 172 return maxWidth + 'px' } const handleMouseEnter: MouseEventHandler = (e) => { e.currentTarget.classList.add('gm-nav-three-wrap-bg') } const handleMouseLeave: MouseEventHandler = (e) => { e.currentTarget.classList.remove('gm-nav-three-wrap-bg') } return (
{data.map((v, i) => (
{!!v.name &&
{v.name}
}
{v.sub.map((s, si) => (
{ event.preventDefault() onSelect(s) }} > {s.name} {s.toCreate && ( onPushCreate(s)} /> )}
))}
))}
) } export default Popup