UNPKG

@wix/design-system

Version:

@wix/design-system

42 lines 1.97 kB
import shallowEqual from 'shallowequal'; import { stVars } from './DataTable.st.css.js'; export function virtualRowsAreEqual(prevProps, nextProps) { const { style: prevStyle, data: prevData, index: prevIndex, ...prevRest } = prevProps; const { style: nextStyle, data: nextData, index: nextIndex, ...nextRest } = nextProps; const { data: nextItemData, ...restNextItemData } = nextData; const { data: prevItemData, ...restPrevItemData } = prevData; return (nextIndex === prevIndex && shallowEqual(prevStyle, nextStyle) && shallowEqual(prevItemData[prevIndex], nextItemData[nextIndex]) && shallowEqual(restPrevItemData, restNextItemData) && shallowEqual(prevRest, nextRest)); } export const CELL_PADDING = parseInt(stVars.cellHorizontalPadding, 10); export const CELL_EDGE_PADDING = parseInt(stVars.cellHorizontalEdgePadding, 10); /** * The cell padding is themeable, so the offset has to stay symbolic — a number * computed from CELL_PADDING would misplace sticky columns in themes that * resolve `--wds-table-cell-padding-inline` to anything other than 12px. */ export const getStickyColumnOffset = (widths, cellPaddings, edgePaddings) => `calc(${widths}px + ${edgePaddings * CELL_EDGE_PADDING}px + ${cellPaddings} * var(--wds-table-cell-padding-inline, ${CELL_PADDING}px))`; export const getStickyColumnStyle = (columns, column, getColumnWidth = col => parseInt(col.width, 10)) => { let widths = 0; let cellPaddings = 0; let edgePaddings = 0; for (let i = 0; i < columns.length; i++) { const col = columns[i]; if (col === column) { break; } if (i === 0) { edgePaddings += 1; cellPaddings += 1; } else { cellPaddings += 2; } widths += getColumnWidth(col); } return { left: getStickyColumnOffset(widths, cellPaddings, edgePaddings) }; }; //# sourceMappingURL=DataTable.utils.js.map