-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add toaster if create instance failed (#39)
add toaster if create instance failed
- Loading branch information
1 parent
0edca73
commit 76cb991
Showing
9 changed files
with
199 additions
and
13 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {VariantType} from 'notistack'; | ||
|
||
export interface SnackbarProps { | ||
variant: VariantType; | ||
message: string; | ||
key: string | number; | ||
} |
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,68 @@ | ||
import {makeStyles, Theme} from '@material-ui/core/styles'; | ||
|
||
import {VariantType} from 'notistack'; | ||
|
||
interface VariantProps { | ||
variant: VariantType; | ||
} | ||
|
||
export const useStyles = makeStyles<Theme, VariantProps>(theme => ({ | ||
root: { | ||
maxWidth: 600, | ||
[theme.breakpoints.up('sm')]: { | ||
minWidth: '344px !important', | ||
// maxWidth: '344px !important', | ||
}, | ||
}, | ||
card: { | ||
backgroundColor: props => | ||
props?.variant === 'success' | ||
? '#47B881' | ||
: props?.variant === 'error' | ||
? '#FE3636' | ||
: props?.variant === 'warning' | ||
? '#F0A200' | ||
: props?.variant === 'info' | ||
? '#1070CA' | ||
: '#FFFFFF', | ||
width: '100%', | ||
height: '60px', | ||
paddingLeft: 8, | ||
borderRadius: 10, | ||
}, | ||
cardInside: { | ||
backgroundColor: '#FFFFFF', | ||
width: '100%', | ||
height: '100%', | ||
borderTopRightRadius: 10, | ||
borderBottomRightRadius: 10, | ||
display: 'flex', | ||
alignItems: 'center', | ||
paddingLeft: 15, | ||
}, | ||
typography: { | ||
fontWeight: 'normal', | ||
lineHeight: '17.57px', | ||
}, | ||
icons: { | ||
marginLeft: 'auto', | ||
}, | ||
iconLeft: { | ||
marginRight: '12px', | ||
fill: props => | ||
props?.variant === 'success' | ||
? '#47B881' | ||
: props?.variant === 'error' | ||
? '#FE3636' | ||
: props?.variant === 'warning' | ||
? '#F0A200' | ||
: props?.variant === 'info' | ||
? '#1070CA' | ||
: '#FFFFFF', | ||
}, | ||
iconClose: { | ||
marginRight: '5px', | ||
marginLeft: '5px', | ||
fill: '#66788A', | ||
}, | ||
})); |
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,65 @@ | ||
import { | ||
ExclamationIcon, | ||
CheckCircleIcon, | ||
ExclamationCircleIcon, | ||
InformationCircleIcon, | ||
QuestionMarkCircleIcon, | ||
XIcon, | ||
} from '@heroicons/react/solid'; | ||
|
||
import React from 'react'; | ||
|
||
import IconButton from '@material-ui/core/IconButton'; | ||
import SvgIcon from '@material-ui/core/SvgIcon'; | ||
import Typography from '@material-ui/core/Typography'; | ||
|
||
import {SnackbarProps} from './Snackbar.interface'; | ||
import {useStyles} from './Snackbar.style'; | ||
|
||
import {useSnackbar, SnackbarContent} from 'notistack'; | ||
|
||
export const Snackbar = React.forwardRef<HTMLDivElement, SnackbarProps>((props, ref) => { | ||
const style = useStyles(props); | ||
|
||
const {closeSnackbar} = useSnackbar(); | ||
const dismiss = () => closeSnackbar(props.key); | ||
|
||
return ( | ||
<SnackbarContent ref={ref} className={style.root}> | ||
<div className={style.card}> | ||
<div className={style.cardInside}> | ||
<SvgIcon | ||
classes={{root: style.iconLeft}} | ||
component={ | ||
props?.variant === 'success' | ||
? CheckCircleIcon | ||
: props?.variant === 'error' | ||
? ExclamationCircleIcon | ||
: props?.variant === 'warning' | ||
? ExclamationIcon | ||
: props?.variant === 'info' | ||
? InformationCircleIcon | ||
: QuestionMarkCircleIcon | ||
} | ||
viewBox="0 0 20 20" | ||
/> | ||
<Typography variant="body1" className={style.typography} color="textPrimary"> | ||
{props.message} | ||
</Typography> | ||
<div className={style.icons}> | ||
<IconButton aria-label="close" onClick={dismiss}> | ||
<SvgIcon | ||
component={XIcon} | ||
viewBox="0 0 20 20" | ||
classes={{root: style.iconClose}} | ||
color="inherit" | ||
/> | ||
</IconButton> | ||
</div> | ||
</div> | ||
</div> | ||
</SnackbarContent> | ||
); | ||
}); | ||
|
||
Snackbar.displayName = 'Snackbar'; |
30 changes: 30 additions & 0 deletions
30
src/components/molecules/Snackbar/useEnqueueSnackbar.hook.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,30 @@ | ||
import {useMediaQuery, useTheme} from '@material-ui/core'; | ||
|
||
import {Snackbar} from './Snackbar'; | ||
import {SnackbarProps} from './Snackbar.interface'; | ||
|
||
import {useSnackbar as useDefaultSnackbar} from 'notistack'; | ||
|
||
export const useEnqueueSnackbar = () => { | ||
const {enqueueSnackbar} = useDefaultSnackbar(); | ||
const theme = useTheme(); | ||
const isMobile = useMediaQuery(theme.breakpoints.down('xs')); | ||
|
||
const pushSnackbar = (payload: Omit<SnackbarProps, 'key'> & {id?: string | number}) => { | ||
const {message, variant, id} = payload; | ||
|
||
enqueueSnackbar(payload.message, { | ||
variant, | ||
preventDuplicate: true, | ||
anchorOrigin: { | ||
vertical: isMobile ? 'bottom' : 'top', | ||
horizontal: 'right', | ||
}, | ||
content: key => { | ||
return <Snackbar key={id ?? key} message={message} variant={variant} />; | ||
}, | ||
}); | ||
}; | ||
|
||
return pushSnackbar; | ||
}; |
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