-
-
- {resolvedIcon()}
-
-
-
- {opts.title}
-
-
- {opts.description}
-
-
-
-
-
-
- {opts.actions!.map((action) => (
- {
- if (typeof action.onClick === "function") {
- action.onClick()
- }
- toaster.dismiss(props.toastId)
- }}
- >
- {action.label}
-
- ))}
-
-
-
- )
+ const opts: ToastV2Options = typeof options === "string" ? { description: options } : options
+ const key = JSON.stringify({
+ title: opts.title,
+ description: opts.description,
+ variant: opts.variant,
+ duration: opts.duration,
+ persistent: opts.persistent,
+ actions: opts.actions?.map((action) => [action.label, action.variant]),
})
+ const active = activeToastV2ByKey.get(key)
+ const toasts = toast.getToasts()
+
+ if (active && toasts.at(-1)?.id === active.id) {
+ active.options = opts
+ publishToastV2(active)
+ pulseToastV2(active.id)
+ return active.id
+ }
+
+ if (active && toasts.some((item) => item.id === active.id)) toasterV2.dismiss(active.id)
+ releaseToastV2(active)
+
+ const entry: ActiveToastV2 = { id: --toastV2Id, key, options: opts }
+ entry.actions = createToastV2Actions(entry)
+ activeToastV2ByKey.set(key, entry)
+ activeToastV2ById.set(entry.id, entry)
+ publishToastV2(entry)
+ return entry.id
+}
+
+function publishToastV2(entry: ActiveToastV2) {
+ const release = () => releaseToastV2(entry)
+ toast(entry.options.title ?? "", {
+ id: entry.id,
+ description: entry.options.description,
+ icon: entry.options.icon,
+ action: entry.actions,
+ closeButton: true,
+ duration: entry.options.persistent ? Number.POSITIVE_INFINITY : entry.options.duration,
+ className: `toast-v2 toast-v2--${entry.options.variant ?? "default"}`,
+ testId: `toast-v2-${entry.id}`,
+ unstyled: true,
+ onDismiss: release,
+ onAutoClose: release,
+ })
+}
+
+function createToastV2Actions(entry: ActiveToastV2) {
+ if (!entry.options.actions?.length) return undefined
+ return (
+