@atlaskit/editor-plugin-toolbar-lists-indentation
Version:
Toolbar lists and indentation plugin for @atlaskit/editor-core
48 lines • 2.31 kB
JavaScript
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 const ListsIndentationMenu = ({
children,
api,
allowHeadingAndParagraphIndentation
}) => {
const {
formatMessage
} = useIntl();
const {
editorView
} = useEditorToolbar();
const indentationState = useIndentationState({
api,
allowHeadingAndParagraphIndentation,
state: editorView === null || editorView === void 0 ? void 0 : editorView.state
});
const {
bulletListDisabled,
orderedListDisabled,
taskListActive
} = useSharedPluginStateWithSelector(api, ['list', 'taskDecision'], 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
};
});
const 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);
};