@atlaskit/editor-plugin-table
Version:
Table plugin for the @atlaskit/editor
34 lines (33 loc) • 1.67 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';
/**
* 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 const ColumnBackgroundSection = ({
api,
children
}) => {
const tableMenuContext = useTableMenuContext();
const {
isHeaderColumnAllowed
} = useSharedPluginStateWithSelector(api !== null && api !== void 0 ? api : undefined, ['table'], states => {
var _states$tableState, _states$tableState$pl;
return {
isHeaderColumnAllowed: (_states$tableState = states.tableState) === null || _states$tableState === void 0 ? void 0 : (_states$tableState$pl = _states$tableState.pluginConfig) === null || _states$tableState$pl === void 0 ? void 0 : _states$tableState$pl.allowHeaderColumn
};
});
const hasSeparator = shouldShowHeaderColumnToggle({
isFirstColumn: tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isFirstColumn,
isHeaderColumnAllowed,
selectedColumnCount: tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedColumnCount
});
return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
hasSeparator: hasSeparator
}, children);
};