Skip to content

Commit b29293d

Browse files
committed
Merge branch 'main' into pr/135
2 parents 4565800 + e4faada commit b29293d

File tree

5 files changed

+54
-8
lines changed

5 files changed

+54
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [2.0.2](https://github.com/xiaoluoboding/vue-sonner/compare/v2.0.1...v2.0.2) (2025-07-17)
2+
3+
4+
15
## [2.0.1](https://github.com/xiaoluoboding/vue-sonner/compare/v2.0.0...v2.0.1) (2025-06-23)
26

37

app/components/HeadlessToast.vue

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
<script setup lang="ts">
2+
import { toast } from '@/packages'
3+
24
defineProps<{ msg?: string }>()
35
</script>
46

57
<template>
68
<div class="headless">
79
<p class="headlessTitle">Event Created {{ msg }}</p>
810
<p class="headlessDescription">Today at 4:00pm - "Louvre Museum"</p>
11+
<button class="headlessCloseAll" @click="toast.dismiss()">
12+
Close all
13+
</button>
914
<button class="headlessClose" @click="$emit('closeToast')">
1015
<svg width="14" height="14" viewBox="0 0 16 16" fill="currentColor">
1116
<path
@@ -28,7 +33,7 @@ defineProps<{ msg?: string }>()
2833
}
2934
3035
.headlessDescription {
31-
margin: 0;
36+
margin: 0 0 8px;
3237
color: var(--gray10);
3338
font-size: 14px;
3439
line-height: 1;
@@ -42,6 +47,22 @@ defineProps<{ msg?: string }>()
4247
line-height: 1;
4348
}
4449
50+
.headlessCloseAll {
51+
font-size: 14px;
52+
color: var(--gray10);
53+
font-weight: 500;
54+
line-height: 1;
55+
border: 1px solid var(--gray10);
56+
border-radius: 4px;
57+
padding: 6px 8px;
58+
transition: color 200ms, border 200ms;
59+
}
60+
61+
.headlessCloseAll:hover {
62+
color: var(--gray12);
63+
border: 1px solid var(--gray12);
64+
}
65+
4566
.headlessClose {
4667
position: absolute;
4768
cursor: pointer;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vue-sonner",
33
"type": "module",
4-
"version": "2.0.1",
4+
"version": "2.0.2",
55
"packageManager": "[email protected]",
66
"author": "xiaoluoboding <[email protected]>",
77
"license": "MIT",

src/packages/Toaster.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ function removeToast(toastToRemove: ToastT) {
232232
233233
// First remove toast
234234
toasts.value = toasts.value.filter(({ id }) => id !== toastToRemove.id)
235-
235+
236236
// Delay cleaning heights to give animation time to complete
237237
setTimeout(() => {
238238
// Ensure toast has been actually removed before cleaning heights
@@ -332,7 +332,7 @@ watchEffect((onInvalidate) => {
332332
/**
333333
* Helper function to update the actualTheme value
334334
* based on current media query match.
335-
*
335+
*
336336
* @param {boolean} matches - true if dark mode is preferred
337337
*/
338338
const updateTheme = (matches: boolean) => {
@@ -734,7 +734,7 @@ html[dir='rtl'],
734734
735735
[data-sonner-toast][data-expanded='false'][data-front='false'] {
736736
--scale: var(--toasts-before) * 0.05 + 1;
737-
--y: translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--scale)));
737+
--y: translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--toasts-before) * 0.05 + 1));
738738
height: var(--front-toast-height);
739739
}
740740
@@ -887,11 +887,11 @@ html[dir='rtl'],
887887
}
888888
889889
[data-sonner-toaster][data-y-position='bottom'] {
890-
bottom: var(--mobile-offset-bottom);
890+
bottom: calc(var(--mobile-offset-bottom) + max(env(safe-area-inset-bottom), 0px));
891891
}
892892
893893
[data-sonner-toaster][data-y-position='top'] {
894-
top: var(--mobile-offset-top);
894+
top: calc(var(--mobile-offset-top) + max(env(safe-area-inset-top), 0px));
895895
}
896896
897897
[data-sonner-toaster][data-x-position='center'] {

src/packages/state.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,28 @@ class Observer {
299299
// We can't provide the toast we just created as a prop as we didn't create it yet, so we can create a default toast object, I just don't know how to use function in argument when calling()?
300300
custom = (component: Component, data?: ExternalToast) => {
301301
const id = data?.id || toastsCounter++
302-
this.publish({ component, id, ...data })
302+
const alreadyExists = this.toasts.find((toast) => {
303+
return toast.id === id
304+
})
305+
const dismissible =
306+
data?.dismissible === undefined ? true : data.dismissible
307+
308+
if (this.dismissedToasts.has(id)) {
309+
this.dismissedToasts.delete(id)
310+
}
311+
312+
if (alreadyExists) {
313+
this.toasts = this.toasts.map((toast) => {
314+
if (toast.id === id) {
315+
this.publish({ ...toast, component, dismissible, id, ...data })
316+
return { ...toast, component, dismissible, id, ...data }
317+
}
318+
319+
return toast
320+
})
321+
} else {
322+
this.addToast({ component, dismissible, id, ...data })
323+
}
303324
return id
304325
}
305326

0 commit comments

Comments
 (0)