UNPKG

@atlaskit/table-tree

Version:

A table tree is an expandable table for showing nested hierarchies of information.

29 lines • 1.13 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; var _excluded = ["width", "columnIndex"]; import React, { useContext, useEffect } from 'react'; import { TableTreeContext } from './context'; export default function withColumnWidth(Cell) { return function (props) { var _useContext = useContext(TableTreeContext), setColumnWidth = _useContext.setColumnWidth, getColumnWidth = _useContext.getColumnWidth; var width = props.width, columnIndex = props.columnIndex, other = _objectWithoutProperties(props, _excluded); useEffect(function () { if (width !== undefined && columnIndex !== undefined) { setColumnWidth(columnIndex, width); } }, [width, columnIndex, setColumnWidth]); var columnWidth; if (width !== null && width !== undefined) { columnWidth = width; } else if (columnIndex !== undefined) { columnWidth = getColumnWidth(columnIndex); } return /*#__PURE__*/React.createElement(Cell, _extends({ width: columnWidth }, other)); }; }