add DarkMode with Button #51

Merged
jakob.scheid merged 7 commits from feature/dark-mode into main 2026-05-15 12:47:26 +02:00
3 changed files with 62 additions and 8 deletions
+12
View File
@@ -17,9 +17,15 @@ 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>
<div :class="{ dark: isDark }" class="app-wrapper">
<Navbar /> <Navbar />
<div class="main-content"> <div class="main-content">
@@ -27,6 +33,7 @@ import Footer from './features/footer/components/Footer.vue';
</div> </div>
<Footer /> <Footer />
</div>
</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>
+28 -1
View File
@@ -13,13 +13,24 @@ 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">
<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> </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>
+15
View File
@@ -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);
}