-
-
Notifications
You must be signed in to change notification settings - Fork 294
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
Default classNames are not working for other variants #242
Comments
That's expected, if you want differrent styling for different toast types you can use it like this:
|
No the styling is applied for all variants when applied to toast variant ignoring the default styling for other variants |
Again, that's expected. Everything you apply to |
I want to change the default style of the toast when we call the toast like this toast('Event has been created') because I would like to apply the shadcn themes for the toast when the default toast is being called and it should not change the styling of the other variants |
@emilkowalski can I make a PR for the default property which takes the styling in the classNames so that it will not effect the other variants |
@imopbuilder Of course, go for it! |
sure I will start working on it |
@emilkowalski I have made a PR #245 by add the default property to the types and also to the state |
This is still an issue as the I'm trying to apply styling to each variant, while also styling the default to allow usage of However, applying classes to export const Toaster = (props: ToasterProps) => (
<Sonner.Toaster
toastOptions={{
classNames: {
error: "bg-red",
success: "bg-green",
warning: "bg-yellow",
info: "bg-blue",
// default classes are never applied
default: "bg-white",
// can't use bg-white here because it overwrites variant classes
// toast: "bg-white",
},
unstyled: true,
}}
{...props}
/>
) Is there a reason default type was removed? FYI I'm working around this by checking for toasts that don't have the [data-sonner-toaster] li:not([data-type]) {
@apply bg-white;
} |
@justinnais yes the property has been removed in the commit but the types are not updated hence the Shadcn-ui sonner toast (take a look at the manual installation) Here is the implementation // Toaster.tsx
"use client"
import { useTheme } from "next-themes"
import { Toaster as Sonner } from "sonner"
type ToasterProps = React.ComponentProps<typeof Sonner>
const Toaster = ({ ...props }: ToasterProps) => {
const { theme = "system" } = useTheme()
return (
<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}
/>
)
}
export { Toaster } Make sure to add |
@imopbuilder Should the |
Do we have an update on this? This is pretty frustrating to work around. Intuitively any of the styling for the "variant" toasts (error, success, warning, info) should be applied after the "default" toast (toast). |
This is fixed in #324. You can now style with the default key, those styles will be overidden by any type specific ones. |
Just a heads up that I pulled the latest version 1.4.1 and it seems the "error" variant is still using the background color as styled in either "toast" or "default". The "success" variant is working correctly however. I also wanted to say thank you for a wonderful toast component. |
I had the same issue and I realised that the issue was due to my class name for my The fix is to provide custom 'use client';
import { cn } from '@/lib/utils';
// ...
<Sonner
// ...
cn={cn}
// ...
/> Hopefully that helps! |
When the classNames for toast are changed then the error default styles are also changed even when the error styles are not being touched
The text was updated successfully, but these errors were encountered: