Skip to content
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

feature: custom cn function #310

Merged

Conversation

jzxhuang
Copy link
Contributor

Issue 😱:

Support a custom cn function, for example if you want to use clsx or tailwind-merge . In particular I was looking for the tw-merge use case

Copy link

vercel bot commented Jan 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sonner ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 3, 2024 2:04pm

@emilkowalski
Copy link
Owner

I don't fully understand why this is needed, can you explain?

@jzxhuang
Copy link
Contributor Author

I don't fully understand why this is needed, can you explain?

Yep! Suppose we have something like:

<Toaster toastOptions={{ unstyled: true, classNames: { title: "text-sm font-heading font-semibold" }}} />

then in an individual toast, we want to override some styles:

toast("Hello world", { classNames: { title: "text-lg font-bold" }})

As-is, there is no easy way to tell if text-lg or text-sm will take precedence; same with font-semibold vs font-bold. Sure, we could try to use !important but this is not very reliable, and I've also found myself needing to use !important in Toaster itself (separate issue, see #321).

With a custom cn function we could guarantee that the classes are merged in a way such that the classes in toast(...) take precedence over classes in Toaster when there are classes that target the same attribute. In particular, I'm thinking of the tailwind use case with tailwind-merge, i.e. https://ui.shadcn.com/docs/installation/manual#add-a-cn-helper!

Let me know if this makes sense 🙏

@emilkowalski emilkowalski merged commit d39170f into emilkowalski:main Feb 6, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants