UNPKG

@atlaskit/editor-plugin-table

Version:

Table plugin for the @atlaskit/editor

79 lines (78 loc) 3.98 kB
/* SortIncreasingItem.tsx generated by @compiled/babel-plugin v3.0.2 */ import _extends from "@babel/runtime/helpers/extends"; import "./SortIncreasingItem.compiled.css"; import { ax, ix } from "@compiled/react/runtime"; import React from 'react'; import { useIntl } from 'react-intl'; import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps'; import { INPUT_METHOD } from '@atlaskit/editor-common/analytics'; import { tableMessages as messages } from '@atlaskit/editor-common/messages'; import { getSelectionRect } from '@atlaskit/editor-tables/utils'; import { InformationCircleIcon, SortAscendingIcon, ToolbarDropdownItem } from '@atlaskit/editor-toolbar'; import { fg } from '@atlaskit/platform-feature-flags/fg'; import { Box, Text } from '@atlaskit/primitives/compiled'; import Tooltip from '@atlaskit/tooltip/Tooltip'; import { closeActiveTableMenu } from '../../../../pm-plugins/commands'; import { sortColumnWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics'; import { useTableMenuContext } from '../../shared/TableMenuContext'; var styles = { infoIconTrigger: "_1e0c116y _4cvr1h6o" }; export var SortIncreasingItem = function SortIncreasingItem(_ref) { var api = _ref.api; var tableMenuContext = useTableMenuContext(); var _ref2 = tableMenuContext !== null && tableMenuContext !== void 0 ? tableMenuContext : {}, editorView = _ref2.editorView; var _useIntl = useIntl(), formatMessage = _useIntl.formatMessage; var hasMergedCellsInTable = Boolean(tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.hasMergedCellsInTable); var handleClick = function handleClick() { var _api$analytics; if (!editorView) { return; } var selectionRect = getSelectionRect(editorView.state.selection); var columnIndex = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.left; if (columnIndex === undefined) { return; } sortColumnWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(INPUT_METHOD.TABLE_CONTEXT_MENU, columnIndex, SortOrder.ASC)(editorView.state, editorView.dispatch); api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu(api)); api === null || api === void 0 || api.core.actions.focus(); }; // When the table has merged cells, the item remains interactive but is rendered // with a disabled-looking label and leading icon, alongside an enabled info icon // that surfaces why sorting is unavailable. if (hasMergedCellsInTable && fg('platform_editor_table_menu_updates_patch_1')) { return /*#__PURE__*/React.createElement(ToolbarDropdownItem, { elemBefore: /*#__PURE__*/React.createElement(SortAscendingIcon, { label: "", size: "small", color: "var(--ds-text-disabled, #080F214A)" }), elemAfter: /*#__PURE__*/React.createElement(Tooltip, { content: formatMessage(messages.canNotSortTableNoIcon), position: "top" }, function (tooltipProps) { return /*#__PURE__*/React.createElement(Box, _extends({ as: "span", xcss: styles.infoIconTrigger }, tooltipProps), /*#__PURE__*/React.createElement(InformationCircleIcon, { label: "", size: "small", color: "var(--ds-icon, #292A2E)" })); }) }, /*#__PURE__*/React.createElement(Text, { color: "color.text.disabled" }, formatMessage(messages.sortColumnIncreasing))); } return /*#__PURE__*/React.createElement(ToolbarDropdownItem, { onClick: handleClick, isDisabled: Boolean(tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.hasMergedCellsInTable), elemBefore: /*#__PURE__*/React.createElement(SortAscendingIcon, { label: "", size: "small" }) }, formatMessage(messages.sortColumnIncreasing)); };