import React from 'react'; import { SessionIconButton, SessionIconSize, SessionIconType } from './icon/'; interface Props { title: string; onClose: any; onOk: any; showExitIcon?: boolean; showHeader?: boolean; //Maximum of two icons in header headerIconButtons?: Array<{ type: SessionIconType; onClick?: any; }>; } interface State { isVisible: boolean; } export class SessionModal extends React.PureComponent { public static defaultProps = { showExitIcon: true, showHeader: true, }; constructor(props: any) { super(props); this.state = { isVisible: true, }; this.close = this.close.bind(this); this.onKeyUp = this.onKeyUp.bind(this); window.addEventListener('keyup', this.onKeyUp); } public render() { const { title, headerIconButtons, showExitIcon, showHeader } = this.props; const { isVisible } = this.state; return isVisible ? (
{showHeader ? ( <>
{showExitIcon ? ( ) : null}
{title}
{headerIconButtons ? headerIconButtons.map((iconItem: any) => { return ( ); }) : null}
) : null}
{this.props.children}
) : null; } public close() { this.setState({ isVisible: false, }); window.removeEventListener('keyup', this.onKeyUp); if (this.props.onClose) { this.props.onClose(); } } public onKeyUp(event: any) { switch (event.key) { case 'Enter': this.props.onOk(); break; case 'Esc': case 'Escape': this.close(); break; default: } } }