docs/.vitepress/theme/components/VPSwitchAppearance.vue

9cf555e0d1004701b0f9bdba559b0b245840b9f3
wotaku/docs/.vitepress/theme/components/VPSwitchAppearance.vue
taskylizard chore: update license0dddca8d19 1 year ago

67 lines · 1640 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 { useData } from 'vitepress'
10import { inject } from 'vue'
11import VPIconMoon from 'vitepress/dist/client/theme-default/components/icons/VPIconMoon.vue'
12import VPIconSun from 'vitepress/dist/client/theme-default/components/icons/VPIconSun.vue'
13
14const { isDark } = useData()
15
16const toggleAppearance = inject('toggle-appearance', () => {
17  isDark.value = !isDark.value
18})
19</script>
20
21<template>
22  <button type="button" role="switch" title="VPSwitchAppearance" class="VPSwitchAppearance" :aria-checked="isDark"
23    @click="toggleAppearance">
24    <ClientOnly>
25      <Transition name="fade" mode="out-in">
26        <VPIconSun v-if="!isDark" class="sun" />
27        <VPIconMoon v-else class="moon" />
28      </Transition>
29    </ClientOnly>
30  </button>
31</template>
32
33<style lang="scss" scoped>
34.VPSwitchAppearance {
35  display: flex;
36  justify-content: center;
37  align-items: center;
38  width: 36px;
39  height: 36px;
40  color: var(--vp-c-text-2);
41  transition: color 0.5s;
42
43  &:hover {
44    color: var(--vp-c-text-1);
45    transition: color 0.25s;
46  }
47
48  &> :deep(svg) {
49    width: 20px;
50    height: 20px;
51    fill: currentColor;
52  }
53
54  &[data-view-transition='false'] {
55
56    .fade-enter-active,
57    .fade-leave-active {
58      transition: opacity 0.1s ease;
59    }
60
61    .fade-enter-from,
62    .fade-leave-to {
63      opacity: 0;
64    }
65  }
66}
67</style>
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form