UNPKG

@itwin/itwinui-react

Version:

A react component library for iTwinUI

51 lines (50 loc) 1.65 kB
import * as React from 'react'; export 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; }; export 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, }; }; export 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, }; }; export const TableInstanceContext = React.createContext(void 0);