toastify-js
toastify-js copied to clipboard
Adding a class doesn't override backgroundColor
If I do NOT set a backgroundColor option when calling Toastify, but add a className
that maps for instance to a Bootstrap alert class, the Toast's default backgroundColor still takes precedence over the class' background color.
i.e.
Toastify({
text: "A simple warning alert—check it out!",
duration: 3000,
close: true,
gravity: "bottom",
positionLeft: false,
className:"alert alert-warning>"
}).showToast();
Should yield the following:
Instead I get:
Hey @CharlieIGG,
The issue that you are facing is a side-effect of using a gradient background as default. Linear gradient requires to use background
property where as bootstrap sets the color of alert using background-color
. Setting a default background was done in order to make Toastify a simple drop-in library for anyone to use.
But for the issue of style not being applied, you will need to import the bootstrap css from your JS file for it to take effect. Demo: https://codesandbox.io/s/8kyk48zoll
Let me know your thoughts of this.
@apvarun What about adding a class for the default gradient that is the default value of the className
property?
FYI I ended up doing the following to achieve what I wanted (thankfully I was already packing SCSS):
@each $color,
$value in $theme-colors {
.toastify.alert-#{$color},
.alert-#{$color} {
@include alert-variant(theme-color-level($color, $alert-bg-level), theme-color-level($color, $alert-border-level), color-yiq(theme-color-level($color, $alert-bg-level)));
.close,
.alert-link {
color: color-yiq(theme-color-level($color, $alert-bg-level));
}
}
}
I had exactly this same issue wanting to use bg-success
or bg-danger
from bootstrap. (alert added a div/block which messed with the layout.)
I found you can set a null backgroundColor
as "unset", "transparent" or "none" and then the className
works.
https://caniuse.com/mdn-css_types_color_transparent https://caniuse.com/css-unset-value
p.s. the options table didn't have a default value for backgroundColor so I expected that would be null. Perhaps remove it from the CSS and instead add it if both backgroundColor and className aren't specified?
I added one-line CSS to solve that
.toastify {
background-image: unset;
}