UNPKG

@atlaskit/editor-plugin-insert-block

Version:

Insert block plugin for @atlaskit/editor-core

49 lines 2.42 kB
import React from 'react'; import { useIntl } from 'react-intl'; import { INPUT_METHOD } from '@atlaskit/editor-common/analytics'; import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks'; import { ToolTipContent, insertMention } from '@atlaskit/editor-common/keymaps'; import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages'; import { TOOLBAR_BUTTON_TEST_ID } from '@atlaskit/editor-common/toolbar'; import { ToolbarButton, ToolbarTooltip, MentionIcon } from '@atlaskit/editor-toolbar'; export const MentionButton = ({ api }) => { const { formatMessage } = useIntl(); const { canInsertMention, mentionProvider, isTypeAheadAllowed } = useSharedPluginStateWithSelector(api, ['mention', 'typeAhead'], states => { var _states$mentionState, _states$mentionState2, _states$typeAheadStat; return { canInsertMention: (_states$mentionState = states.mentionState) === null || _states$mentionState === void 0 ? void 0 : _states$mentionState.canInsertMention, mentionProvider: (_states$mentionState2 = states.mentionState) === null || _states$mentionState2 === void 0 ? void 0 : _states$mentionState2.mentionProvider, isTypeAheadAllowed: (_states$typeAheadStat = states.typeAheadState) === null || _states$typeAheadStat === void 0 ? void 0 : _states$typeAheadStat.isAllowed }; }); if (!(api !== null && api !== void 0 && api.mention)) { return null; } const onClick = () => { var _api$mention, _api$mention$actions; api === null || api === void 0 ? void 0 : (_api$mention = api.mention) === null || _api$mention === void 0 ? void 0 : (_api$mention$actions = _api$mention.actions) === null || _api$mention$actions === void 0 ? void 0 : _api$mention$actions.openTypeAhead(INPUT_METHOD.TOOLBAR); }; return /*#__PURE__*/React.createElement(ToolbarTooltip, { content: /*#__PURE__*/React.createElement(ToolTipContent, { description: formatMessage(messages.mention), keymap: insertMention }) }, /*#__PURE__*/React.createElement(ToolbarButton, { iconBefore: /*#__PURE__*/React.createElement(MentionIcon, { label: formatMessage(messages.mention), size: "small" }), onClick: onClick, ariaKeyshortcuts: "Shift+2 Space", isDisabled: !canInsertMention || !mentionProvider || !isTypeAheadAllowed, testId: TOOLBAR_BUTTON_TEST_ID.MENTION })); };