-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstraction for displaying components delayed
New DelayedLoadingOverlay
- Loading branch information
1 parent
8549053
commit ef702fb
Showing
8 changed files
with
59 additions
and
35 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,33 @@ | ||
import {useEffect, useState} from 'react'; | ||
import {LoadingOverlayProps, SkeletonProps} from '@mantine/core'; | ||
|
||
type DelayedComponentProps = SkeletonProps | LoadingOverlayProps; | ||
type DelayedProps<ComponentProps extends DelayedComponentProps> = ComponentProps & { | ||
component: any; | ||
}; | ||
|
||
/** | ||
* Shows children after this delay | ||
*/ | ||
const DELAY = 700; | ||
|
||
/** | ||
* Shows children after a delay of {@link DELAY}ms | ||
*/ | ||
export function Delayed<ComponentProps extends DelayedComponentProps>(props: DelayedProps<ComponentProps>): JSX.Element { | ||
const {component: DelayedComponent, ...componentProps} = props; | ||
|
||
const [visible, setVisible] = useState(false); | ||
|
||
useEffect(() => { | ||
const timer = setTimeout(() => setVisible(true), DELAY); | ||
return (): void => { | ||
clearTimeout(timer); | ||
}; | ||
}, [componentProps]); | ||
|
||
if (visible) { | ||
return <DelayedComponent {...componentProps}/>; | ||
} | ||
return <></>; | ||
} |
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,11 @@ | ||
import {LoadingOverlay, LoadingOverlayProps} from '@mantine/core'; | ||
import {Delayed} from './Delayed'; | ||
|
||
/** | ||
* Shows a loading overlay after a delay | ||
* | ||
* @see {@link Delayed} | ||
*/ | ||
export function DelayedLoadingOverlay(props: LoadingOverlayProps): JSX.Element { | ||
return <Delayed component={LoadingOverlay} {...props}/>; | ||
} |
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,11 @@ | ||
import {Skeleton, SkeletonProps} from '@mantine/core'; | ||
import {Delayed} from './Delayed'; | ||
|
||
/** | ||
* Shows a skeleton after a delay | ||
* | ||
* @see {@link Delayed} | ||
*/ | ||
export function DelayedSkeleton(props: SkeletonProps): JSX.Element { | ||
return <Delayed component={Skeleton} {...props}/>; | ||
} |
This file was deleted.
Oops, something went wrong.
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
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