import React, { useEffect, useRef, useState } from 'react'; import Iconsvg from '../../Ui/Icon/Icon'; import './drop-down.css'; type Props = { label: string, clickable: boolean, size? : 'default' | 'small' | 'medium' | 'large', variant?: 'default' |'primary' | 'secondary', placement: 'top' | 'bottom', iconName:any, } const menuOptions = [ { label: 'Action', value: 'action' }, { label: 'Anther action', link: 'anotherAction' }, { label: 'Somthing else here', link: 'somthingElseHere' } ] const DropDown = (props:Props) => { const {label, size, clickable, iconName, variant, placement } = props; const [show, setShow] = useState(false); const dropdownRef = useRef(null); const showMenu = () => { setShow(!show) }; const onMouseOver = () => { setShow(!show) } const onMouseLeave = () => { setShow(false) } useEffect(() => { const pageClickEvent = (e:any) => { if (dropdownRef.current !== null && !dropdownRef.current.contains(e.target)) { setShow(!show); } }; if (show) { window.addEventListener('click', pageClickEvent); } return () => { window.removeEventListener('click', pageClickEvent); } }, [show]) return ( <>
{/* Click Drpdown */} {clickable && } {/* Hover Dropdown */} {!clickable && } {/* Menu Options */}
Dropdown header
    { menuOptions && menuOptions.map((item, index) => (
  • {item.label}
  • )) }
); } export default DropDown;