File tree Expand file tree Collapse file tree 5 files changed +28
-7
lines changed
apps/mantine-react-table-docs/components/prop-tables
packages/mantine-react-table/src Expand file tree Collapse file tree 5 files changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -180,7 +180,7 @@ export const stateOptions: StateOption[] = [
180180 linkText : '' ,
181181 source : 'TanStack Table' ,
182182 stateOption : 'density' ,
183- type : 'MantineSize' ,
183+ type : "'xs' | 'sm' | 'md' | 'lg' | 'xl'" ,
184184 } ,
185185 {
186186 defaultValue : 'false' ,
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import { MRT_TableDetailPanel } from './MRT_TableDetailPanel';
1717import {
1818 type MRT_Cell ,
1919 type MRT_ColumnVirtualizer ,
20+ type MRT_DensityState ,
2021 type MRT_Row ,
2122 type MRT_RowData ,
2223 type MRT_RowVirtualizer ,
@@ -120,10 +121,18 @@ export const MRT_TableBodyRow = <TData extends MRT_RowData>({
120121 const tableFooterHeight =
121122 ( enableStickyFooter && tableFooterRef . current ?. clientHeight ) || 0 ;
122123
124+ const defaultRowHeightByDensity : Record < MRT_DensityState , number > = {
125+ lg : 61 ,
126+ md : 53 ,
127+ sm : 45 ,
128+ xl : 69 ,
129+ xs : 37 ,
130+ } ;
131+
123132 const rowHeight =
124133 // @ts -ignore
125134 parseInt ( tableRowProps ?. style ?. height , 10 ) ||
126- ( density === 'xs' ? 37 : density === 'md' ? 53 : 69 ) ;
135+ ( defaultRowHeightByDensity [ density ] ?? defaultRowHeightByDensity [ 'md' ] ) ;
127136
128137 const handleDragEnter = ( _e : DragEvent ) => {
129138 if ( enableRowOrdering && draggingRow ) {
Original file line number Diff line number Diff line change @@ -13,7 +13,9 @@ interface Props<TData extends MRT_RowData>
1313 table : MRT_TableInstance < TData > ;
1414}
1515
16- const next : Record < MRT_DensityState , MRT_DensityState > = {
16+ type TogglableDensityState = Exclude < MRT_DensityState , 'lg' | 'sm' > ;
17+
18+ const next : Record < TogglableDensityState , TogglableDensityState > = {
1719 md : 'xs' ,
1820 xl : 'md' ,
1921 xs : 'xl' ,
@@ -42,7 +44,9 @@ export const MRT_ToggleDensePaddingButton = <TData extends MRT_RowData>({
4244 < ActionIcon
4345 aria-label = { title ?? toggleDensity }
4446 color = "gray"
45- onClick = { ( ) => setDensity ( ( current ) => next [ current ] ) }
47+ onClick = { ( ) =>
48+ setDensity ( ( current ) => next [ current as TogglableDensityState ] )
49+ }
4650 size = "lg"
4751 variant = "subtle"
4852 { ...rest }
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { useCallback } from 'react';
33import { type Range , useVirtualizer } from '@tanstack/react-virtual' ;
44
55import {
6+ type MRT_DensityState ,
67 type MRT_Row ,
78 type MRT_RowData ,
89 type MRT_RowVirtualizer ,
@@ -40,8 +41,16 @@ export const useMRT_RowVirtualizer = <
4041
4142 const rowCount = rows ?. length ?? getRowModel ( ) . rows . length ;
4243
44+ const defaultRowHeightByDensity : Record < MRT_DensityState , number > = {
45+ lg : 62.7 ,
46+ md : 54.7 ,
47+ sm : 48.7 ,
48+ xl : 70.7 ,
49+ xs : 42.7 ,
50+ } ;
51+
4352 const normalRowHeight =
44- density === 'xs' ? 42.7 : density === 'md' ? 54.7 : 70.7 ;
53+ defaultRowHeightByDensity [ density ] ?? defaultRowHeightByDensity [ 'md' ] ;
4554
4655 const rowVirtualizer = useVirtualizer ( {
4756 count : renderDetailPanel ? rowCount * 2 : rowCount ,
Original file line number Diff line number Diff line change @@ -52,7 +52,6 @@ import {
5252 type CheckboxProps ,
5353 type HighlightProps ,
5454 type LoadingOverlayProps ,
55- type MantineSize ,
5655 type ModalProps ,
5756 type MultiSelectProps ,
5857 type PaginationProps ,
@@ -106,7 +105,7 @@ export type MRT_PaginationProps = {
106105 showRowsPerPage ?: boolean ;
107106} & Partial < PaginationProps > ;
108107
109- export type MRT_DensityState = MantineSize ;
108+ export type MRT_DensityState = 'lg' | 'md' | 'sm' | 'xl' | 'xs' ;
110109
111110export type MRT_ColumnFilterFnsState = Record < string , MRT_FilterOption > ;
112111
You can’t perform that action at this time.
0 commit comments