@elastic/eui
Version:
Elastic UI Component Library
90 lines (89 loc) • 4.37 kB
JavaScript
var _excluded = ["children", "className", "scope", "style", "width", "minWidth", "maxWidth", "append"];
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import React, { useEffect, useRef } from 'react';
import PropTypes from "prop-types";
import classNames from 'classnames';
import { useEuiMemoizedStyles } from '../../services';
import { resolveWidthPropsAsStyle } from './utils';
import { euiTableCellCheckboxStyles } from './table_cells_shared.styles';
import { useEuiTableColumnDataStore } from './store/provider';
import { useEuiTableWithinStickyHeader } from './sticky_header';
import { useEuiTableStoreUniqueColumnId } from './store/use_unique_column_id';
import { jsx as ___EmotionJSX } from "@emotion/react";
export var EuiTableHeaderCellCheckbox = function EuiTableHeaderCellCheckbox(props) {
var children = props.children,
className = props.className,
_props$scope = props.scope,
scope = _props$scope === void 0 ? 'col' : _props$scope,
_style = props.style,
width = props.width,
minWidth = props.minWidth,
maxWidth = props.maxWidth,
append = props.append,
rest = _objectWithoutProperties(props, _excluded);
var storeCellId = useEuiTableStoreUniqueColumnId();
var store = useEuiTableColumnDataStore();
var isWithinStickyHeader = useEuiTableWithinStickyHeader();
var styles = useEuiMemoizedStyles(euiTableCellCheckboxStyles);
var renderHeaderCellRef = useRef();
renderHeaderCellRef.current = function (extraProps) {
var classes = classNames('euiTableHeaderCellCheckbox', className);
var style = resolveWidthPropsAsStyle(_style, {
width: width,
minWidth: minWidth,
maxWidth: maxWidth
});
return ___EmotionJSX("th", _extends({
css: styles.euiTableHeaderCellCheckbox,
className: classes,
scope: scope,
style: style
}, rest, extraProps), ___EmotionJSX("div", {
className: "euiTableCellContent"
}, children), append);
};
useEffect(function () {
// Don't register the column inside the sticky header as the original
// column is already registered. This would cause an infinite loop.
if (isWithinStickyHeader) {
return;
}
var unregisterColumn = store.registerColumn(storeCellId, {
renderHeaderCellRef: renderHeaderCellRef
});
return function () {
unregisterColumn();
};
}, [store, isWithinStickyHeader, storeCellId]);
useEffect(function () {
// Notify the store on every render so the sticky header stays in sync.
// React's reconciliation will efficiently handle any duplicate renders.
if (isWithinStickyHeader) {
return;
}
store.updateColumn(storeCellId, {
renderHeaderCellRef: renderHeaderCellRef
});
});
return renderHeaderCellRef.current({});
};
EuiTableHeaderCellCheckbox.propTypes = {
className: PropTypes.string,
"aria-label": PropTypes.string,
"data-test-subj": PropTypes.string,
css: PropTypes.any,
scope: PropTypes.any,
append: PropTypes.node,
width: PropTypes.oneOfType([PropTypes.string.isRequired, PropTypes.number.isRequired]),
minWidth: PropTypes.oneOfType([PropTypes.string.isRequired, PropTypes.number.isRequired]),
maxWidth: PropTypes.oneOfType([PropTypes.string.isRequired, PropTypes.number.isRequired])
};