UNPKG

@itwin/itwinui-react

Version:

A react component library for iTwinUI

77 lines (76 loc) 2.27 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true, }); function _export(target, all) { for (var name in all) Object.defineProperty(target, name, { enumerable: true, get: all[name], }); } _export(exports, { TableInstanceContext: function () { return TableInstanceContext; }, getCellStyle: function () { return getCellStyle; }, getStickyStyle: function () { return getStickyStyle; }, getSubRowStyle: function () { return getSubRowStyle; }, }); const _interop_require_wildcard = require('@swc/helpers/_/_interop_require_wildcard'); const _react = /*#__PURE__*/ _interop_require_wildcard._(require('react')); const getCellStyle = (column, isTableResizing) => { let style = {}; style.flex = '1 1 145px'; if (column.width) { let width = 'string' == typeof column.width ? column.width : `${column.width}px`; style.width = width; if (isTableResizing && column.canResize) style.flex = `${Number(column.width)} ${Number(column.width)} ${width}`; else style.flex = `0 0 ${width}`; } if (column.maxWidth) style.maxWidth = `${column.maxWidth}px`; if (column.minWidth) style.minWidth = `${column.minWidth}px`; return style; }; const getStickyStyle = (column, columnList) => { if (!column.sticky) return {}; let left = 0; for (let col of columnList) { if (col.id === column.id) break; left += Number(col.width || col.resizeWidth || 0); } let right = 0; for (let col of [...columnList].reverse()) { if (col.id === column.id) break; right += Number(col.width || col.resizeWidth || 0); } return { '--iui-table-sticky-left': 'left' === column.sticky ? `${left}px` : void 0, '--iui-table-sticky-right': 'right' === column.sticky ? `${right}px` : void 0, }; }; const getSubRowStyle = ({ density = 'default', depth = 1 }) => { let cellPadding = 16; let expanderMargin = 8; if ('condensed' === density) { cellPadding = 12; expanderMargin = 4; } else if ('extra-condensed' === density) { cellPadding = 8; expanderMargin = 4; } let multiplier = 26 + expanderMargin; return { paddingInlineStart: cellPadding + depth * multiplier, }; }; const TableInstanceContext = _react.createContext(void 0);