UNPKG

@atlaskit/editor-plugin-toolbar-lists-indentation

Version:

Toolbar lists and indentation plugin for @atlaskit/editor-core

44 lines 2.68 kB
import React from 'react'; import { useIntl } from 'react-intl'; import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks'; import { messages } from '@atlaskit/editor-common/lists'; import { useEditorToolbar } from '@atlaskit/editor-common/toolbar'; import { MoreItemsIcon, ToolbarDropdownMenu, ToolbarTooltip } from '@atlaskit/editor-toolbar'; import { useIndentationState } from '../utils/hooks'; export var ListsIndentationMenu = function ListsIndentationMenu(_ref) { var children = _ref.children, api = _ref.api, allowHeadingAndParagraphIndentation = _ref.allowHeadingAndParagraphIndentation; var _useIntl = useIntl(), formatMessage = _useIntl.formatMessage; var _useEditorToolbar = useEditorToolbar(), editorView = _useEditorToolbar.editorView; var indentationState = useIndentationState({ api: api, allowHeadingAndParagraphIndentation: allowHeadingAndParagraphIndentation, state: editorView === null || editorView === void 0 ? void 0 : editorView.state }); var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['list', 'taskDecision'], function (states) { var _states$listState, _states$listState2, _states$taskDecisionS; return { bulletListDisabled: (_states$listState = states.listState) === null || _states$listState === void 0 ? void 0 : _states$listState.bulletListDisabled, orderedListDisabled: (_states$listState2 = states.listState) === null || _states$listState2 === void 0 ? void 0 : _states$listState2.orderedListDisabled, taskListActive: (_states$taskDecisionS = states.taskDecisionState) === null || _states$taskDecisionS === void 0 ? void 0 : _states$taskDecisionS.isInsideTask }; }), bulletListDisabled = _useSharedPluginState.bulletListDisabled, orderedListDisabled = _useSharedPluginState.orderedListDisabled, taskListActive = _useSharedPluginState.taskListActive; var allItemsDisabled = bulletListDisabled && orderedListDisabled && (indentationState === null || indentationState === void 0 ? void 0 : indentationState.indentDisabled) && (indentationState === null || indentationState === void 0 ? void 0 : indentationState.outdentDisabled) && !taskListActive; return /*#__PURE__*/React.createElement(ToolbarDropdownMenu, { iconBefore: /*#__PURE__*/React.createElement(MoreItemsIcon, { label: formatMessage(messages.lists) }), isDisabled: allItemsDisabled, testId: "editor-toolbar__lists-and-indentation-menu", label: formatMessage(messages.lists), tooltipComponent: /*#__PURE__*/React.createElement(ToolbarTooltip, { content: formatMessage(messages.lists) }) }, children); };