import React, { useRef, useEffect, useCallback } from 'react'; import { UncontrolledPopover } from 'reactstrap'; import PropTypes from 'prop-types'; import { gettext } from '../../../../utils'; import Icon from '../../../../../../components/icon'; import '../index.css'; const AddView = ({ target, options, toggle, onOptionClick }) => { const popoverRef = useRef(null); const handleClickOutside = useCallback((event) => { if (popoverRef.current && !popoverRef.current.contains(event.target)) { toggle(event); } }, [toggle]); useEffect(() => { if (popoverRef.current) { document.addEventListener('click', handleClickOutside, true); } return () => { document.removeEventListener('click', handleClickOutside, true); }; }, [handleClickOutside]); return (
{gettext('New view')}
{options.map((item, index) => { return ( ); })}
); }; AddView.propTypes = { target: PropTypes.string.isRequired, toggle: PropTypes.func.isRequired, onOptionClick: PropTypes.func.isRequired, }; export default AddView;