docs/.vitepress/theme/components/NewDomainBanner.vue
114 lines · 2436 bytes
1<!--
2 Copyright (c) 2024 taskylizard
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15-->
16<script setup lang="ts">
17import { ref, watchEffect } from 'vue'
18import { useElementSize } from '@vueuse/core'
19
20const el = ref<HTMLElement>()
21const { height } = useElementSize(el)
22
23watchEffect(() => {
24 if (height.value) {
25 document.documentElement.style.setProperty(
26 '--vp-layout-top-height',
27 `${height.value + 16}px`
28 )
29 }
30})
31
32const dismiss = () => {
33 localStorage.setItem('ackDomainChange', 'true')
34 document.documentElement.classList.add('banner-dismissed')
35}
36</script>
37
38<template>
39 <div rel="el" class="banner">
40 <div class="text">
41 wotaku.
42 <bold class="font-bold">moe</bold>
43 is now
44 <a class="underline" href="https://wotaku.wiki">wotaku.wiki</a>
45 . Bookmark & share!!
46 </div>
47 <button type="button" @click="dismiss">
48 <svg
49 xmlns="http://www.w3.org/2000/svg"
50 viewBox="0 0 20 20"
51 fill="currentColor"
52 >
53 <path
54 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"
55 />
56 </svg>
57 </button>
58 </div>
59</template>
60
61<style>
62.banner-dismissed {
63 --vp-layout-top-height: 0px !important;
64}
65
66html {
67 --vp-layout-top-height: 88px;
68}
69
70@media (min-width: 375px) {
71 html {
72 --vp-layout-top-height: 64px;
73 }
74}
75
76@media (min-width: 768px) {
77 html {
78 --vp-layout-top-height: 40px;
79 }
80}
81</style>
82
83<style scoped>
84.banner-dismissed .banner {
85 display: none;
86}
87
88.banner {
89 position: fixed;
90 top: 0;
91 right: 0;
92 left: 0;
93 z-index: var(--vp-z-index-layout-top);
94
95 padding: 8px;
96 text-align: center;
97
98 background: var(--vp-c-bg-soft);
99 color: var(--vp-c-text-1);
100
101 display: flex;
102 justify-content: space-between;
103}
104
105.text {
106 flex: 1;
107}
108
109svg {
110 width: 20px;
111 height: 20px;
112 margin-left: 8px;
113}
114</style>