UNPKG

@atlaskit/editor-plugin-hyperlink

Version:

Hyperlink plugin for @atlaskit/editor-core

36 lines 1.74 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, addLink } from '@atlaskit/editor-common/keymaps'; import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages'; import { LinkIcon, ToolbarButton, ToolbarTooltip } from '@atlaskit/editor-toolbar'; export const LinkButton = ({ api }) => { const { formatMessage } = useIntl(); const canInsertLink = useSharedPluginStateWithSelector(api, ['hyperlink'], state => { var _state$hyperlinkState, _state$hyperlinkState2; return (_state$hyperlinkState = state === null || state === void 0 ? void 0 : (_state$hyperlinkState2 = state.hyperlinkState) === null || _state$hyperlinkState2 === void 0 ? void 0 : _state$hyperlinkState2.canInsertLink) !== null && _state$hyperlinkState !== void 0 ? _state$hyperlinkState : true; }); const onClick = () => { api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : api.hyperlink.commands.showLinkToolbar(INPUT_METHOD.FLOATING_TB)); }; const isEnabled = canInsertLink; return /*#__PURE__*/React.createElement(ToolbarTooltip, { content: /*#__PURE__*/React.createElement(ToolTipContent, { description: formatMessage(messages.link), keymap: addLink }) }, /*#__PURE__*/React.createElement(ToolbarButton, { iconBefore: /*#__PURE__*/React.createElement(LinkIcon, { label: formatMessage(messages.link), size: "small" }), onClick: onClick, testId: 'editor-toolbar__link-button', isDisabled: !isEnabled })); };