Skip to content

Commit

Permalink
Merge pull request #4 from bondarevpavel/dark-theme
Browse files Browse the repository at this point in the history
Added dark theme switcher
  • Loading branch information
DKunin authored Sep 30, 2022
2 parents 6b59ba9 + c3bfd19 commit 413c6a0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion css/lemon.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
<div class="container">
<div class="row">
<div class="column">
<h1>Protocol</h1>
<h1>
Protocol
<button v-if="!isDark" @click="toggleTheme">Dark theme</button>
<button v-if="isDark" @click="toggleTheme">Bright theme</button>
</h1>
<ul>
<li v-for="logItem in log" class="row">
<div class="colum">
Expand Down
16 changes: 14 additions & 2 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ function newLogItem() {

new Vue({
el: '#app',
mounted() {},
mounted() {
if (this.isDark) {
document.body.classList.add("dark-theme")
}
},
methods: {
removeLine() {
const text = event.target.parentNode.parentNode.querySelector('input').value || null;
Expand Down Expand Up @@ -55,6 +59,13 @@ new Vue({
clear() {
this.log = [newLogItem()];
this.persist();
},
toggleTheme() {
this.isDark = !this.isDark
this.isDark
? localStorage.setItem('dark-theme', '1')
: localStorage.removeItem('dark-theme')
document.body.classList.toggle("dark-theme")
}
},
template: '#user',
Expand All @@ -63,7 +74,8 @@ new Vue({
log: JSON.parse(localStorage.getItem('protocol-log')) || [
newLogItem()
],
timeOut: null
timeOut: null,
isDark: localStorage.getItem('dark-theme') !== null
};
},
computed: {}
Expand Down

0 comments on commit 413c6a0

Please sign in to comment.