From d46675844b8fb8ea754b7e26b2ffe0efd372bc10 Mon Sep 17 00:00:00 2001 From: Jay Laiche Date: Fri, 29 Mar 2024 17:08:15 +0000 Subject: [PATCH] feat(react): use native CSS transition for IndexTable loading --- .changeset/wild-sloths-begin.md | 5 ++ .../IndexTable/IndexTable.module.css | 38 +++++------- .../IndexTable/IndexTable.stories.tsx | 61 ++++++++++--------- .../src/components/IndexTable/IndexTable.tsx | 48 +++++---------- 4 files changed, 68 insertions(+), 84 deletions(-) create mode 100644 .changeset/wild-sloths-begin.md diff --git a/.changeset/wild-sloths-begin.md b/.changeset/wild-sloths-begin.md new file mode 100644 index 00000000000..26e2a5e7728 --- /dev/null +++ b/.changeset/wild-sloths-begin.md @@ -0,0 +1,5 @@ +--- +'@shopify/polaris': patch +--- + +Fixed `IndexTable` `loading` prop to correctly show/hide loading UI when prop value changes diff --git a/polaris-react/src/components/IndexTable/IndexTable.module.css b/polaris-react/src/components/IndexTable/IndexTable.module.css index 7433a4d8333..483223485ca 100644 --- a/polaris-react/src/components/IndexTable/IndexTable.module.css +++ b/polaris-react/src/components/IndexTable/IndexTable.module.css @@ -34,30 +34,6 @@ border-radius: 0; } -.LoadingContainer-enter { - opacity: 0; - transform: translateY(-100%); -} - -.LoadingContainer-enter-active { - opacity: 1; - transition: opacity var(--p-motion-duration-100) var(--p-motion-ease-out), - transform var(--p-motion-duration-100) var(--p-motion-ease-out); - transform: translateY(0); -} - -.LoadingContainer-exit { - opacity: 1; - transform: translateY(0); -} - -.LoadingContainer-exit-active { - opacity: 0; - transform: translateY(-100%); - transition: opacity var(--p-motion-duration-100) var(--p-motion-ease-in), - transform var(--p-motion-duration-100) var(--p-motion-ease-in); -} - .LoadingPanel { position: absolute; z-index: var(--p-z-index-2); @@ -70,6 +46,20 @@ background: var(--p-color-bg-surface); padding: var(--p-space-200) var(--p-space-400); box-shadow: var(--p-shadow-300); + opacity: 0; + transform: translateY(-100%); + transition: opacity var(--p-motion-duration-100) var(--p-motion-ease-in), + transform var(--p-motion-duration-100) var(--p-motion-ease-in), + visibility 0s linear var(--p-motion-duration-100); + visibility: hidden; + + &.LoadingPanelEntered { + visibility: visible; + opacity: 1; + transform: translateY(0); + transition: opacity var(--p-motion-duration-100) var(--p-motion-ease-out), + transform var(--p-motion-duration-100) var(--p-motion-ease-out); + } .LoadingPanelRow { display: flex; diff --git a/polaris-react/src/components/IndexTable/IndexTable.stories.tsx b/polaris-react/src/components/IndexTable/IndexTable.stories.tsx index 1823695d249..5f9fe6db789 100644 --- a/polaris-react/src/components/IndexTable/IndexTable.stories.tsx +++ b/polaris-react/src/components/IndexTable/IndexTable.stories.tsx @@ -1491,6 +1491,8 @@ export function WithBulkActionsAndSelectionAcrossPages() { } export function WithLoadingState() { + const [loading, setLoading] = useState(true); + const customers = [ { id: '3410', @@ -1574,34 +1576,37 @@ export function WithLoadingState() { ); return ( - - - {rowMarkup} - - + <> + + + + {rowMarkup} + + + ); } diff --git a/polaris-react/src/components/IndexTable/IndexTable.tsx b/polaris-react/src/components/IndexTable/IndexTable.tsx index 0010a282b60..bdf62c7a31d 100644 --- a/polaris-react/src/components/IndexTable/IndexTable.tsx +++ b/polaris-react/src/components/IndexTable/IndexTable.tsx @@ -1,6 +1,5 @@ import React, {useRef, useState, useEffect, useCallback, useMemo} from 'react'; import {SortAscendingIcon, SortDescendingIcon} from '@shopify/polaris-icons'; -import {CSSTransition} from 'react-transition-group'; import {themeDefault, toPx} from '@shopify/polaris-tokens'; import type {SpaceScale} from '@shopify/polaris-tokens'; @@ -41,7 +40,6 @@ import type { Width, TooltipOverlayProps, } from '../Tooltip'; -import {useTheme} from '../../utilities/use-theme'; import {getTableHeadingsBySelector} from './utilities'; import {ScrollContainer, Cell, Row} from './components'; @@ -156,8 +154,6 @@ function IndexTableBase({ pagination, ...restProps }: IndexTableBaseProps) { - const theme = useTheme(); - const { loading, bulkSelectState, @@ -184,7 +180,6 @@ function IndexTableBase({ const tableElement = useRef(null); const tableBodyElement = useRef(null); const condensedListElement = useRef(null); - const loadingElement = useRef(null); const [tableInitialized, setTableInitialized] = useState(false); const [stickyWrapper, setStickyWrapper] = useState(null); @@ -541,36 +536,25 @@ function IndexTableBase({ const paginatedSelectAllAction = getPaginatedSelectAllAction(); - const loadingTransitionClassNames = { - enter: styles['LoadingContainer-enter'], - enterActive: styles['LoadingContainer-enter-active'], - exit: styles['LoadingContainer-exit'], - exitActive: styles['LoadingContainer-exit-active'], - }; - const loadingMarkup = ( - -
-
- - - {i18n.translate( - 'Polaris.IndexTable.resourceLoadingAccessibilityLabel', - { - resourceNamePlural: resourceName.plural.toLocaleLowerCase(), - }, - )} - -
+
+ + + {i18n.translate( + 'Polaris.IndexTable.resourceLoadingAccessibilityLabel', + { + resourceNamePlural: resourceName.plural.toLocaleLowerCase(), + }, + )} +
- +
); const stickyTableClassNames = classNames(