|
| 1 | +<script setup lang="ts"> |
| 2 | +const { data: banner } = useFetch('/api/banner'); |
| 3 | +
|
| 4 | +const dismissedBanners = useCookie('directus-dismissed-banners', { |
| 5 | + default: () => [] as string[], |
| 6 | +}); |
| 7 | +
|
| 8 | +const bannerVisible = computed(() => { |
| 9 | + if (!unref(banner)) return false; |
| 10 | + return unref(dismissedBanners).includes(unref(banner)!.id) === false; |
| 11 | +}); |
| 12 | +
|
| 13 | +const dismiss = (id: string) => { |
| 14 | + dismissedBanners.value = [...unref(dismissedBanners), id]; |
| 15 | +}; |
| 16 | +
|
| 17 | +const iconName = computed(() => { |
| 18 | + if (!unref(banner)) return null; |
| 19 | + return getIconName(unref(banner)!.icon); |
| 20 | +}); |
| 21 | +</script> |
| 22 | + |
| 23 | +<template> |
| 24 | + <div |
| 25 | + v-if="banner && bannerVisible" |
| 26 | + class="bg-foreground cursor-pointer h-8" |
| 27 | + > |
| 28 | + <UContainer class="h-full flex items-center gap-x-4"> |
| 29 | + <NuxtLink |
| 30 | + class="flex-grow h-full flex items-center text-background no-underline text-xs leading-xs font-semibold group" |
| 31 | + :href="banner.link ?? undefined" |
| 32 | + > |
| 33 | + <Icon |
| 34 | + v-if="iconName" |
| 35 | + class="mr-2 size-5" |
| 36 | + :name="iconName" |
| 37 | + /> |
| 38 | + <span |
| 39 | + class="whitespace-nowrap overflow-hidden text-ellipsis" |
| 40 | + v-html="banner.content" |
| 41 | + /> |
| 42 | + <Icon |
| 43 | + class="hidden md:block transform duration-150 ease-out ml-1 group-hover:translate-x-1 size-5" |
| 44 | + name="material-symbols:arrow-forward" |
| 45 | + /> |
| 46 | + </NuxtLink> |
| 47 | + |
| 48 | + <button |
| 49 | + aria-label="Close" |
| 50 | + class="text-background" |
| 51 | + :padded="false" |
| 52 | + icon="material-symbols:close" |
| 53 | + @click="dismiss(banner.id)" |
| 54 | + > |
| 55 | + <Icon |
| 56 | + name="material-symbols:close" |
| 57 | + class="size-5" |
| 58 | + /> |
| 59 | + </button> |
| 60 | + </UContainer> |
| 61 | + </div> |
| 62 | +</template> |
0 commit comments