-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
variants of sonner #2254
Comments
Thanks for your suggestion. You can actually already use variants. Here's an example: toast.success('Event has been created')
toast.error('Event has not been created')
// warning, info etc Check here for more details : https://sonner.emilkowal.ski/ And another thing, you can also style the sooner with css as well as tailwind css also, like this with Toaster component <Toaster
toastOptions={{
unstyled: true,
classNames: {
error: 'bg-red-400',
success: 'text-green-400',
warning: 'text-yellow-400',
info: 'bg-blue-400',
},
}}
/> or also with toast function: toast('Hello World', {
unstyled: true,
classNames: {
toast: 'bg-blue-400',
title: 'text-red-400 text-2xl',
description: 'text-red-400',
actionButton: 'bg-zinc-400',
cancelButton: 'bg-orange-400',
closeButton: 'bg-lime-400',
},
}); as mentioned here in the documentation For more advanced usages, you can directly check out the documentation: Feel free to ask any questions if you are not satisfied with the answer. |
@jrTilak would really appreciate some pointers in terms of what I'm missing here -
I understand that a lot more styles will have to go there if I'm opting for What's interesting though is that looks like only the And in case it helps, my
|
Yes, You are right.I also noticed that the styles are not being applied using the method you are using. After doing some trials here are my findings:
Example.tsx.-.moinulmoin_vite-react-tailwind-starter.-.StackBlitz.-.Google.Chrome.2024-02-02.11-13-32.mp4SolutionFor now you can provide the same styles to <Toaster toastOptions={{
unstyled: true,
duration: 9000000,
classNames: {
error: 'bg-red-400',
info: 'bg-blue-400',
success: 'bg-green-400',
warning: 'bg-orange-400',
toast: 'bg-blue-400',
title: 'text-red-400 text-2xl',
description: 'text-red-400',
actionButton: 'bg-zinc-400',
cancelButton: 'bg-orange-400',
closeButton: 'bg-lime-400',
},
}}/> OR,you can directly import the import { Toaster } from 'sonner'; BUGI think it is some bug from I guess you should open a issue, if you want. If you are not satisfied with the answer, you can ask more❤️ |
thanks for looking into it @jrTilak , appreciate your insight! in my case, using Having said that, I think you're right regarding there being some sort of style overriding going on. What I'm not sure about though is the source - this style overriding seems to be originating from the library itself (?), i.e., in the video, where you're inspecting the styles for the background color, it's coming from the As a workaround, what I found working for me is the following -
Basically putting all my styles in the |
Yeah, there is some style overriding , I think it is from shadcn because if you inspect the component <Sonner
theme={theme as ToasterProps["theme"]}
className="toaster group"
toastOptions={{
classNames: {
toast:
"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",
description: "group-[.toast]:text-muted-foreground",
actionButton:
"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",
cancelButton:
"group-[.toast]:bg-muted group-[.toast]:text-muted-foreground",
},
}}
{...props}
/> It is good things as it makes us our design consistent but it also made that drawback to overriding the styles. As I mentioned earlier, if you pass the style props to the That's it from me. And glad to know you found the solution helpful. |
yeah, that makes sense. Guess the best path forward in this case would be to use |
I prefer variant like this Just add something like this to the toastOptions
|
hi sir, Where can I get all the props or properties related to this sonner? |
You can follow the installation guide here: After the installation, just paste the following code in
|
Example how to use it :
|
return ( |
text-foreground group-[.toaster] get rid of this line and all will be a success |
|
An error and an success variant of sonner would be a great addition
The text was updated successfully, but these errors were encountered: