1+ <script setup lang="ts">
2+ import { X } from ' lucide-vue-next' ;
3+ import { onMounted , ref , watch } from ' vue' ;
4+
5+ const props = defineProps ({
6+ notice: { type: Object , default: null },
7+ });
8+
9+ const isVisible = ref (false );
10+
11+ const getStorageKey = () => {
12+ return props .notice ?.updated_at
13+ ? ` session_notice_${props .notice .updated_at } `
14+ : ' session_notice_dismissed' ;
15+ };
16+
17+ const checkVisibility = () => {
18+ if (! props .notice ) return false ;
19+
20+
21+ return sessionStorage .getItem (getStorageKey ()) !== ' true' ;
22+ };
23+
24+
25+ onMounted (() => {
26+ isVisible .value = checkVisibility ();
27+ });
28+
29+
30+ watch (() => props .notice , () => {
31+ isVisible .value = checkVisibility ();
32+ });
33+
34+ const close = () => {
35+ if (props .notice ) {
36+ sessionStorage .setItem (getStorageKey (), ' true' );
37+ }
38+ isVisible .value = false ;
39+ };
40+ </script >
41+
42+ <template >
43+ <Teleport to="body">
44+ <Transition
45+ enter-active-class="transition duration-300 ease-out"
46+ enter-from-class="opacity-0 scale-95"
47+ enter-to-class="opacity-100 scale-100"
48+ leave-active-class="transition duration-200 ease-in"
49+ leave-from-class="opacity-100 scale-100"
50+ leave-to-class="opacity-0 scale-95"
51+ >
52+ <div
53+ v-if =" isVisible && notice"
54+ class =" fixed inset-0 z-50 flex items-center justify-center p-4"
55+ >
56+ <div
57+ class =" absolute inset-0 bg-slate-950/20 backdrop-blur-sm"
58+ @click =" close"
59+ ></div >
60+
61+ <div
62+ class =" relative w-full max-w-md overflow-hidden rounded-3xl bg-white shadow-xl ring-1 ring-slate-900/5"
63+ role =" alertdialog"
64+ >
65+ <button
66+ @click =" close"
67+ class =" absolute top-4 right-4 z-10 rounded-full p-2 transition bg-slate-100 text-slate-600"
68+ aria-label =" Close notice"
69+ >
70+ <X class="h-5 w-5" />
71+ </button >
72+
73+ <img
74+ v-if =" notice.image"
75+ :src =" notice.image"
76+ class =" h-40 w-full object-cover"
77+ alt =" "
78+ />
79+
80+ <div class =" p-6" >
81+ <h2 v-if =" notice.title" class =" text-lg font-semibold text-slate-900" >
82+ {{ notice.title }}
83+ </h2 >
84+ <p v-if =" notice.message" class =" mt-2 text-sm text-slate-600 leading-relaxed whitespace-pre-line" >
85+ {{ notice.message }}
86+ </p >
87+
88+ <div class =" mt-6 flex gap-3" >
89+ <a
90+ v-if =" notice.show_button && notice.button_link"
91+ :href =" notice.button_link"
92+ target =" _blank"
93+ rel =" noopener noreferrer"
94+ class =" flex-1 rounded-xl bg-slate-900 px-4 py-2.5 text-center text-sm font-medium text-white transition hover:bg-slate-800"
95+ >
96+ {{ notice.button_title || 'Learn more' }}
97+ </a >
98+
99+ </div >
100+ </div >
101+ </div >
102+ </div >
103+ </Transition >
104+ </Teleport >
105+ </template >
0 commit comments