import React, { Component } from 'react'; import { Popover, OverlayTrigger, Button } from 'react-bootstrap'; interface Props { children: JSX.Element; onConfirm?: () => void; onCancel?: () => void; } interface State { show: boolean; } export default class PopoverConfirm extends Component { state: State = { show: false }; toggle = (e?: React.MouseEvent) => { if (e) { e.stopPropagation(); } const { show } = this.state; this.setState({ show: !show }); }; confirm = () => { this.toggle(); const { onConfirm } = this.props; if (onConfirm) { onConfirm(); } }; cancel = () => { this.toggle(); const { onCancel } = this.props; if (onCancel) { onCancel(); } }; render() { const { children } = this.props; const { show } = this.state; const clonedChildren = React.cloneElement(children, { onClick: this.toggle }); const popover = ( { // Prevent to trigger hide event on modal dialog e.stopPropagation(); }} > Are you sure?
); if (!show) { return clonedChildren; } return ( <> {children} ); } }