From 479690d2b21efe2668a11dab2f75a34a142f23f3 Mon Sep 17 00:00:00 2001 From: Leni Aniva Date: Fri, 11 Oct 2024 11:45:19 -0700 Subject: [PATCH 01/14] feat: Implement dark mode switch --- src/app.css | 4 +++ src/lib/components/ThemeSwitch.svelte | 39 +++++++++++++++++++++++++++ src/lib/theme.ts | 13 +++++++++ src/routes/+layout.svelte | 2 +- src/routes/+page.svelte | 6 ++++- src/routes/Navbar.svelte | 2 ++ 6 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 src/lib/components/ThemeSwitch.svelte create mode 100644 src/lib/theme.ts diff --git a/src/app.css b/src/app.css index 193a062..b761127 100644 --- a/src/app.css +++ b/src/app.css @@ -71,6 +71,10 @@ } } +body { + transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out; +} + @layer base { * { @apply border-border; diff --git a/src/lib/components/ThemeSwitch.svelte b/src/lib/components/ThemeSwitch.svelte new file mode 100644 index 0000000..cd4f708 --- /dev/null +++ b/src/lib/components/ThemeSwitch.svelte @@ -0,0 +1,39 @@ + + + + + diff --git a/src/lib/theme.ts b/src/lib/theme.ts new file mode 100644 index 0000000..55ad19f --- /dev/null +++ b/src/lib/theme.ts @@ -0,0 +1,13 @@ +import { writable } from 'svelte/store' +import { browser } from "$app/environment" + +type Theme = 'tokiwa' | 'star' + +const userTheme = browser && localStorage.getItem('color-scheme') + +export const theme = writable(userTheme ?? 'tokiwa') + +// set the theme +export function setTheme(newTheme: Theme) { + theme.set(newTheme) +} diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 8c0ad4f..7b2e80b 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -40,7 +40,7 @@ color: rgb(128,128,128); pointer-events: none; } - :global(a) { + :global(a), :global(button) { color: theme('colors.eucalyptus.400'); &:hover, &:focus { diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 04c862e..1b5e70d 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -2,6 +2,7 @@ import { routes } from "$lib/sitemap.ts" import { Separator } from "$lib/components/ui/separator/index.js"; import { Rss } from "lucide-svelte"; + import ThemeSwitch from "$lib/components/ThemeSwitch.svelte" let scrollPosition: number = .5; let scrollHeight: number = 1; let progress: number = 0; @@ -58,6 +59,8 @@ {/if} {/each} + + @@ -65,7 +68,7 @@
-
+
@@ -130,6 +133,7 @@ main { width: 100%; @apply bg-background; + @apply dark:bg-gray-800; box-shadow: 0px -5px 10px 10px rgba(200,200,200,0.4); } diff --git a/src/routes/Navbar.svelte b/src/routes/Navbar.svelte index cc0e47c..0f63ef0 100644 --- a/src/routes/Navbar.svelte +++ b/src/routes/Navbar.svelte @@ -2,6 +2,7 @@ import { page } from '$app/stores'; import { routes } from "$lib/sitemap.ts" import { name } from '$content/metadata.json'; + import ThemeSwitch from "$lib/components/ThemeSwitch.svelte" import { Rss } from "lucide-svelte"; function isCurrentLink(pathname, route) { @@ -19,6 +20,7 @@ class:disabled-link={item.disabled} href={item.route}>{item.name} {/each} +
-- 2.44.1 From 20f663e654a118b90d96523a1ebbca73ab191e80 Mon Sep 17 00:00:00 2001 From: Leni Aniva Date: Fri, 11 Oct 2024 11:49:58 -0700 Subject: [PATCH 02/14] feat: Glowing links in dark mode --- src/routes/+layout.svelte | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 7b2e80b..ee365b8 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -107,6 +107,11 @@ gap: 20px; } } + @media (prefers-color-scheme: dark) { + :global(a), :global(button) { + text-shadow: 0 0 5px theme('colors.eucalyptus.400'); + } + } main { width: min(100vw, max(50vw, 100vh)); grid-area: content; -- 2.44.1 From e8ef1d6a0ebe37abcac2cb844125bf6339336b4f Mon Sep 17 00:00:00 2001 From: Leni Aniva Date: Fri, 11 Oct 2024 11:50:31 -0700 Subject: [PATCH 03/14] fix: Glowing links inherit colour --- src/routes/+layout.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index ee365b8..17b941b 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -109,7 +109,7 @@ } @media (prefers-color-scheme: dark) { :global(a), :global(button) { - text-shadow: 0 0 5px theme('colors.eucalyptus.400'); + text-shadow: 0 0 5px; } } main { -- 2.44.1 From 95095083c39d2337b491edf3fadfa87573e40e08 Mon Sep 17 00:00:00 2001 From: Leni Aniva Date: Fri, 11 Oct 2024 14:43:20 -0700 Subject: [PATCH 04/14] refactor: Move global styles to `app.css` --- .pre-commit-config.yaml | 2 +- src/app.css | 57 ++++++++++++++++++++++++++++++++++++++ src/routes/+layout.svelte | 58 --------------------------------------- 3 files changed, 58 insertions(+), 59 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4e128de..3e6b0fa 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,7 @@ repos: hooks: - id: conventional-pre-commit stages: [commit-msg] - args: [feat, fix, chore, test, build, merge] + args: [feat, fix, chore, test, build, merge, refactor] - repo: local hooks: - id: eslint diff --git a/src/app.css b/src/app.css index b761127..329d28d 100644 --- a/src/app.css +++ b/src/app.css @@ -95,3 +95,60 @@ html { hr { @apply separator; } + +a, button { + color: theme('colors.eucalyptus.400'); + &:hover, + &:focus { + color: theme('colors.java.500'); + } +} +.dark a:not(.disabled-link),button { + text-shadow: 0 0 5px; +} +.nav-link { + @apply text-lg; + font-weight: 500; + font-family: serif; +} +a.disabled-link { + color: rgb(128,128,128); + pointer-events: none; +} +a:not(.icon) { + position: relative; + text-decoration: inherit; + + &::after { + content: ""; + display: block; + width: 100%; + position: absolute; + height: 2px; + bottom: 0; + left: 0; + background-color: theme('colors.java.500'); + transform: scaleX(0); + transition: transform 0.3s ease; + } + + &:hover, + &:focus { + &::after { + content: ""; + position: absolute; + transform: scaleX(1); + } + } +} +a.current-link { + color: theme('colors.magenta.500'); + + &::after { + background-color: theme('colors.magenta.500'); + } + &:hover, + &:focus { + color: theme('colors.magenta.500'); + } +} diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 17b941b..bdee40b 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -31,59 +31,6 @@ {/if}