From f136be197ca0a1287d7039525e3c286b6f379a97 Mon Sep 17 00:00:00 2001 From: Unbewohnte Date: Mon, 28 Oct 2024 07:18:03 +0300 Subject: [PATCH] UI: Light and dark theme --- pages/base.html | 23 +++++++++++++++++++++++ static/images/brightness-high.svg | 3 +++ static/images/moon-stars.svg | 4 ++++ 3 files changed, 30 insertions(+) create mode 100644 static/images/brightness-high.svg create mode 100644 static/images/moon-stars.svg diff --git a/pages/base.html b/pages/base.html index 9d59350..14c9874 100644 --- a/pages/base.html +++ b/pages/base.html @@ -27,6 +27,11 @@
  • About
  • +
    + +
    Login Sign-up @@ -62,6 +67,24 @@ return; } + // Theme + let theme = localStorage.getItem("theme"); + if (theme) { + document.documentElement.setAttribute('data-bs-theme', theme); + } + + document.getElementById('theme-switch-btn').addEventListener('click', () => { + if (document.documentElement.getAttribute('data-bs-theme') == 'dark') { + document.documentElement.setAttribute('data-bs-theme','light'); + localStorage.setItem("theme", "light"); + document.getElementById("theme-svg").src = "/static/images/brightness-high.svg"; + } else { + document.documentElement.setAttribute('data-bs-theme','dark'); + localStorage.setItem("theme", "dark"); + document.getElementById("theme-svg").src = "/static/images/moon-stars.svg"; + } + }) + }, false) diff --git a/static/images/brightness-high.svg b/static/images/brightness-high.svg new file mode 100644 index 0000000..f00d050 --- /dev/null +++ b/static/images/brightness-high.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/static/images/moon-stars.svg b/static/images/moon-stars.svg new file mode 100644 index 0000000..ae138c2 --- /dev/null +++ b/static/images/moon-stars.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file