Skip to content

Commit 629ae73

Browse files
committed
Add dark mode configurations
1 parent 60f3ecd commit 629ae73

File tree

5 files changed

+42
-35
lines changed

5 files changed

+42
-35
lines changed

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<link rel="icon" href="./favicon.png" />
88
<title><%= htmlWebpackPlugin.options.title %></title>
99
</head>
10-
<body>
10+
<body id="app-theme" class="app-theme">
1111
<noscript>
1212
<strong
1313
>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't

src/components/ThemeSwitcher.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
href="#"
44
class="text-copy-primary hover:text-gray-600"
55
@click.prevent="toggleTheme"
6-
data-cypress="switchTheme"
76
>
87
<svg
9-
v-if="theme === 'theme-light'"
8+
v-if="theme === 'theme'"
109
xmlns="http://www.w3.org/2000/svg"
1110
width="24"
1211
height="24"
@@ -49,10 +48,10 @@ export default {
4948
},
5049
methods: {
5150
toggleTheme() {
52-
const newTheme =
53-
this.theme === 'theme-light' ? 'theme-dark' : 'theme-light';
51+
const newTheme = this.theme === 'light' ? 'dark' : 'light';
5452
localStorage.setItem('theme', newTheme);
5553
this.$emit('themeChanged', newTheme);
54+
this.$router.go();
5655
},
5756
},
5857
};

src/components/shared/Header.vue

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<nav id="nav" class="container mx-auto bg-white" :class="theme">
2+
<nav id="nav" class="container mx-auto bg-white">
33
<div class="md:flex items-center justify-between my-6">
44
<div class="flex justify-between items-center">
55
<div class="text-2xl font-bold text-gray-800 md:text-3xl">
@@ -52,7 +52,9 @@
5252
Hire Me
5353
</button>
5454
</div>
55-
<div>
55+
<div
56+
class="ml-8 bg-gray-50 p-3 shadow-sm rounded-xl cursor-pointer"
57+
>
5658
<theme-switcher
5759
:theme="theme"
5860
@themeChanged="updateTheme"
@@ -64,8 +66,8 @@
6466
</template>
6567

6668
<script>
69+
import ThemeSwitcher from '../ThemeSwitcher';
6770
import feather from 'feather-icons';
68-
import ThemeSwitcher from '../ThemeSwitcher.vue';
6971
7072
export default {
7173
components: {
@@ -77,15 +79,18 @@ export default {
7779
theme: '',
7880
};
7981
},
80-
toggle() {
81-
this.isOpen = !this.isOpen;
82-
},
83-
updateTheme(theme) {
84-
this.theme = theme;
82+
83+
created() {
84+
this.theme = localStorage.getItem('theme') || 'light';
8585
},
8686
mounted() {
8787
feather.replace();
88-
this.theme = localStorage.getItem('theme') || 'theme-light';
88+
this.theme = localStorage.getItem('theme') || 'light';
89+
},
90+
methods: {
91+
updateTheme(theme) {
92+
this.theme = theme;
93+
},
8994
},
9095
updated() {
9196
feather.replace();

src/main.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,14 @@ feather.replace();
1010
createApp(App)
1111
.use(router)
1212
.mount('#app');
13+
14+
const appTheme = localStorage.getItem('theme');
15+
16+
if (
17+
appTheme === 'dark' &&
18+
document.querySelector('body').classList.contains('app-theme')
19+
) {
20+
document.querySelector('body').classList.add('bg-background-primary-dark');
21+
} else {
22+
document.querySelector('body').classList.add('bg-background-primary-light');
23+
}

tailwind.config.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@ module.exports = {
22
purge: { content: ['./public/**/*.html', './src/**/*.vue'] },
33
darkMode: false, // or 'media' or 'class'
44
theme: {
5-
extend: {},
5+
extend: {
6+
colors: {
7+
background: {
8+
'primary-light': '#F7F8FC',
9+
'secondary-light': '#FFFFFF',
10+
'ternary-light': '#f6f7f8',
11+
'primary-dark': '#0D2438',
12+
'secondary-dark': '#102D44',
13+
'ternary-dark': '#1E3851',
14+
},
15+
},
16+
},
617
container: {
718
padding: {
819
DEFAULT: '1rem',
@@ -14,26 +25,7 @@ module.exports = {
1425
},
1526
},
1627
variants: {
17-
extend: {
18-
colors: {
19-
background: {
20-
primary: 'var(--bg-background-primary)',
21-
secondary: 'var(--bg-background-secondary)',
22-
tertiary: 'var(--bg-background-tertiary)',
23-
24-
form: 'var(--bg-background-form)',
25-
},
26-
27-
copy: {
28-
primary: 'var(--text-copy-primary)',
29-
secondary: 'var(--text-copy-hover)',
30-
},
31-
32-
'border-color': {
33-
primary: 'var(--border-border-color-primary)',
34-
},
35-
},
36-
},
28+
extend: {},
3729
},
3830
plugins: [
3931
require('@tailwindcss/forms')({

0 commit comments

Comments
 (0)