1
0
mirror of https://github.com/aquatix/digimarks.git synced 2025-12-06 22:05:09 +01:00

Initial theme toggler

This commit is contained in:
2025-05-08 19:13:17 +02:00
parent faae900b06
commit d9e8ca76fe
3 changed files with 42 additions and 3 deletions

View File

@@ -2,6 +2,31 @@
* digimarks styling
*/
html[data-theme='light'] {
--background-color: #fff;
--text-color: #121416d8;
--link-color: #543fd7;
}
html[data-theme='dark'] {
--background-color: #212a2e;
--text-color: #F7F8F8;
--link-color: #828fff;
}
body {
background: var(--background-color);
color: var(--text-color);
}
a {
color: var(--link-color);
}
a:hover {
text-decoration: underline;
filter: brightness(80%);
}
/* Active element, e.g. a button */
.active {

View File

@@ -9,6 +9,8 @@ document.addEventListener('alpine:init', () => {
bookmarks: [],
tags: [],
theme: Alpine.$persist('light').as('theme'),
show_bookmarks: Alpine.$persist(true).as('show_bookmarks'),
show_bookmarks_list: Alpine.$persist(true).as('show_bookmarks_list'),
show_bookmarks_cards: Alpine.$persist(false).as('show_bookmarks_cards'),
@@ -39,6 +41,16 @@ document.addEventListener('alpine:init', () => {
}, 1000);
},
async toggleTheme() {
/* TBD: loop through themes instead of dark/light modes */
if (this.theme === 'dark') {
this.theme = 'light';
} else {
this.theme = 'dark';
}
document.documentElement.setAttribute('data-theme', this.theme);
},
async loadCache() {
if (this.userKey in this.cache) {
console.log('Loading bookmarks from cache for user "' + this.userKey + '"');
@@ -75,8 +87,7 @@ document.addEventListener('alpine:init', () => {
this.cache[this.userKey]['bookmarks'] = result;
let tags_response = await fetch('/api/v1/' + this.userKey + '/tags/');
let tags_result = await tags_response.json();
this.cache[this.userKey]['tags'] = tags_result;
this.cache[this.userKey]['tags'] = await tags_response.json();
this.loading = false;
},

View File

@@ -18,6 +18,9 @@
<li>
<button x-data>add bookmark</button>
</li>
<li>
<button @click="$store.digimarks.toggleTheme()">theme</button>
</li>
<li><input x-model="$store.digimarks.search" placeholder="Search..."></li>
<li x-show="$store.digimarks.loading">&orarr;</li>
</ul>