Skip to content

Instantly share code, notes, and snippets.

@alegoritma
Created January 13, 2021 08:51
Show Gist options
  • Select an option

  • Save alegoritma/bd30e202a874fd89219a59df126aca97 to your computer and use it in GitHub Desktop.

Select an option

Save alegoritma/bd30e202a874fd89219a59df126aca97 to your computer and use it in GitHub Desktop.
import React, { createContext, useContext, useState } from 'react';
import {
makeStyles,
Dialog,
DialogContent,
CircularProgress,
Typography,
} from '@material-ui/core';
const PendingContext = createContext();
const useStyles = makeStyles(theme => ({
root: {
width: 'auto',
padding: '5px 15px',
},
content: {
height: 125,
display: 'flex',
justifyContent: 'center',
},
typography: {
maxWidth: 170,
},
}));
export const PendingProvider = ({children}) => {
const styles = useStyles();
const [pending, setPending] = useState(false)
return <PendingContext.Provider value={setPending}>
<Dialog
open={pending}
classes={{paper: styles.root}}
disableBackdropClick
disableEscapeKeyDown
maxWidth="xs"
>
<DialogContent className={styles.content}>
<CircularProgress size={80} thickness={3.3} />
</DialogContent>
<Typography
variant="body2"
align="center"
display="inline"
className={styles.typography}
>
{text ? text : ' '}
</Typography>
</Dialog>
{children}
</PendingContext.Provider>
}
export const usePending = () => useContext(PendingContext);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment