UNPKG

@atlaskit/editor-plugin-table

Version:

Table plugin for the @atlaskit/editor

32 lines (31 loc) 1.79 kB
import React from 'react'; import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks'; import { ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar'; import { useTableMenuContext } from '../../shared/TableMenuContext'; import { shouldShowHeaderColumnToggle } from './HeaderColumnToggleItem'; /** * Background section sits directly below `ColumnToggleSection`. Its separator * exists only to divide it from the toggle section; when the toggle section * is hidden, the separator must drop too so we don't render a stray rule at * the very top of the menu. */ export var ColumnBackgroundSection = function ColumnBackgroundSection(_ref) { var api = _ref.api, children = _ref.children; var tableMenuContext = useTableMenuContext(); var _useSharedPluginState = useSharedPluginStateWithSelector(api !== null && api !== void 0 ? api : undefined, ['table'], function (states) { var _states$tableState; return { isHeaderColumnAllowed: (_states$tableState = states.tableState) === null || _states$tableState === void 0 || (_states$tableState = _states$tableState.pluginConfig) === null || _states$tableState === void 0 ? void 0 : _states$tableState.allowHeaderColumn }; }), isHeaderColumnAllowed = _useSharedPluginState.isHeaderColumnAllowed; var hasSeparator = shouldShowHeaderColumnToggle({ isFirstColumn: tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isFirstColumn, isHeaderColumnAllowed: isHeaderColumnAllowed, selectedColumnCount: tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedColumnCount }); return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, { hasSeparator: hasSeparator }, children); };