@@ -8,6 +8,7 @@ import { useSort } from '@table-library/react-table-library/sort';
8
8
import { usePagination } from '@table-library/react-table-library/pagination' ;
9
9
import { SelectTypes , useRowSelect } from '@table-library/react-table-library/select' ;
10
10
import styled from 'styled-components' ;
11
+ import usePresence from 'use-presence' ;
11
12
import type { TableContextType } from './TableContext' ;
12
13
import { TableProvider } from './TableContext' ;
13
14
import { ComponentIds } from './componentIds' ;
@@ -18,7 +19,7 @@ import {
18
19
tablePagination ,
19
20
} from './tokens' ;
20
21
import type { TableHeaderCellProps } from './TableHeader' ;
21
- import { makeBorderSize , useTheme } from '~utils' ;
22
+ import { makeBorderSize , makeMotionTime , useTheme } from '~utils' ;
22
23
import { getComponentId , isValidAllowedChildren } from '~utils/isValidAllowedChildren' ;
23
24
import { throwBladeError } from '~utils/logger' ;
24
25
import type { BoxProps } from '~components/Box' ;
@@ -201,6 +202,23 @@ const StyledReactTable = styled(ReactTable)<{ styledProps?: { height?: BoxProps[
201
202
} ,
202
203
) ;
203
204
205
+ const RefreshWrapper = styled ( BaseBox ) < {
206
+ isRefreshSpinnerVisible : boolean ;
207
+ isRefreshSpinnerEntering : boolean ;
208
+ isRefreshSpinnerExiting : boolean ;
209
+ } > ( ( { isRefreshSpinnerVisible, isRefreshSpinnerEntering, isRefreshSpinnerExiting, theme } ) => {
210
+ return {
211
+ opacity : isRefreshSpinnerVisible ? 1 : 0 ,
212
+ transition : `opacity ${ makeMotionTime ( theme . motion . duration . quick ) } ${
213
+ isRefreshSpinnerEntering
214
+ ? theme . motion . easing . entrance . effective
215
+ : isRefreshSpinnerExiting
216
+ ? theme . motion . easing . exit . effective
217
+ : ''
218
+ } `,
219
+ } ;
220
+ } ) ;
221
+
204
222
const Table = < Item , > ( {
205
223
children,
206
224
data,
@@ -228,6 +246,16 @@ const Table = <Item,>({
228
246
const [ totalItems , setTotalItems ] = React . useState ( data . nodes . length || 0 ) ;
229
247
// Need to make header is sticky if first column is sticky otherwise the first header cell will not be sticky
230
248
const shouldHeaderBeSticky = isHeaderSticky ?? isFirstColumnSticky ;
249
+
250
+ const {
251
+ isEntering : isRefreshSpinnerEntering ,
252
+ isMounted : isRefreshSpinnerMounted ,
253
+ isExiting : isRefreshSpinnerExiting ,
254
+ isVisible : isRefreshSpinnerVisible ,
255
+ } = usePresence ( isRefreshing , {
256
+ transitionDuration : theme . motion . duration . quick ,
257
+ } ) ;
258
+
231
259
// Table Theme
232
260
const columnCount = getTableHeaderCellCount ( children ) ;
233
261
const firstColumnStickyHeaderCellCSS = isFirstColumnSticky
@@ -503,8 +531,8 @@ const Table = <Item,>({
503
531
{ ...getStyledProps ( styledProps ) }
504
532
{ ...metaAttribute ( { name : MetaConstants . Table } ) }
505
533
>
506
- { isRefreshing && (
507
- < BaseBox
534
+ { isRefreshSpinnerMounted && (
535
+ < RefreshWrapper
508
536
position = "absolute"
509
537
width = "100%"
510
538
height = "100%"
@@ -513,9 +541,12 @@ const Table = <Item,>({
513
541
justifyContent = "center"
514
542
alignItems = "center"
515
543
display = "flex"
544
+ isRefreshSpinnerEntering = { isRefreshSpinnerEntering }
545
+ isRefreshSpinnerExiting = { isRefreshSpinnerExiting }
546
+ isRefreshSpinnerVisible = { isRefreshSpinnerVisible }
516
547
>
517
548
< Spinner color = "white" accessibilityLabel = "Refreshing Table" size = "large" />
518
- </ BaseBox >
549
+ </ RefreshWrapper >
519
550
) }
520
551
{ toolbar }
521
552
< StyledReactTable
0 commit comments