pouncejs
Version:
A collection of UI components from Panther labs
52 lines (49 loc) • 2.36 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
import React from 'react';
import Box from '../Box';
var TableContext = /*#__PURE__*/React.createContext({});
var useTable = function useTable() {
return React.useContext(TableContext);
};
var Table = /*#__PURE__*/React.forwardRef(function Table(_ref, ref) {
var _ref$layout = _ref.layout,
layout = _ref$layout === void 0 ? 'auto' : _ref$layout,
_ref$size = _ref.size,
size = _ref$size === void 0 ? 'medium' : _ref$size,
_ref$stickyHeader = _ref.stickyHeader,
stickyHeader = _ref$stickyHeader === void 0 ? false : _ref$stickyHeader,
_ref$hoverable = _ref.hoverable,
hoverable = _ref$hoverable === void 0 ? false : _ref$hoverable,
_ref$rowSeparationStr = _ref.rowSeparationStrategy,
rowSeparationStrategy = _ref$rowSeparationStr === void 0 ? 'background' : _ref$rowSeparationStr,
_ref$backgroundColor = _ref.backgroundColor,
backgroundColor = _ref$backgroundColor === void 0 ? 'inherit' : _ref$backgroundColor,
_ref$backgroundColorO = _ref.backgroundColorOddRows,
backgroundColorOddRows = _ref$backgroundColorO === void 0 ? 'navyblue-500' : _ref$backgroundColorO,
rest = _objectWithoutPropertiesLoose(_ref, ["layout", "size", "stickyHeader", "hoverable", "rowSeparationStrategy", "backgroundColor", "backgroundColorOddRows"]);
var contextValue = React.useMemo(function () {
return {
size: size,
hoverable: hoverable,
rowSeparationStrategy: rowSeparationStrategy,
stickyHeader: stickyHeader,
backgroundColor: backgroundColor,
backgroundColorOddRows: backgroundColorOddRows
};
}, [size, rowSeparationStrategy, hoverable, stickyHeader, backgroundColor, backgroundColorOddRows]);
return /*#__PURE__*/React.createElement(TableContext.Provider, {
value: contextValue
}, /*#__PURE__*/React.createElement(Box, _extends({
as: "table",
tableLayout: layout,
ref: ref,
width: 1 // Make a new "stacking context" so that any absolute- / sticky-positioned
// items (like header rows) will not pollute the global z-index space.
,
position: "relative",
zIndex: 0
}, rest)));
});
export { useTable };
export default /*#__PURE__*/React.memo(Table);