An opinionated toast component for React.
Add fully custom toast
emilkowalskid4f52d81b3f0
diff --git a/src/index.tsx b/src/index.tsxindex db0c932..3ba803b 100644--- a/src/index.tsx+++ b/src/index.tsx@@ -223,6 +223,7 @@ const Toast = (props: ToastProps) => {ref={toastRef}className={className + ' ' + toastClassname}data-sonner-toast=""+ data-styled={!Boolean(toast.jsx)}data-mounted={mounted}data-promise={Boolean(toast.promise)}data-removed={removed}diff --git a/src/styles.css b/src/styles.cssindex 3adcd85..0f2c45c 100644--- a/src/styles.css+++ b/src/styles.css@@ -49,12 +49,18 @@--y: translateY(100%);--lift-amount: calc(var(--lift) * var(--gap));z-index: var(--z-index);- display: flex;- align-items: center;- gap: 6px;position: absolute;opacity: 0;transform: var(--y);+ /* https://stackoverflow.com/questions/48124372/pointermove-event-not-working-with-touch-why-not */+ touch-action: none;+ will-change: transform, opacity, height;+ transition: transform 400ms, opacity 400ms, height 400ms, box-shadow 200ms;+ box-sizing: border-box;+ outline: none;+}++[data-sonner-toast][data-styled='true'] {padding: 16px;background: var(--normal-bg);border: 1px solid var(--normal-border);@@ -63,12 +69,9 @@box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.1);width: var(--width);font-size: 13px;- /* https://stackoverflow.com/questions/48124372/pointermove-event-not-working-with-touch-why-not */- touch-action: none;- will-change: transform, opacity, height;- transition: transform 400ms, opacity 400ms, height 400ms, box-shadow 200ms;- box-sizing: border-box;- outline: none;+ display: flex;+ align-items: center;+ gap: 6px;}[data-sonner-toast]:focus-visible {diff --git a/website/src/components/Hero/index.tsx b/website/src/components/Hero/index.tsxindex 28c77b9..fd7f009 100644--- a/website/src/components/Hero/index.tsx+++ b/website/src/components/Hero/index.tsx@@ -16,9 +16,12 @@ export const Hero = () => {<buttondata-primary=""onClick={() => {- toast('Sonner', {- description: 'An opinionated toast component for React.',- });+ toast.custom((t) => (+ <div>+ <h1>Custom toast</h1>+ <button onClick={() => toast.dismiss(t)}>Dismiss</button>+ </div>+ ));}}className={styles.button}>