@atlaskit/editor-plugin-table
Version:
Table plugin for the @atlaskit/editor
31 lines (30 loc) • 1.73 kB
JavaScript
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';
/**
* The toggle section currently contains only the Header column toggle. When
* that item is hidden, the whole section disappears so we don't render an
* empty wrapper (and so the section below can drop its leading separator).
*/
export var ColumnToggleSection = function ColumnToggleSection(_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;
if (!shouldShowHeaderColumnToggle({
isFirstColumn: tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isFirstColumn,
isHeaderColumnAllowed: isHeaderColumnAllowed,
selectedColumnCount: tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedColumnCount
})) {
return null;
}
return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, null, children);
};