@atlaskit/table-tree
Version:
A table tree is an expandable table for showing nested hierarchies of information.
30 lines • 876 B
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import React, { useContext, useEffect } from 'react';
import { TableTreeContext } from './context';
export default function withColumnWidth(Cell) {
return props => {
const {
setColumnWidth,
getColumnWidth
} = useContext(TableTreeContext);
const {
width,
columnIndex,
...other
} = props;
useEffect(() => {
if (width !== undefined && columnIndex !== undefined) {
setColumnWidth(columnIndex, width);
}
}, [width, columnIndex, setColumnWidth]);
let columnWidth;
if (width !== null && width !== undefined) {
columnWidth = width;
} else if (columnIndex !== undefined) {
columnWidth = getColumnWidth(columnIndex);
}
return /*#__PURE__*/React.createElement(Cell, _extends({
width: columnWidth
}, other));
};
}