diff --git a/package.json b/package.json index 5f35cc48..8111c9fe 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "test": "vitest", "dev": "vite", "generate-tokens": "node build-tokens.js", + "typecheck": "tsc --noEmit", "build": "tsc && vite build", "build:watch": "watch 'npm run build' ./src", "lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0", diff --git a/src/components/Grid/Cell.tsx b/src/components/Grid/Cell.tsx index 03cb5b2e..a107e287 100644 --- a/src/components/Grid/Cell.tsx +++ b/src/components/Grid/Cell.tsx @@ -3,6 +3,10 @@ import { GridChildComponentProps, areEqual } from "react-window"; import { ItemDataType } from "./types"; import { StyledCell } from "./StyledCell"; +type CellProps = GridChildComponentProps & { + width: number; +} + export const Cell = memo( ({ data, @@ -10,7 +14,7 @@ export const Cell = memo( columnIndex, style, ...props - }: GridChildComponentProps) => { + }: CellProps) => { const { cell: CellData, getSelectionType, diff --git a/src/components/Grid/Grid.stories.tsx b/src/components/Grid/Grid.stories.tsx index 6e718a75..9cbd5767 100644 --- a/src/components/Grid/Grid.stories.tsx +++ b/src/components/Grid/Grid.stories.tsx @@ -2,13 +2,13 @@ import { useCallback, useEffect, useState } from "react"; import { CellProps, GridContextMenuItemProps, SelectedRegion, SelectionFocus } from ".."; import { Grid as CUIGrid } from "./Grid"; -const Cell: CellProps = ({ type, rowIndex, columnIndex, isScrolling, ...props }) => { +const Cell: CellProps = ({ type, rowIndex, columnIndex, isScrolling, width, ...props }) => { return (
- {rowIndex} {columnIndex} - {type} + {rowIndex} {columnIndex} - {type} - {width}px
); }; diff --git a/src/components/Grid/Grid.tsx b/src/components/Grid/Grid.tsx index d4ea9b56..fef156b9 100644 --- a/src/components/Grid/Grid.tsx +++ b/src/components/Grid/Grid.tsx @@ -15,6 +15,7 @@ import { GridOnScrollProps, VariableSizeGrid, GridOnItemsRenderedProps, + GridChildComponentProps, } from "react-window"; import AutoSizer, { Size } from "react-virtualized-auto-sizer"; import RowNumberColumn from "./RowNumberColumn"; @@ -771,6 +772,16 @@ export const Grid = forwardRef( } }, [rowStart, onItemsRendered]); + const CellWithWidth = (args: GridChildComponentProps): JSX.Element => { + const width = columnWidth(args.columnIndex); + return ( + + ); + } + return ( ( onItemsRendered={onItemsRendered} {...props} > - {Cell} + {CellWithWidth} )} diff --git a/src/components/Grid/Header.tsx b/src/components/Grid/Header.tsx index 96963242..5d684b1e 100644 --- a/src/components/Grid/Header.tsx +++ b/src/components/Grid/Header.tsx @@ -151,6 +151,7 @@ const Column = ({ data-grid-column={columnIndex} data-selected={isSelected} $showBorder={showBorder} + width={columnWidth(columnIndex)} /> { interface CellHeaderProps extends CellCommonProps { rowIndex?: never; type: "header-cell"; + width: number; } interface CellBodyProps extends CellCommonProps { rowIndex: number; type: "row-cell"; + width: number; } type CellComponentProps = CellHeaderProps | CellBodyProps; diff --git a/src/examples/GridExample.tsx b/src/examples/GridExample.tsx index be791601..931d879f 100644 --- a/src/examples/GridExample.tsx +++ b/src/examples/GridExample.tsx @@ -8,13 +8,13 @@ import { Pagination, } from ".."; -const Cell: CellProps = ({ type, rowIndex, columnIndex, isScrolling, ...props }) => { +const Cell: CellProps = ({ type, rowIndex, columnIndex, isScrolling, width, ...props }) => { return ( - {rowIndex} {columnIndex} - {type} + {rowIndex} {columnIndex} - {type} {width}px ); };