import { markdown } from 'markdown'; import { debounce } from 'lodash'; import React from 'react'; import PropTypes from 'prop-types'; import Modal from 'antd/lib/modal'; import Input from 'antd/lib/input'; import Tooltip from 'antd/lib/tooltip'; import Divider from 'antd/lib/divider'; import { wrap as wrapDialog, DialogPropType } from '@/components/DialogWrapper'; import { toastr } from '@/services/ng'; import './AddTextboxDialog.less'; class AddTextboxDialog extends React.Component { static propTypes = { dashboard: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types dialog: DialogPropType.isRequired, onConfirm: PropTypes.func.isRequired, }; state = { saveInProgress: false, text: '', preview: '', } updatePreview = debounce(() => { const text = this.state.text; this.setState({ preview: markdown.toHTML(text), }); }, 100); onTextChanged = (event) => { this.setState({ text: event.target.value }); this.updatePreview(); }; saveWidget() { this.setState({ saveInProgress: true }); this.props.onConfirm(this.state.text) .then(() => { this.props.dialog.close(); }) .catch(() => { toastr.error('Widget could not be added'); }) .finally(() => { this.setState({ saveInProgress: false }); }); } render() { const { dialog } = this.props; return ( this.saveWidget()} okButtonProps={{ loading: this.state.saveInProgress, disabled: !this.state.text, }} okText="Add to Dashboard" width={500} >
Supports basic{' '} Markdown . {this.state.text && ( Preview:

)}

); } } export default wrapDialog(AddTextboxDialog);