Skip to content

Commit 747d2c1

Browse files
Merge remote-tracking branch 'origin/feat/table-component' into feat/table-component-documentation
2 parents 4c4ba34 + b995c01 commit 747d2c1

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

packages/blade/src/components/Table/Table.web.tsx

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useSort } from '@table-library/react-table-library/sort';
88
import { usePagination } from '@table-library/react-table-library/pagination';
99
import { SelectTypes, useRowSelect } from '@table-library/react-table-library/select';
1010
import styled from 'styled-components';
11+
import usePresence from 'use-presence';
1112
import type { TableContextType } from './TableContext';
1213
import { TableProvider } from './TableContext';
1314
import { ComponentIds } from './componentIds';
@@ -18,7 +19,7 @@ import {
1819
tablePagination,
1920
} from './tokens';
2021
import type { TableHeaderCellProps } from './TableHeader';
21-
import { makeBorderSize, useTheme } from '~utils';
22+
import { makeBorderSize, makeMotionTime, useTheme } from '~utils';
2223
import { getComponentId, isValidAllowedChildren } from '~utils/isValidAllowedChildren';
2324
import { throwBladeError } from '~utils/logger';
2425
import type { BoxProps } from '~components/Box';
@@ -201,6 +202,23 @@ const StyledReactTable = styled(ReactTable)<{ styledProps?: { height?: BoxProps[
201202
},
202203
);
203204

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+
204222
const Table = <Item,>({
205223
children,
206224
data,
@@ -228,6 +246,16 @@ const Table = <Item,>({
228246
const [totalItems, setTotalItems] = React.useState(data.nodes.length || 0);
229247
// Need to make header is sticky if first column is sticky otherwise the first header cell will not be sticky
230248
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+
231259
// Table Theme
232260
const columnCount = getTableHeaderCellCount(children);
233261
const firstColumnStickyHeaderCellCSS = isFirstColumnSticky
@@ -503,8 +531,8 @@ const Table = <Item,>({
503531
{...getStyledProps(styledProps)}
504532
{...metaAttribute({ name: MetaConstants.Table })}
505533
>
506-
{isRefreshing && (
507-
<BaseBox
534+
{isRefreshSpinnerMounted && (
535+
<RefreshWrapper
508536
position="absolute"
509537
width="100%"
510538
height="100%"
@@ -513,9 +541,12 @@ const Table = <Item,>({
513541
justifyContent="center"
514542
alignItems="center"
515543
display="flex"
544+
isRefreshSpinnerEntering={isRefreshSpinnerEntering}
545+
isRefreshSpinnerExiting={isRefreshSpinnerExiting}
546+
isRefreshSpinnerVisible={isRefreshSpinnerVisible}
516547
>
517548
<Spinner color="white" accessibilityLabel="Refreshing Table" size="large" />
518-
</BaseBox>
549+
</RefreshWrapper>
519550
)}
520551
{toolbar}
521552
<StyledReactTable

0 commit comments

Comments
 (0)