-
Notifications
You must be signed in to change notification settings - Fork 576
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Select panel] Loading states re-submission (#5139)
* Revert "Revert "Select panel loading states (#4929)" (#5136)" This reverts commit f93eb9b. * Use published primer/behaviors * Revert snapshot change to TextInput * Huh ok never mind * Use role in test * Prevent active descendant from resetting when items change * Allow loading state to be managed by the user * Encounter the loading state for the initial state announcement * It's working * Cleanup * Fix linting issues * Revert snapshots * test(vrt): update snapshots * Backport #5551 to this PR * Fix auto-focus behavior * Add test to ensure focus behavior * Allow consumers to pass an inputRef; DRY up timeout cleanup; simplify nullish coercion * DRY up announcement code; restore useAnnouncements hook for non-SelectPanel cases * Fix types tests * Remove testing ID * Remove confusing componentManagesLoading control in async story --------- Co-authored-by: Cameron Dutro <[email protected]> Co-authored-by: francinelucca <[email protected]> Co-authored-by: Marie Lucca <[email protected]>
- Loading branch information
1 parent
b48b520
commit 59e0efa
Showing
28 changed files
with
615 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@primer/react': minor | ||
--- | ||
|
||
[SelectPanel] Implement loading states |
Binary file modified
BIN
+10 Bytes
(100%)
...el-Height-Initial-with-Underflowing-Items-After-Fetch-dark-colorblind-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+10 Bytes
(100%)
...derflowing-Items-After-Fetch-dark-colorblind-modern-action-list--true-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5 Bytes
(100%)
...tPanel-Height-Initial-with-Underflowing-Items-After-Fetch-dark-dimmed-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5 Bytes
(100%)
...h-Underflowing-Items-After-Fetch-dark-dimmed-modern-action-list--true-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+2 Bytes
(100%)
...Height-Initial-with-Underflowing-Items-After-Fetch-dark-high-contrast-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+2 Bytes
(100%)
...flowing-Items-After-Fetch-dark-high-contrast-modern-action-list--true-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+10 Bytes
(100%)
...s/SelectPanel-Height-Initial-with-Underflowing-Items-After-Fetch-dark-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+10 Bytes
(100%)
...ial-with-Underflowing-Items-After-Fetch-dark-modern-action-list--true-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+10 Bytes
(100%)
...el-Height-Initial-with-Underflowing-Items-After-Fetch-dark-tritanopia-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+10 Bytes
(100%)
...derflowing-Items-After-Fetch-dark-tritanopia-modern-action-list--true-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-4 Bytes
(100%)
...l-Height-Initial-with-Underflowing-Items-After-Fetch-light-colorblind-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-9 Bytes
(100%)
...erflowing-Items-After-Fetch-light-colorblind-modern-action-list--true-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-7 Bytes
(100%)
...eight-Initial-with-Underflowing-Items-After-Fetch-light-high-contrast-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-6 Bytes
(100%)
...lowing-Items-After-Fetch-light-high-contrast-modern-action-list--true-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-9 Bytes
(100%)
.../SelectPanel-Height-Initial-with-Underflowing-Items-After-Fetch-light-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-9 Bytes
(100%)
...al-with-Underflowing-Items-After-Fetch-light-modern-action-list--true-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-9 Bytes
(100%)
...l-Height-Initial-with-Underflowing-Items-After-Fetch-light-tritanopia-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-9 Bytes
(100%)
...erflowing-Items-After-Fetch-light-tritanopia-modern-action-list--true-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 66 additions & 0 deletions
66
packages/react/src/FilteredActionList/FilteredActionListLoaders.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React from 'react' | ||
import Box from '../Box' | ||
import Spinner from '../Spinner' | ||
import {Stack} from '../Stack/Stack' | ||
import {SkeletonBox} from '../experimental/Skeleton/SkeletonBox' | ||
|
||
export class FilteredActionListLoadingType { | ||
public name: string | ||
public appearsInBody: boolean | ||
|
||
constructor(name: string, appearsInBody: boolean) { | ||
this.name = name | ||
this.appearsInBody = appearsInBody | ||
} | ||
} | ||
|
||
export const FilteredActionListLoadingTypes = { | ||
bodySpinner: new FilteredActionListLoadingType('body-spinner', true), | ||
bodySkeleton: new FilteredActionListLoadingType('body-skeleton', true), | ||
input: new FilteredActionListLoadingType('input', false), | ||
} | ||
|
||
const SKELETON_ROW_HEIGHT = 24 | ||
const SKELETON_MIN_ROWS = 3 | ||
|
||
export function FilteredActionListBodyLoader({ | ||
loadingType, | ||
height, | ||
}: { | ||
loadingType: FilteredActionListLoadingType | ||
height: number | ||
}): JSX.Element { | ||
switch (loadingType) { | ||
case FilteredActionListLoadingTypes.bodySpinner: | ||
return <LoadingSpinner data-testid="filtered-action-list-spinner" /> | ||
case FilteredActionListLoadingTypes.bodySkeleton: { | ||
const rows = height < SKELETON_ROW_HEIGHT ? SKELETON_MIN_ROWS : height / SKELETON_ROW_HEIGHT | ||
return <LoadingSkeleton data-testid="filtered-action-list-skeleton" rows={rows} /> | ||
} | ||
default: | ||
return <></> | ||
} | ||
} | ||
|
||
function LoadingSpinner({...props}): JSX.Element { | ||
return ( | ||
<Box p={3} flexGrow={1} sx={{alignContent: 'center', textAlign: 'center', height: '100%'}}> | ||
<Spinner {...props} /> | ||
</Box> | ||
) | ||
} | ||
|
||
function LoadingSkeleton({rows = 10, ...props}: {rows: number}): JSX.Element { | ||
return ( | ||
<Box p={2} display="flex" flexGrow={1} flexDirection="column"> | ||
<Stack direction="vertical" justify="center" gap="condensed" {...props}> | ||
{Array.from({length: rows}, (_, i) => ( | ||
<Stack key={i} direction="horizontal" gap="condensed" align="center"> | ||
<SkeletonBox width="16px" height="16px" /> | ||
<SkeletonBox height="10px" width={`${Math.random() * 60 + 20}%`} sx={{borderRadius: '4px'}} /> | ||
</Stack> | ||
))} | ||
</Stack> | ||
</Box> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.