@atlaskit/editor-plugin-table
Version:
Table plugin for the @atlaskit/editor
33 lines (32 loc) • 1.61 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 const ColumnToggleSection = ({
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
};
});
if (!shouldShowHeaderColumnToggle({
isFirstColumn: tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isFirstColumn,
isHeaderColumnAllowed,
selectedColumnCount: tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedColumnCount
})) {
return null;
}
return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, null, children);
};