docs/.vitepress/theme/components/NewDomainBanner.vue

166ff785f836e8bec40729ed071dd134fd2ec9a8
wotaku/docs/.vitepress/theme/components/NewDomainBanner.vue

101 lines · 2097 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 { ref, watchEffect } from 'vue'
 10import { useElementSize } from '@vueuse/core'
 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 xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
 41        <path
 42          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" />
 43      </svg>
 44    </button>
 45  </div>
 46</template>
 47
 48<style>
 49.banner-dismissed {
 50  --vp-layout-top-height: 0px !important;
 51}
 52
 53html {
 54  --vp-layout-top-height: 88px;
 55}
 56
 57@media (min-width: 375px) {
 58  html {
 59    --vp-layout-top-height: 64px;
 60  }
 61}
 62
 63@media (min-width: 768px) {
 64  html {
 65    --vp-layout-top-height: 40px;
 66  }
 67}
 68</style>
 69
 70<style scoped>
 71.banner-dismissed .banner {
 72  display: none;
 73}
 74
 75.banner {
 76  position: fixed;
 77  top: 0;
 78  right: 0;
 79  left: 0;
 80  z-index: var(--vp-z-index-layout-top);
 81
 82  padding: 8px;
 83  text-align: center;
 84
 85  background: var(--vp-c-bg-soft);
 86  color: var(--vp-c-text-1);
 87
 88  display: flex;
 89  justify-content: space-between;
 90}
 91
 92.text {
 93  flex: 1;
 94}
 95
 96svg {
 97  width: 20px;
 98  height: 20px;
 99  margin-left: 8px;
100}
101</style>