2019-08-31 04:07:25 +05:00
|
|
|
import React, { useCallback, useState } from 'react';
|
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
import { Button, Popup as SemanticUIPopup } from 'semantic-ui-react';
|
|
|
|
|
|
|
|
|
|
import styles from './Popup.module.css';
|
|
|
|
|
|
2020-05-16 04:09:46 +05:00
|
|
|
export default (WrappedComponent, defaultProps) => {
|
2019-08-31 04:07:25 +05:00
|
|
|
const Popup = React.memo(({ children, ...props }) => {
|
|
|
|
|
const [isOpened, setIsOpened] = useState(false);
|
|
|
|
|
|
|
|
|
|
const handleOpen = useCallback(() => {
|
|
|
|
|
setIsOpened(true);
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const handleClose = useCallback(() => {
|
|
|
|
|
setIsOpened(false);
|
|
|
|
|
}, []);
|
|
|
|
|
|
2020-03-25 00:15:47 +05:00
|
|
|
const handleMouseDown = useCallback((event) => {
|
2019-08-31 04:07:25 +05:00
|
|
|
event.stopPropagation();
|
|
|
|
|
}, []);
|
|
|
|
|
|
2020-03-25 00:15:47 +05:00
|
|
|
const handleClick = useCallback((event) => {
|
2019-08-31 04:07:25 +05:00
|
|
|
event.stopPropagation();
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const handleTriggerClick = useCallback(
|
2020-03-25 00:15:47 +05:00
|
|
|
(event) => {
|
2019-08-31 04:07:25 +05:00
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
|
|
const { onClick } = children;
|
|
|
|
|
|
|
|
|
|
if (onClick) {
|
|
|
|
|
onClick(event);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[children],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const tigger = React.cloneElement(children, {
|
|
|
|
|
onClick: handleTriggerClick,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<SemanticUIPopup
|
|
|
|
|
basic
|
|
|
|
|
wide
|
|
|
|
|
trigger={tigger}
|
|
|
|
|
on="click"
|
|
|
|
|
open={isOpened}
|
|
|
|
|
position="bottom left"
|
2020-10-20 16:10:25 +05:00
|
|
|
popperModifiers={[
|
|
|
|
|
{
|
|
|
|
|
name: 'preventOverflow',
|
|
|
|
|
options: {
|
|
|
|
|
boundariesElement: 'window',
|
|
|
|
|
},
|
2020-05-16 04:09:46 +05:00
|
|
|
},
|
2020-10-20 16:10:25 +05:00
|
|
|
]}
|
2019-08-31 04:07:25 +05:00
|
|
|
className={styles.wrapper}
|
|
|
|
|
onOpen={handleOpen}
|
|
|
|
|
onClose={handleClose}
|
|
|
|
|
onMouseDown={handleMouseDown}
|
|
|
|
|
onClick={handleClick}
|
2020-05-16 04:09:46 +05:00
|
|
|
{...defaultProps} // eslint-disable-line react/jsx-props-no-spreading
|
2019-08-31 04:07:25 +05:00
|
|
|
>
|
|
|
|
|
<Button icon="close" onClick={handleClose} className={styles.closeButton} />
|
|
|
|
|
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
|
|
|
|
|
<WrappedComponent {...props} onClose={handleClose} />
|
|
|
|
|
</SemanticUIPopup>
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Popup.propTypes = {
|
|
|
|
|
children: PropTypes.node.isRequired,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return Popup;
|
|
|
|
|
};
|