docs/.vitepress/theme/components/NewDomainBanner.vue
104 lines · 2118 bytes
1<!--
2 All Rights Reserved
3
4 Copyright (c) 2025 taskylizard
5
6 All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder.
7-->
8<script setup lang="ts">
9import { useElementSize } from '@vueuse/core'
10import { ref, watchEffect } from 'vue'
11
12const el = ref<HTMLElement>()
13const { height } = useElementSize(el)
14
15watchEffect(() => {
16 if (height.value) {
17 document.documentElement.style.setProperty(
18 '--vp-layout-top-height',
19 `${height.value + 16}px`
20 )
21 }
22})
23
24const dismiss = () => {
25 localStorage.setItem('ackDomainChange', 'true')
26 document.documentElement.classList.add('banner-dismissed')
27}
28</script>
29
30<template>
31 <div rel="el" class="banner">
32 <div class="text">
33 wotaku.
34 <bold class="font-bold">moe</bold>
35 is now
36 <a class="underline" href="https://wotaku.wiki">wotaku.wiki</a>
37 . Bookmark & share!!
38 </div>
39 <button type="button" @click="dismiss">
40 <svg
41 xmlns="http://www.w3.org/2000/svg"
42 viewBox="0 0 20 20"
43 fill="currentColor"
44 >
45 <path d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z" />
46 </svg>
47 </button>
48 </div>
49</template>
50
51<style>
52.banner-dismissed {
53 --vp-layout-top-height: 0px !important;
54}
55
56html {
57 --vp-layout-top-height: 88px;
58}
59
60@media (min-width: 375px) {
61 html {
62 --vp-layout-top-height: 64px;
63 }
64}
65
66@media (min-width: 768px) {
67 html {
68 --vp-layout-top-height: 40px;
69 }
70}
71</style>
72
73<style scoped>
74.banner-dismissed .banner {
75 display: none;
76}
77
78.banner {
79 position: fixed;
80 top: 0;
81 right: 0;
82 left: 0;
83 z-index: var(--vp-z-index-layout-top);
84
85 padding: 8px;
86 text-align: center;
87
88 background: var(--vp-c-bg-soft);
89 color: var(--vp-c-text-1);
90
91 display: flex;
92 justify-content: space-between;
93}
94
95.text {
96 flex: 1;
97}
98
99svg {
100 width: 20px;
101 height: 20px;
102 margin-left: 8px;
103}
104</style>