generated from Seekra/repository-template
Move color theme toggle button into a separate component
This commit is contained in:
@@ -21,7 +21,6 @@ import { ref, provide, watch } from 'vue';
|
|||||||
|
|
||||||
const isDark = ref(localStorage.getItem('theme') === 'dark');
|
const isDark = ref(localStorage.getItem('theme') === 'dark');
|
||||||
provide('isDark', isDark);
|
provide('isDark', isDark);
|
||||||
watch(isDark, val => localStorage.setItem('theme', val ? 'dark' : 'light'));
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<!--
|
||||||
|
Copyright 2026 Seekra
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { inject, watch } from 'vue';
|
||||||
|
|
||||||
|
const isDark = inject('isDark');
|
||||||
|
watch(isDark, val => localStorage.setItem('theme', val ? 'dark' : 'light'));
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<button class="dark-mode-toggle"
|
||||||
|
@click="isDark = !isDark"
|
||||||
|
:aria-label="isDark ? 'Light mode' : 'Dark mode'"
|
||||||
|
>
|
||||||
|
<span v-if="isDark">☀</span>
|
||||||
|
<span v-else>⏾</span>
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
@@ -15,6 +15,8 @@ limitations under the License.
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import DarkModeToggleButton from '@/features/colorTheme/components/DarkModeToggleButton.vue';
|
||||||
|
|
||||||
import { inject } from 'vue';
|
import { inject } from 'vue';
|
||||||
import logo from '@/assets/logo.svg';
|
import logo from '@/assets/logo.svg';
|
||||||
|
|
||||||
@@ -27,12 +29,7 @@ const isDark = inject('isDark');
|
|||||||
</RouterLink>
|
</RouterLink>
|
||||||
<ul class="right-links">
|
<ul class="right-links">
|
||||||
<li>
|
<li>
|
||||||
<button class="dark-mode-toggle"
|
<DarkModeToggleButton />
|
||||||
@click="isDark = !isDark"
|
|
||||||
:aria-label="isDark ? 'Light mode' : 'Dark mode'">
|
|
||||||
<span v-if="isDark">☀</span>
|
|
||||||
<span v-else>⏾</span>
|
|
||||||
</button>
|
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|||||||
Reference in New Issue
Block a user