UNPKG

@1771technologies/lytenyte-pro

Version:

Blazingly fast headless React data grid with 100s of features.

46 lines (45 loc) 1.9 kB
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime"; import { COLUMN_MARKER_ID } from "@1771technologies/lytenyte-shared"; import { itemsWithIdToMap } from "@1771technologies/lytenyte-shared"; export function columnHandleMarker({ columns, marker, markerEnabled, }) { const lookup = itemsWithIdToMap(columns); if (markerEnabled && !lookup.has(COLUMN_MARKER_ID)) { columns = [ { id: COLUMN_MARKER_ID, name: "", pin: "start", width: marker.width ?? 30, widthMin: 24, cellRenderer: marker.cellRenderer, headerRenderer: marker.headerRenderer ?? HeaderRenderer, floatingCellRenderer: marker.floatingCellRenderer ?? FloatingRenderer, uiHints: marker.uiHints, }, ...columns, ]; lookup.set(COLUMN_MARKER_ID, columns[0]); } else if (!markerEnabled && lookup.has(COLUMN_MARKER_ID)) { const index = columns.findIndex((c) => c.id === COLUMN_MARKER_ID); columns.splice(index, 1); } if (markerEnabled) { const column = lookup.get(COLUMN_MARKER_ID); // The marker column must always be the first column displayed in the grid. const index = columns.findIndex((c) => c.id === COLUMN_MARKER_ID); if (index !== 0) { columns.splice(index, 1); columns.unshift(column); } } return columns; } // eslint-disable-next-line react-refresh/only-export-components function HeaderRenderer() { return (_jsx(_Fragment, { children: _jsx("div", { style: { overflow: "hidden", opacity: 0, width: "100%", height: "100%" }, children: "Marker column default" }) })); } // eslint-disable-next-line react-refresh/only-export-components function FloatingRenderer() { return _jsx(_Fragment, {}); }