Skip to content

Commit

Permalink
feat: add dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentHardouin committed May 3, 2024
1 parent 1cb78a4 commit 01f423d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
</script>

<template>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<nav class="navbar navbar-expand-lg bg-body-tertiary">
<div class="container-fluid">
<RouterLink class="navbar-brand" to="/">
Métro Travel
Expand Down
13 changes: 13 additions & 0 deletions src/handle-theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const darkModeMedia = window.matchMedia('(prefers-color-scheme: dark)');

darkModeMedia.addEventListener('change', setTheme);

function setTheme() {
const theme = darkModeMedia.matches ? 'dark' : 'light';
document.documentElement.setAttribute('data-theme', theme);
document.documentElement.setAttribute('data-bs-theme', theme);
}

export function initTheme() {
setTheme();
}
4 changes: 4 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import App from './App.vue';

import { router } from './router';

import { initTheme } from './handle-theme.js';

const app = createApp(App);

app.use(router).mount('#app');

initTheme();

0 comments on commit 01f423d

Please sign in to comment.