import React, { forwardRef, PropsWithChildren, useImperativeHandle, useLayoutEffect, useRef, useState, } from 'react'; import { Icon, IconTypes } from '../Icon'; import { Popup } from '../Popup'; import { usePluginsElement } from './hooks'; import './styles/index.scss'; export interface PluginsProps { plugins?: Array, showNumber?: number, MoreIcon?: any, className?: string, customClass?: string, style?: any, root?: any, handleVisible?: (isVisible:any) => void, showMore?: boolean, } function PluginsWithContext( props:PropsWithChildren, ref, ):React.ReactElement { const { plugins = [], showNumber, MoreIcon, className = '', style, customClass = '', root, handleVisible, } = props; useImperativeHandle(ref, () => ({ closeMore: (newVal) => { setShow(false); }, })); const { showPicker, elements } = usePluginsElement({ plugins, showNumber }); const pluginRef = useRef(null); const [show, setShow] = useState(false); const handleShow = (e) => { e.stopPropagation(); setShow(!show); if (!show) { pluginRef.current.offsetParent.removeEventListener('scroll', handleShow); } }; const pluginHandleVisible = (data) => { if (handleVisible) { const { width, height, } = pluginRef.current.children[1].getBoundingClientRect(); const { x = 0, y = 0 } = pluginRef.current.getBoundingClientRect(); pluginRef.current.offsetParent.addEventListener('scroll', handleShow); handleVisible({ ...data, width, height, x, y, }); } }; return ( (showPicker.length > 0 || elements?.length > 0) && (
    {showPicker?.length > 0 && showPicker.map((Item, index:number) => { const key = `${Item}${index}`; return (
  • {Item}
  • ); })} { elements?.length > 0 && (
    { !MoreIcon && } { MoreIcon && MoreIcon }
      {elements.map((Item, index:number) => { const key = `${Item}${index}`; return (
    • {Item}
    • ); })}
    ) }
) ); } const Plugins = forwardRef(PluginsWithContext); export { Plugins, };