UNPKG

@atlaskit/editor-plugin-toolbar

Version:

Toolbar plugin for @atlaskit/editor-core

31 lines • 1.32 kB
import React, { useCallback, useSyncExternalStore } from 'react'; import { ConfirmationModal } from '../ConfirmationModal'; /** * Renders the dialog opened with `store.show`. Render it where it outlives the toolbar, e.g. in a * plugin `contentComponent`: menus close and the toolbar hides when the dialog takes focus. */ export const ConfirmDialog = ({ editorView, store, testId }) => { const options = useSyncExternalStore(store.subscribe, store.getOptions, store.getOptions); const onConfirm = useCallback((isChecked = false) => { var _options$onConfirm; const command = options === null || options === void 0 ? void 0 : (_options$onConfirm = options.onConfirm) === null || _options$onConfirm === void 0 ? void 0 : _options$onConfirm.call(options, isChecked); command === null || command === void 0 ? void 0 : command(editorView.state, editorView.dispatch, editorView); }, [options, editorView]); const onClose = useCallback(() => { store.hide(); // The dialog takes focus from the editor; restore it so the cursor does not jump. if (!editorView.hasFocus()) { editorView.focus(); } }, [store, editorView]); return /*#__PURE__*/React.createElement(ConfirmationModal, { testId: testId, options: options, onConfirm: onConfirm, onClose: onClose }); };