简体   繁体   English

如何根据主题更改吐司的背景颜色? 反应烘烤

[英]How to change background color of a toast depending on theme? react-toastify

I got react-toastify installed, and my toasts are working, but I want to add them some custom styling depending on a theme, and none of the solutions I saw are working in my case.我安装了 react-toastify,我的 toasts 工作正常,但我想根据主题为它们添加一些自定义样式,但我看到的所有解决方案都不适用于我的情况。

I don't want to overcomplicate it, I just want to change background color, maybe borders, font color, etc.我不想让它过于复杂,我只想改变背景颜色,可能是边框,字体颜色等。

在此处输入图像描述

I tried class overriding which documentation is saying about - it's not working.我试过 class 覆盖文档中所说的 - 它不起作用。

.Toastify__toast-theme--colored.Toastify__toast--error {
  color: white;
  background-color: red;
}

I tried my own className and pass it to certein toast - it's not working.我尝试了自己的className并将其传递给 certein toast - 它不起作用。

toast.error('here some error', {
          className: 'toast-error'
        });
.toast-error {
  color: white;
  background-color: red;
}

And these themed classes are not even added to the toast.success() or toast.error()这些主题类甚至没有添加到toast.success()toast.error()

I tried to override values in the core css file that im importing, and it's not working.我试图覆盖我正在导入的核心 css 文件中的值,但它不起作用。 And if I set background-color: red to the actual class that is added, then I get red background on toast.success() as well.如果我将background-color: red设置为实际添加的 class,那么我也会在toast.success()上获得红色背景。

Here is documentation .这是文档 在此处输入图像描述

How to deal with this?如何处理?

using classnames should be the solution to your problem使用类名应该是您问题的解决方案

className={classnames("Toastify__toast-theme--colored", {
          "toast-error": // here the condition by which toast-error class should pop up
        })}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM