generated from Seekra/repository-template
add DarkMode with Button #51
+17
-5
@@ -17,16 +17,23 @@ limitations under the License.
|
|||||||
<script setup>
|
<script setup>
|
||||||
import Navbar from './features/nav/components/Navbar.vue';
|
import Navbar from './features/nav/components/Navbar.vue';
|
||||||
import Footer from './features/footer/components/Footer.vue';
|
import Footer from './features/footer/components/Footer.vue';
|
||||||
|
import { ref, provide, watch } from 'vue';
|
||||||
|
|
||||||
|
const isDark = ref(localStorage.getItem('theme') === 'dark');
|
||||||
|
provide('isDark', isDark);
|
||||||
|
watch(isDark, val => localStorage.setItem('theme', val ? 'dark' : 'light'));
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Navbar />
|
<div :class="{ dark: isDark }" class="app-wrapper">
|
||||||
|
<Navbar />
|
||||||
|
|
||||||
<div class="main-content">
|
<div class="main-content">
|
||||||
<router-view />
|
<router-view />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Footer />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Footer />
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@@ -37,4 +44,9 @@ import Footer from './features/footer/components/Footer.vue';
|
|||||||
width: calc(100% - var(--main-content-padding-x) * 2);
|
width: calc(100% - var(--main-content-padding-x) * 2);
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
}
|
}
|
||||||
|
.app-wrapper {
|
||||||
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -13,14 +13,25 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
<script setup>
|
||||||
|
import { inject } from 'vue';
|
||||||
|
const isDark = inject('isDark');
|
||||||
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<nav class="global-nav">
|
<nav class="global-nav">
|
||||||
<RouterLink to="/" class="link button link">
|
<RouterLink to="/" class="link button link">
|
||||||
<span id="logo">Seekra</span>
|
<span id="logo">Seekra</span>
|
||||||
</RouterLink>
|
</RouterLink>
|
||||||
<ul class="right-links">
|
<ul class="right-links">
|
||||||
</ul>
|
<li>
|
||||||
|
<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>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -48,4 +59,20 @@ limitations under the License.
|
|||||||
.global-nav .right-links a:hover{
|
.global-nav .right-links a:hover{
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
.dark-mode-toggle {
|
||||||
|
background: none;
|
||||||
|
border: 1.5px solid var(--light-d-3);
|
||||||
|
border-radius: 50%;
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 1rem;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark-mode-toggle:hover {
|
||||||
|
background: var(--light-d-2);
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -60,3 +60,18 @@
|
|||||||
--dark-bg: var(--black-l-2);
|
--dark-bg: var(--black-l-2);
|
||||||
--light-bg: oklch(1 0 0);
|
--light-bg: oklch(1 0 0);
|
||||||
}
|
}
|
||||||
|
.dark {
|
||||||
|
color-scheme: dark;
|
||||||
|
background-color: var(--dark-bg);
|
||||||
|
color: var(--white-d-1);
|
||||||
|
|
||||||
|
--light: var(--black-l-8);
|
||||||
|
--light-d-1: var(--black-l-7);
|
||||||
|
--light-d-2: var(--black-l-6);
|
||||||
|
--light-d-3: var(--black-l-5);
|
||||||
|
--light-d-4: var(--black-l-4);
|
||||||
|
--light-d-5: var(--black-l-3);
|
||||||
|
--light-d-6: var(--black-l-2);
|
||||||
|
--light-d-7: var(--black-l-1);
|
||||||
|
--light-d-8: var(--black);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user