-
-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Easier classname customization (#232)
* Create classNames prop * Add styling section * Make title class optional * Polish * Add todo
- Loading branch information
1 parent
84745a2
commit e78eb41
Showing
4 changed files
with
147 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Styling | ||
|
||
Styling can be done globally via `toastOptions`, this way every toast will have the same styling. | ||
|
||
```jsx | ||
<Toaster | ||
toastOptions={{ | ||
style: { | ||
background: 'red', | ||
}, | ||
className: 'class', | ||
}} | ||
/> | ||
``` | ||
|
||
You can also use the same props when calling `toast` to style a specific toast. | ||
|
||
```jsx | ||
toast('Hello World', { | ||
style: { | ||
background: 'red', | ||
}, | ||
className: 'class', | ||
}); | ||
``` | ||
|
||
## Tailwind CSS | ||
|
||
The preferred way to style the toasts with tailwind is by using the `classNames` prop. Exclamation mark in front of the class is required to override the default styles. | ||
|
||
```jsx | ||
<Toaster | ||
toastOptions={{ | ||
classNames: { | ||
toast: '!bg-blue-400', | ||
title: '!text-red-400', | ||
description: '!text-red-400', | ||
actionButton: '!bg-zinc-400', | ||
cancelButton: '!bg-orange-400', | ||
closeButton: '!bg-lime-400', | ||
}, | ||
}} | ||
/> | ||
``` | ||
|
||
You can do the same when calling `toast()`. | ||
|
||
```jsx | ||
toast('Hello World', { | ||
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', | ||
}, | ||
}); | ||
``` | ||
|
||
Styling per toast type is also possible. | ||
|
||
```jsx | ||
<Toaster | ||
toastOptions={{ | ||
classNames: { | ||
error: '!bg-red-400', | ||
success: '!text-green-400', | ||
warning: '!text-yellow-400', | ||
info: '!bg-blue-400', | ||
}, | ||
}} | ||
/> | ||
``` | ||
|
||
## No styles | ||
|
||
You can also disable default styles by going headless. | ||
|
||
```jsx | ||
toast.custom((t) => ( | ||
<div> | ||
This is a custom component <button onClick={() => toast.dismiss(t)}>close</button> | ||
</div> | ||
)); | ||
``` |
e78eb41
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
sonner – ./
sonner-git-main-emilkowalski-s-team.vercel.app
sonner-emilkowalski-s-team.vercel.app
sonner-toast.vercel.app
sonner.emilkowal.ski