{"version":3,"file":"Toast-DzB4rFGc.js","sources":["../../Client/legacy/Components/Toast.tsx"],"sourcesContent":["import * as React from 'react';\r\n\r\nimport Portal from '@webkit/components/portal';\r\n\r\nenum ToastType {\r\n Error = 'toast-error-cp',\r\n Warning = 'toast-warning-cp',\r\n Success = 'toast-success-cp',\r\n}\r\n\r\ntype Props = {\r\n portal?: boolean;\r\n};\r\n\r\ntype State = {\r\n visible: boolean;\r\n message: string;\r\n type: ToastType;\r\n};\r\n\r\nexport default class Toast extends React.Component<Props, State> {\r\n private timeout: any;\r\n\r\n state = {\r\n visible: false,\r\n message: '',\r\n type: ToastType.Success,\r\n };\r\n\r\n componentWillUnmount() {\r\n if (this.timeout) clearTimeout(this.timeout);\r\n }\r\n\r\n render() {\r\n const portal = this.props.portal === undefined ? true : this.props.portal;\r\n return portal ? <Portal className='toast'>{this.renderToast()}</Portal> : this.renderToast();\r\n }\r\n\r\n renderToast() {\r\n return (\r\n <div\r\n className={`toast-cp ${this.state.visible ? 'toast-visible-cp' : ''} ${this.state.type}`}\r\n onClick={() => this.setState({ visible: false })}\r\n >\r\n <span className='toast-message-cp'>{this.state.message}</span>\r\n </div>\r\n );\r\n }\r\n\r\n success(message: string, timeoutInMilliseconds?: number) {\r\n this.message(message, ToastType.Success, timeoutInMilliseconds);\r\n }\r\n\r\n warning(message: string, timeoutInMilliseconds?: number) {\r\n this.message(message, ToastType.Warning, timeoutInMilliseconds);\r\n }\r\n\r\n error(message: string, timeoutInMilliseconds?: number) {\r\n this.message(message, ToastType.Error, timeoutInMilliseconds);\r\n }\r\n\r\n private message(message: string, type: ToastType, timeoutInMilliseconds?: number) {\r\n if (this.timeout) clearTimeout(this.timeout);\r\n\r\n if (this.state.visible) {\r\n this.setState({ visible: false }, () => {\r\n setTimeout(() => {\r\n this.setState({ message, type, visible: true });\r\n }, 150);\r\n });\r\n } else {\r\n this.setState({ message, type, visible: true });\r\n }\r\n\r\n this.timeout = setTimeout(() => this.setState({ visible: false }), timeoutInMil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