Skip to content

Commit

Permalink
feat: change the style
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoluoboding committed Feb 29, 2024
1 parent 7f79ecd commit 4b73c89
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 27 deletions.
2 changes: 1 addition & 1 deletion packages/Toast.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
ref="toastRef"
data-sonner-toast=""
:class="toastClass"
:data-styled="!isTitleComponent"
:data-styled="!Boolean(toast.unstyled || unstyled)"
:data-mounted="mounted"
:data-promise="Boolean(toast.promise)"
:data-removed="removed"
Expand Down
27 changes: 17 additions & 10 deletions packages/Toaster.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<!-- Remove item from normal navigation flow, only available via hotkey -->
<section :aria-label="`${containerAriaLabel} ${hotkeyLabel}`" :tabIndex="-1">
<template v-for="pos in possiblePositions" :key="pos">
<template v-for="(pos, index) in possiblePositions" :key="pos">
<ol
ref="listRef"
data-sonner-toaster
Expand Down Expand Up @@ -36,9 +36,15 @@
@pointerdown="onPointerDown"
@pointerup="interacting = false"
>
<template v-for="(toast, index) in toasts" :key="toast.id">
<template
v-for="(toast, idx) in toasts.filter(
(toast) =>
(!toast.position && index === 0) || toast.position === position
)"
:key="toast.id"
>
<Toast
:index="index"
:index="idx"
:toast="toast"
:duration="toastOptions?.duration ?? duration"
:className="toastOptions?.className"
Expand Down Expand Up @@ -265,14 +271,15 @@ watchEffect((onInvalidate) => {
// Update the toast if it already exists
if (indexOfExistingToast !== -1) {
// toasts.value.splice(indexOfExistingToast, 1, toast)
toasts.value = [
...toasts.value.slice(0, indexOfExistingToast),
{ ...toasts.value[indexOfExistingToast], ...toast },
...toasts.value.slice(indexOfExistingToast + 1)
]
toasts.value.splice(indexOfExistingToast, 1, toast)
// toasts.value = [
// ...toasts.value.slice(0, indexOfExistingToast),
// { ...toasts.value[indexOfExistingToast], ...toast },
// ...toasts.value.slice(indexOfExistingToast + 1)
// ]
} else {
toasts.value = [toast, ...toasts.value]
}
toasts.value = [toast, ...toasts.value]
})
})
Expand Down
37 changes: 21 additions & 16 deletions packages/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ html[dir='rtl'],

[data-sonner-toast] [data-icon] {
display: flex;
height: 20px;
width: 20px;
height: 16px;
width: 16px;
position: relative;
justify-content: flex-start;
align-items: center;
Expand Down Expand Up @@ -180,8 +180,10 @@ html[dir='rtl'],
border: none;
cursor: pointer;
outline: none;
display: flex;
align-items: center;
flex-shrink: 0;
transition: opacity 400ms, box-shadow 200ms;
z-index: 100;
}

[data-sonner-toast] [data-button]:focus-visible {
Expand Down Expand Up @@ -218,7 +220,6 @@ html[dir='rtl'],
border: 1px solid var(--gray4);
transform: var(--toast-close-button-transform);
border-radius: 50%;
opacity: 0;
cursor: pointer;
z-index: 1;
transition: opacity 100ms, background 200ms, border-color 200ms;
Expand All @@ -232,16 +233,6 @@ html[dir='rtl'],
cursor: not-allowed;
}

[data-sonner-toast]:hover [data-close-button] {
opacity: 1;
}
[data-sonner-toast]:focus [data-close-button] {
opacity: 1;
}
[data-sonner-toast]:focus-within [data-close-button] {
opacity: 1;
}

[data-sonner-toast]:hover [data-close-button]:hover {
background: var(--gray2);
border-color: var(--gray5);
Expand All @@ -254,6 +245,7 @@ html[dir='rtl'],
left: 0;
right: 0;
height: 100%;
z-index: -1;
}

[data-sonner-toast][data-y-position='top'][data-swiping='true']:before {
Expand Down Expand Up @@ -518,12 +510,12 @@ html[dir='rtl'],
--size: 16px;
height: var(--size);
width: var(--size);
position: absolute;
inset: 0;
z-index: 10;
}

.sonner-loading-wrapper[data-visible='false'] {
display: none;
transform-origin: center;
animation: sonner-fade-out 0.2s ease forwards;
}
Expand All @@ -549,7 +541,6 @@ html[dir='rtl'],

.sonner-loading-bar:nth-child(1) {
animation-delay: -1.2s;
/* Rotate trick to avoid adding an additional pixel in some sizes */
transform: rotate(0.0001deg) translate(146%);
}

Expand Down Expand Up @@ -647,3 +638,17 @@ html[dir='rtl'],
animation: none !important;
}
}

.sonner-loader {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
transform-origin: center;
transition: opacity 200ms, transform 200ms;
}

.sonner-loader[data-visible='false'] {
opacity: 0;
transform: scale(0.8) translate(-50%, -50%);
}

0 comments on commit 4b73c89

Please sign in to comment.