This is old, but maybe I can help someone.
This is working on react-toastify 8.2.0
with react 16.9.0
.
First, I use css files for override styles:
.Toastify__toast-container {
z-index: 1200 !important;
}
@media only screen and (max-width: 480px){
.Toastify__toast-container > .Toastify__toast:not(:last-child) {
margin-bottom: 0.5em !important;
}
}
.Toastify__toast-theme--colored.Toastify__toast--info {
background-color: #104eb2 !important;
}
.Toastify__toast-theme--colored.Toastify__toast--success {
background-color: #18cc48 !important;
}
.Toastify__toast-theme--colored.Toastify__toast--warning {
background-color: #fcc52c !important;
}
.Toastify__toast-theme--colored.Toastify__toast--error {
background-color: #FE685E !important;
}
@media only screen and (min-width: 480px){
.Toastify__toast-container--bottom-left {
bottom: 3.5em !important;
}
}
You can see the style you need in How to style - react-toastify
Then, in the project I am working currently, we do not use css files too much, usually we use makeStyles
hook from material-ui
, so I did something like this:
import { makeStyles } from '@material-ui/core';
import clsx from 'clsx';
import React from 'react';
import { toast, ToastContainer } from 'react-toastify';
const CustomToastContainer = () => {
const classes = useStyles();
return (
<ToastContainer
className={({ defaultClassName }) =>
clsx(defaultClassName, classes.toastContainer)
}
toastClassName={({ type, defaultClassName }) =>
clsx(defaultClassName, classes[type])
}
rtl={false}
autoClose={3000}
pauseOnHover
position={toast.POSITION.BOTTOM_LEFT}
theme="colored"
limit={3}
pauseOnFocusLoss
newestOnTop
/>
);
};
const useStyles = makeStyles(theme => ({
toastContainer: {
zIndex: 1200,
[theme.breakpoints.up(theme.breakpoints.values.sm)]: {
bottom: '3.5em !important'
},
'& > .Toastify__toast:not(:last-child)': {
marginBottom: '0.5em !important'
}
},
success: {
backgroundColor: `${theme.palette.success.main} !important`
},
info: {
backgroundColor: `${theme.palette.primary.main} !important`
},
error: {
backgroundColor: `${theme.palette.error.main} !important`
},
warning: {
backgroundColor: `${theme.palette.warning.main} !important`
}
}));
clsx(defaultClassName, classes.toastContainer)
is equivalent to concat defaultClassName
with your own style classes, e.g. ${defaultClassName} ${classes.myClass}
.
defaultClassName
is the variable which store the default styles mentioned on the link aboved, so, is like override them. I used !important
in my makeStyle
styles, but I do not sure if is really necessary. So, you can try.