Skip to content

An opinionated toast component for React.

Update docs

emilkowalski74b09e3a6072
diff --git a/README.md b/README.md
index 6d81711..53869e2 100644
--- a/README.md
+++ b/README.md
@@ -132,7 +132,9 @@ Toasts can also be expanded by default through the `expand` prop. You can also c
You can style your toasts globally with the `toastOptions` prop in the `Toaster` component.
```jsx
-<Toaster toastOptions={{ style: { background: 'red' }, className: 'my-toast', descriptionClassName: 'my-toast-description' }} />
+<Toaster
+ toastOptions={{ style: { background: 'red' }, className: 'my-toast', descriptionClassName: 'my-toast-description' }}
+/>
```
### Styling for individual toast
@@ -171,6 +173,16 @@ Offset from the edges of the screen.
<Toaster offset="80px" />
```
+### Programmatically remove toast
+
+To remove a toast programmatically use `toast.dismiss(id)`.
+
+```jsx
+const toastId = toast('Event has been created');
+
+toast.dismiss(toastId);
+```
+
## Keyboard focus
You can focus on the toast area by pressing ⌥/alt + T. You can override it by providing an array of event.code values for each key.
diff --git a/package.json b/package.json
index ce7e14b..3e92886 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "sonner",
- "version": "0.1.1",
+ "version": "0.1.5",
"description": "An opinionated toast component for React.",
"main": "dist/index.js",
"module": "dist/index.mjs",
diff --git a/src/index.tsx b/src/index.tsx
index b8910f0..db0c932 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -213,7 +213,7 @@ const Toast = (props: ToastProps) => {
return null;
}
}, [toast.promiseData, promiseStatus]);
- console.log(toast.delete);
+
return (
<li
aria-live={toast.important ? 'assertive' : 'polite'}
@@ -414,7 +414,7 @@ const Toaster = (props: ToasterProps) => {
React.useEffect(() => {
return ToastState.subscribe((toast) => {
if ((toast as ToastToDismiss).dismiss) {
- setToasts((toasts) => toasts.map((t) => (t.id === (toast as ToastToDismiss).id ? { ...t, delete: true } : t)));
+ setToasts((toasts) => toasts.map((t) => (t.id === toast.id ? { ...t, delete: true } : t)));
return;
}
diff --git a/website/src/components/Hero/index.tsx b/website/src/components/Hero/index.tsx
index ab75a6b..28c77b9 100644
--- a/website/src/components/Hero/index.tsx
+++ b/website/src/components/Hero/index.tsx
@@ -13,17 +13,6 @@ export const Hero = () => {
<h1 className={styles.heading}>Sonner</h1>
<p style={{ marginTop: 0, fontSize: 18 }}>An opinionated toast component for React.</p>
<div className={styles.buttons}>
- <button
- onClick={() => {
- const toastId = toast('hello');
- console.log(toastId);
- setTimeout(() => {
- toast.dismiss(toastId);
- }, 200);
- }}
- >
- dismiss
- </button>
<button
data-primary=""
onClick={() => {