1
1
---
2
-
3
2
const toasts = [
4
- // {
5
- // icon: `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-dollar-sign"><line x1="12" y1="1" x2="12" y2="23"></line><path d="M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"></path></svg>`,
6
- // title: "Two",
7
- // description: "One",
8
- // href: ""
9
- // },
10
- // {
11
- // icon: `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-dollar-sign"><line x1="12" y1="1" x2="12" y2="23"></line><path d="M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"></path></svg>`,
12
- // title: "Three",
13
- // description: "One",
14
- // href: ""
15
- // },
16
3
{
17
4
icon: ` <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-trending-up"><polyline points="22 7 13.5 15.5 8.5 10.5 2 17"/><polyline points="16 7 22 7 22 13"/></svg> ` ,
18
5
title: " One Dollar Stats" ,
19
6
description: " $1 per mo web analytics" ,
20
- href: " https://onedollarstats.com/ "
7
+ href: " https://driz.link/onedollarstats " ,
21
8
},
22
9
];
23
10
---
24
- <div data-toasts class =" toasts-wrap animated_bottom" transition:persist =" toasts" >
11
+
12
+ <div
13
+ data-toasts
14
+ class =" toasts-wrap animated_bottom"
15
+ transition:persist =" toasts"
16
+ >
25
17
<div class =" by-drizzle" >Product by Drizzle</div >
26
18
{
27
19
toasts .map ((toast , index ) => (
@@ -30,12 +22,14 @@ const toasts = [
30
22
target = " _blank"
31
23
rel = " noreferrer nofollow"
32
24
data-toast = { index }
25
+ data-toast-name = { toast .title }
33
26
style = { ` transform: translateY(${(toasts .length - index - 1 ) * 100 }%) scale(${1 - (toasts .length - index - 1 ) * 0.06 }); ` }
34
27
class = " toast"
35
28
>
36
29
<div class = " toast-content" >
37
30
<div class = " toast-icon" >
38
31
<Fragment set :html = { toast .icon } />
32
+ <div class = " toast-indicator" />
39
33
</div >
40
34
<div class = " toast-text" >
41
35
<span class = " toast-title" >{ toast .title } </span >
@@ -51,7 +45,7 @@ const toasts = [
51
45
display: flex;
52
46
flex-direction: column;
53
47
position: absolute;
54
- z-index: 1000 ;
48
+ z-index: 2 ;
55
49
bottom: 0;
56
50
left: 0;
57
51
right: 0;
@@ -88,9 +82,9 @@ const toasts = [
88
82
align-items: center;
89
83
width: 100%;
90
84
/* box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 12px 0px; */
91
- background: #FBFBFC ;
85
+ background: #fbfbfc ;
92
86
border-radius: 8px;
93
- border: 1px solid #E0E1E3 ;
87
+ border: 1px solid #e0e1e3 ;
94
88
}
95
89
96
90
.toast-text {
@@ -109,7 +103,6 @@ const toasts = [
109
103
.toast-description {
110
104
font-size: 12px;
111
105
line-height: normal;
112
-
113
106
}
114
107
115
108
.toast:not(:last-child) .toast-content {
@@ -118,11 +111,11 @@ const toasts = [
118
111
119
112
@keyframes bottom {
120
113
0% {
121
- transform: translateY(20 %);
114
+ transform: translateY(100 %);
122
115
opacity: 0;
123
116
}
124
117
75% {
125
- transform: translateY(-10 %);
118
+ transform: translateY(-15 %);
126
119
opacity: 0.75;
127
120
}
128
121
100% {
@@ -145,63 +138,112 @@ const toasts = [
145
138
}
146
139
147
140
.toast-icon {
141
+ position: relative;
148
142
width: 32px;
149
143
height: 32px;
150
144
border-radius: 50%;
151
145
background-color: #f0f0f0;
152
146
padding: 6px;
153
147
margin: 8px;
154
148
aspect-ratio: 1;
155
- border: 1px solid #E0E1E3;
149
+ border: 1px solid #e0e1e3;
150
+ }
151
+
152
+ .toast-indicator {
153
+ position: absolute;
154
+ width: 8px;
155
+ height: 8px;
156
+ bottom: 0px;
157
+ right: 0px;
158
+ border-radius: 100%;
159
+ background: #ef4444;
156
160
}
157
161
158
162
html.dark .by-drizzle {
159
163
background: #111;
160
164
border: 1px solid #292929;
165
+ color: #909090;
161
166
}
162
167
163
168
.by-drizzle {
164
169
text-transform: uppercase;
165
- font-size: 12px ;
166
- bottom: 0 ;
170
+ font-size: 10px ;
171
+ bottom: -24px ;
167
172
position: absolute;
168
173
transition: bottom 0.2s;
169
174
margin-bottom: 8px;
170
175
left: 50%;
171
- border: 1px solid #E0E1E3;
176
+ color: #909090;
177
+ border: 1px solid #e0e1e3;
172
178
white-space: pre;
173
179
z-index: -1;
174
180
transform: translateX(-50%);
175
- background-color: #FBFBFC ;
181
+ background-color: #fbfbfc ;
176
182
padding: 0 8px;
177
183
border-bottom-left-radius: 8px;
178
184
border-bottom-right-radius: 8px;
179
185
}
180
-
181
- .toasts-wrap:has(.toast:hover) .by-drizzle{
182
- bottom: -26px;
183
- }
184
186
</style >
185
187
<style is:global >
186
- .toast-icon svg {
187
- width: 100%;
188
- height: 100%;
189
- }
188
+ .toast-icon svg {
189
+ width: 100%;
190
+ height: 100%;
191
+ }
190
192
</style >
193
+ <script is:inline >
194
+ const toasts = document.querySelectorAll("[data-toast]");
195
+ const localStorageItems = localStorage.getItem("toasts");
196
+ const storedToasts = localStorageItems ? JSON.parse(localStorageItems) : [];
197
+ toasts.forEach((toast) => {
198
+ const toastName = toast.dataset.toastName;
199
+ const toastIndicator = toast.querySelector(".toast-indicator");
200
+ if (storedToasts.includes(toastName) && toastIndicator) {
201
+ toastIndicator.style.display = "none";
202
+ }
203
+ });
204
+ </script >
191
205
<script >
192
- document.addEventListener("DOMContentLoaded", (e) => {
193
- const toasts = document.querySelectorAll("[data-toast]");
206
+ const initToasts = () => {
207
+ const toasts = document.querySelectorAll(
208
+ "[data-toast]",
209
+ ) as NodeListOf<HTMLElement>;
210
+ const localStorageItems = localStorage.getItem("toasts");
211
+ const storedToasts = localStorageItems ? JSON.parse(localStorageItems) : [];
212
+
194
213
toasts.forEach((toast, index) => {
195
- setTimeout(() => {
196
- toast.setAttribute(
197
- "style",
198
- `transform: translateY(calc(${(toasts.length - index - 1) * 100}% - ${(toasts.length - index - 1) * 12}px)) scale(${1 - (toasts.length - index - 1) * 0.06});`
199
- );
200
- }, 100 * toasts.length - index * 100);
214
+ const toastName = toast.dataset.toastName;
215
+ const toastIndicator = toast.querySelector(
216
+ ".toast-indicator",
217
+ ) as HTMLElement;
218
+ if (storedToasts.includes(toastName) && toastIndicator) {
219
+ toastIndicator.style.display = "none";
220
+ }
221
+
222
+ toast.addEventListener("mouseenter", () => {
223
+ if (!storedToasts.includes(toastName)) {
224
+ storedToasts.push(toastName);
225
+ localStorage.setItem("toasts", JSON.stringify(storedToasts));
226
+ }
227
+ if (toastIndicator) {
228
+ toastIndicator.style.display = "none";
229
+ }
230
+ });
231
+
232
+ setTimeout(
233
+ () => {
234
+ toast.setAttribute(
235
+ "style",
236
+ `transform: translateY(calc(${(toasts.length - index - 1) * 100}% - ${(toasts.length - index - 1) * 12}px)) scale(${1 - (toasts.length - index - 1) * 0.06});`,
237
+ );
238
+ },
239
+ 100 * toasts.length - index * 100,
240
+ );
241
+
201
242
if (index !== toasts.length - 1) {
202
243
toast.classList.add("animated_fadeout");
203
244
}
204
245
});
246
+
205
247
const toastsWrap = document.querySelector("[data-toasts]");
206
248
if (toastsWrap) {
207
249
setTimeout(() => {
@@ -211,5 +253,6 @@ const toasts = [
211
253
toastsWrap.classList.add("toasts-wrap-fade");
212
254
}, 3000);
213
255
}
214
- });
256
+ };
257
+ document.addEventListener("astro:page-load", initToasts);
215
258
</script >
0 commit comments