Improved theme switching
This commit is contained in:
parent
a83a4fd208
commit
eb822e6418
@ -30,12 +30,11 @@ component Sidebar(user *arn.User)
|
|||||||
//- SidebarButton("Groups", "/groups", "users")
|
//- SidebarButton("Groups", "/groups", "users")
|
||||||
//- SidebarButton("Statistics", "/statistics", "pie-chart")
|
//- SidebarButton("Statistics", "/statistics", "pie-chart")
|
||||||
|
|
||||||
.buttons
|
|
||||||
button.action(data-action="lightTheme", data-trigger="click") Light
|
|
||||||
button.action(data-action="darkTheme", data-trigger="click") Dark
|
|
||||||
|
|
||||||
.spacer
|
.spacer
|
||||||
|
|
||||||
|
//- .theme-switcher
|
||||||
|
//- button.theme-switcher-button.action(data-action="toggleTheme", data-trigger="click") Switch theme
|
||||||
|
|
||||||
.sidebar-link(aria-label="Search")
|
.sidebar-link(aria-label="Search")
|
||||||
.sidebar-button
|
.sidebar-button
|
||||||
Icon("search")
|
Icon("search")
|
||||||
@ -48,6 +47,11 @@ component Sidebar(user *arn.User)
|
|||||||
if user.Role == "editor"
|
if user.Role == "editor"
|
||||||
SidebarButton("Editor", "/editor", "pencil")
|
SidebarButton("Editor", "/editor", "pencil")
|
||||||
|
|
||||||
|
a.sidebar-link.action(href="#", data-action="toggleTheme", data-trigger="click")
|
||||||
|
.sidebar-button
|
||||||
|
Icon("paint-brush")
|
||||||
|
span.sidebar-text Theme
|
||||||
|
|
||||||
SidebarButton("Help", "/thread/I3MMiOtzR", "question-circle")
|
SidebarButton("Help", "/thread/I3MMiOtzR", "question-circle")
|
||||||
|
|
||||||
if user != nil
|
if user != nil
|
||||||
|
@ -47,6 +47,9 @@ sidebar-spacing-y = 0.7rem
|
|||||||
.sidebar-link
|
.sidebar-link
|
||||||
color text-color
|
color text-color
|
||||||
|
|
||||||
|
:hover
|
||||||
|
cursor pointer
|
||||||
|
|
||||||
&.active
|
&.active
|
||||||
.sidebar-button
|
.sidebar-button
|
||||||
color tab-active-color
|
color tab-active-color
|
||||||
@ -62,4 +65,4 @@ sidebar-spacing-y = 0.7rem
|
|||||||
|
|
||||||
.icon
|
.icon
|
||||||
font-size 1rem
|
font-size 1rem
|
||||||
margin-right 0.75rem
|
margin-right 0.75rem
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { AnimeNotifier } from "../AnimeNotifier"
|
import { AnimeNotifier } from "../AnimeNotifier"
|
||||||
|
|
||||||
|
let currentTheme = "light"
|
||||||
let light = {}
|
let light = {}
|
||||||
let dark = {
|
let dark = {
|
||||||
"hue": "45",
|
"hue": "45",
|
||||||
@ -35,10 +36,18 @@ let dark = {
|
|||||||
"post-permalink-color": "var(--link-color)"
|
"post-permalink-color": "var(--link-color)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Toggle theme
|
||||||
|
export function toggleTheme() {
|
||||||
|
if(currentTheme === "light") {
|
||||||
|
darkTheme()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
lightTheme()
|
||||||
|
}
|
||||||
|
|
||||||
// Light theme
|
// Light theme
|
||||||
export function lightTheme() {
|
export function lightTheme() {
|
||||||
console.log("Light")
|
|
||||||
|
|
||||||
let root = document.documentElement
|
let root = document.documentElement
|
||||||
|
|
||||||
for(let property in light) {
|
for(let property in light) {
|
||||||
@ -48,12 +57,12 @@ export function lightTheme() {
|
|||||||
|
|
||||||
root.style.setProperty(`--${property}`, light[property])
|
root.style.setProperty(`--${property}`, light[property])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentTheme = "light"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dark theme
|
// Dark theme
|
||||||
export function darkTheme() {
|
export function darkTheme() {
|
||||||
console.log("Dark")
|
|
||||||
|
|
||||||
let root = document.documentElement
|
let root = document.documentElement
|
||||||
|
|
||||||
for(let property in dark) {
|
for(let property in dark) {
|
||||||
@ -61,7 +70,12 @@ export function darkTheme() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
light[property] = root.style.getPropertyValue(`--${property}`)
|
if(light[property] === undefined) {
|
||||||
|
light[property] = root.style.getPropertyValue(`--${property}`)
|
||||||
|
}
|
||||||
|
|
||||||
root.style.setProperty(`--${property}`, dark[property])
|
root.style.setProperty(`--${property}`, dark[property])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentTheme = "dark"
|
||||||
}
|
}
|
@ -41,7 +41,7 @@ class MyServiceWorker {
|
|||||||
currentCSP: string
|
currentCSP: string
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.cache = new MyCache("v-4")
|
this.cache = new MyCache("v-5")
|
||||||
this.currentCSP = ""
|
this.currentCSP = ""
|
||||||
|
|
||||||
self.addEventListener("install", (evt: InstallEvent) => evt.waitUntil(this.onInstall(evt)))
|
self.addEventListener("install", (evt: InstallEvent) => evt.waitUntil(this.onInstall(evt)))
|
||||||
|
Loading…
Reference in New Issue
Block a user