@@ -28,6 +28,7 @@ import type {
28
28
TablePaginationType ,
29
29
TableHeaderRowProps ,
30
30
} from './types' ;
31
+ import { getTableBodyStyles } from './commonStyles' ;
31
32
import { makeBorderSize , makeMotionTime } from '~utils' ;
32
33
import { getComponentId , isValidAllowedChildren } from '~utils/isValidAllowedChildren' ;
33
34
import { throwBladeError } from '~utils/logger' ;
@@ -87,21 +88,42 @@ const getTableHeaderCellCount = (children: (data: []) => React.ReactElement): nu
87
88
return 0 ;
88
89
} ;
89
90
90
- const StyledReactTable = styled ( ReactTable ) < { $styledProps ?: { height ?: BoxProps [ 'height' ] } } > (
91
- ( { $styledProps } ) => {
92
- const { theme } = useTheme ( ) ;
93
- const styledPropsCSSObject = getBaseBoxStyles ( {
94
- theme,
95
- height : $styledProps ?. height ,
96
- } ) ;
97
-
98
- return {
99
- '&&&' : {
100
- ...styledPropsCSSObject ,
101
- } ,
102
- } ;
103
- } ,
104
- ) ;
91
+ const StyledReactTable = styled ( ReactTable ) < {
92
+ $styledProps ?: {
93
+ height ?: BoxProps [ 'height' ] ;
94
+ width ?: BoxProps [ 'width' ] ;
95
+ isVirtualized ?: boolean ;
96
+ isSelectable ?: boolean ;
97
+ showStripedRows ?: boolean ;
98
+ } ;
99
+ } > ( ( { $styledProps } ) => {
100
+ const { theme } = useTheme ( ) ;
101
+ const styledPropsCSSObject = getBaseBoxStyles ( {
102
+ theme,
103
+ height : $styledProps ?. height ,
104
+ ...( $styledProps ?. isVirtualized && {
105
+ width : '100%' ,
106
+ } ) ,
107
+ } ) ;
108
+ const $isSelectable = $styledProps ?. isSelectable ;
109
+ const $showStripedRows = $styledProps ?. showStripedRows ;
110
+ return {
111
+ '&&&' : {
112
+ ...styledPropsCSSObject ,
113
+ overflow : `${ $styledProps ?. isVirtualized ? 'unset' : 'auto' } !important` ,
114
+ } ,
115
+ ...( $styledProps ?. isVirtualized
116
+ ? getTableBodyStyles ( {
117
+ isVirtualized : $styledProps ?. isVirtualized ,
118
+ theme,
119
+ height : $styledProps ?. height ,
120
+ width : '100%' ,
121
+ isSelectable : $isSelectable ,
122
+ showStripedRows : $showStripedRows ,
123
+ } )
124
+ : null ) ,
125
+ } ;
126
+ } ) ;
105
127
106
128
const RefreshWrapper = styled ( BaseBox ) < {
107
129
isRefreshSpinnerVisible : boolean ;
@@ -156,8 +178,10 @@ const _Table = <Item,>({
156
178
undefined ,
157
179
) ;
158
180
const [ hasHoverActions , setHasHoverActions ] = React . useState ( false ) ;
181
+ const tableRootComponent = children ( [ ] ) ;
182
+ const isVirtualized = getComponentId ( tableRootComponent ) === ComponentIds . VirtualizedTable ;
159
183
// Need to make header is sticky if first column is sticky otherwise the first header cell will not be sticky
160
- const shouldHeaderBeSticky = isHeaderSticky ?? isFirstColumnSticky ;
184
+ const shouldHeaderBeSticky = isVirtualized ?? isHeaderSticky ?? isFirstColumnSticky ;
161
185
const backgroundColor = tableBackgroundColor ;
162
186
163
187
const isMobile = useIsMobile ( ) ;
@@ -265,7 +289,7 @@ const _Table = <Item,>({
265
289
} , [ data . nodes ] ) ;
266
290
267
291
// Selection Logic
268
- const onSelectChange : MiddlewareFunction = ( action , state ) : void => {
292
+ const onSelectChange : MiddlewareFunction = ( _ , state ) : void => {
269
293
const selectedIds : Identifier [ ] = state . id ? [ state . id ] : state . ids ?? [ ] ;
270
294
setSelectedRows ( selectedIds ) ;
271
295
onSelectionChange ?.( {
@@ -323,7 +347,7 @@ const _Table = <Item,>({
323
347
) ;
324
348
325
349
// Sort Logic
326
- const handleSortChange : MiddlewareFunction = ( action , state ) => {
350
+ const handleSortChange : MiddlewareFunction = ( _ , state ) => {
327
351
onSortChange ?.( {
328
352
sortKey : state . sortKey ,
329
353
isSortReversed : state . reverse ,
@@ -341,7 +365,7 @@ const _Table = <Item,>({
341
365
} ,
342
366
) ;
343
367
344
- const currentSortedState : TableContextType [ 'currentSortedState' ] = useMemo ( ( ) => {
368
+ const currentSortedState : TableContextType < Item > [ 'currentSortedState' ] = useMemo ( ( ) => {
345
369
return {
346
370
sortKey : sort . state . sortKey ,
347
371
isSortReversed : sort . state . reverse ,
@@ -409,7 +433,7 @@ const _Table = <Item,>({
409
433
}
410
434
411
435
// Table Context
412
- const tableContext : TableContextType = useMemo (
436
+ const tableContext : TableContextType < Item > = useMemo (
413
437
( ) => ( {
414
438
selectionType,
415
439
selectedRows,
@@ -434,6 +458,10 @@ const _Table = <Item,>({
434
458
showBorderedCells,
435
459
hasHoverActions,
436
460
setHasHoverActions,
461
+ columnCount,
462
+ gridTemplateColumns,
463
+ isVirtualized,
464
+ tableData : data . nodes ,
437
465
} ) ,
438
466
[
439
467
selectionType ,
@@ -442,8 +470,10 @@ const _Table = <Item,>({
442
470
toggleRowSelectionById ,
443
471
toggleAllRowsSelection ,
444
472
deselectAllRows ,
473
+ gridTemplateColumns ,
445
474
rowDensity ,
446
475
toggleSort ,
476
+ columnCount ,
447
477
currentSortedState ,
448
478
setPaginationPage ,
449
479
setPaginationRowSize ,
@@ -459,6 +489,8 @@ const _Table = <Item,>({
459
489
showBorderedCells ,
460
490
hasHoverActions ,
461
491
setHasHoverActions ,
492
+ isVirtualized ,
493
+ data ,
462
494
] ,
463
495
) ;
464
496
@@ -484,6 +516,7 @@ const _Table = <Item,>({
484
516
position = "relative"
485
517
{ ...getStyledProps ( rest ) }
486
518
{ ...metaAttribute ( { name : MetaConstants . Table } ) }
519
+ width = { isVirtualized ? `100%` : undefined }
487
520
>
488
521
{ isRefreshSpinnerMounted && (
489
522
< RefreshWrapper
@@ -513,6 +546,10 @@ const _Table = <Item,>({
513
546
sort = { sortFunctions ? sort : null }
514
547
$styledProps = { {
515
548
height,
549
+ width : isVirtualized ? `100%` : undefined ,
550
+ isVirtualized,
551
+ isSelectable : selectionType !== 'none' ,
552
+ showStripedRows,
516
553
} }
517
554
pagination = { hasPagination ? paginationConfig : null }
518
555
{ ...makeAccessible ( { multiSelectable : selectionType === 'multiple' } ) }
@@ -527,7 +564,6 @@ const _Table = <Item,>({
527
564
</ TableContext . Provider >
528
565
) ;
529
566
} ;
530
-
531
567
const Table = assignWithoutSideEffects ( _Table , {
532
568
componentId : ComponentIds . Table ,
533
569
} ) ;
0 commit comments