feat: add manual dark toggle
This commit is contained in:
1 parent
363257087e
commit
629482e5d3
6 files changed
+92
-14
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "photon-lemmy",
|
"name": "photon-lemmy",
|
||||||
"version": "0.5.6",
|
"version": "0.5.7",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
|
|||||||
+16
-7
@@ -10,16 +10,25 @@
|
|||||||
content="Photon: An alternative lemmy client with a sleek design."
|
content="Photon: An alternative lemmy client with a sleek design."
|
||||||
/>
|
/>
|
||||||
<meta name="keywords" content="lemmy, client" />
|
<meta name="keywords" content="lemmy, client" />
|
||||||
|
<script defer type="">
|
||||||
|
const dark = () =>
|
||||||
|
localStorage.theme == 'dark' ||
|
||||||
|
((!localStorage.theme || localStorage.theme == 'system') &&
|
||||||
|
window.matchMedia('(prefers-color-scheme: dark)').matches)
|
||||||
|
|
||||||
|
if (dark()) document.documentElement.classList.add('dark')
|
||||||
|
else document.documentElement.classList.remove('dark')
|
||||||
|
|
||||||
|
window
|
||||||
|
.matchMedia('(prefers-color-scheme: dark)')
|
||||||
|
.addEventListener('change', (event) => {
|
||||||
|
if (dark()) document.documentElement.classList.add('dark')
|
||||||
|
else document.documentElement.classList.remove('dark')
|
||||||
|
})
|
||||||
|
</script>
|
||||||
%sveltekit.head%
|
%sveltekit.head%
|
||||||
</head>
|
</head>
|
||||||
<body data-sveltekit-preload-data="hover">
|
<body data-sveltekit-preload-data="hover">
|
||||||
<div style="display: contents">%sveltekit.body%</div>
|
<div style="display: contents">%sveltekit.body%</div>
|
||||||
</body>
|
</body>
|
||||||
<style>
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
:root {
|
|
||||||
background-color: black;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</html>
|
</html>
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
||||||
import { LINKED_INSTANCE_URL, instance } from '$lib/instance.js'
|
import { LINKED_INSTANCE_URL, instance } from '$lib/instance.js'
|
||||||
import { site } from '$lib/lemmy.js'
|
import { site } from '$lib/lemmy.js'
|
||||||
|
import { theme } from '$lib/ui/image.js'
|
||||||
import {
|
import {
|
||||||
ArrowLeftOnRectangle,
|
ArrowLeftOnRectangle,
|
||||||
ArrowRightOnRectangle,
|
ArrowRightOnRectangle,
|
||||||
@@ -21,13 +22,16 @@
|
|||||||
Bookmark,
|
Bookmark,
|
||||||
Cog6Tooth,
|
Cog6Tooth,
|
||||||
CommandLine,
|
CommandLine,
|
||||||
|
ComputerDesktop,
|
||||||
GlobeAlt,
|
GlobeAlt,
|
||||||
Icon,
|
Icon,
|
||||||
Inbox,
|
Inbox,
|
||||||
InformationCircle,
|
InformationCircle,
|
||||||
MagnifyingGlass,
|
MagnifyingGlass,
|
||||||
|
Moon,
|
||||||
PencilSquare,
|
PencilSquare,
|
||||||
Plus,
|
Plus,
|
||||||
|
Sun,
|
||||||
UserCircle,
|
UserCircle,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
|
|
||||||
@@ -227,6 +231,31 @@
|
|||||||
<Icon src={InformationCircle} mini width={16} />
|
<Icon src={InformationCircle} mini width={16} />
|
||||||
About
|
About
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
|
<MenuButton>
|
||||||
|
<Icon
|
||||||
|
src={$theme == 'system'
|
||||||
|
? ComputerDesktop
|
||||||
|
: $theme == 'light'
|
||||||
|
? Sun
|
||||||
|
: $theme == 'dark'
|
||||||
|
? Moon
|
||||||
|
: Moon}
|
||||||
|
mini
|
||||||
|
size="16"
|
||||||
|
/>
|
||||||
|
<div class="flex flex-row flex-wrap justify-between w-full">
|
||||||
|
<span>Theme</span>
|
||||||
|
<select
|
||||||
|
bind:value={$theme}
|
||||||
|
class="ml-auto w-max"
|
||||||
|
on:click|stopPropagation={() => {}}
|
||||||
|
>
|
||||||
|
<option value="system">System</option>
|
||||||
|
<option value="light">Light</option>
|
||||||
|
<option value="dark">Dark</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</MenuButton>
|
||||||
<hr class="dark:opacity-10 w-[90%] my-2 mx-auto" />
|
<hr class="dark:opacity-10 w-[90%] my-2 mx-auto" />
|
||||||
<li class="flex flex-col px-4 py-1 mx-auto my-1 text-xs w-full">
|
<li class="flex flex-col px-4 py-1 mx-auto my-1 text-xs w-full">
|
||||||
<div class="flex flex-row justify-center gap-2 w-full">
|
<div class="flex flex-row justify-center gap-2 w-full">
|
||||||
|
|||||||
@@ -11,3 +11,44 @@ export const isVideo = (inputUrl: string | undefined) => {
|
|||||||
|
|
||||||
return url.endsWith('mp4') || url.endsWith('webm') || url.endsWith('mov')
|
return url.endsWith('mp4') || url.endsWith('webm') || url.endsWith('mov')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import { writable } from 'svelte/store'
|
||||||
|
|
||||||
|
export const theme = writable<'system' | 'light' | 'dark'>('system')
|
||||||
|
|
||||||
|
export const toggleTheme = () => {
|
||||||
|
theme.update((theme) => {
|
||||||
|
if (theme == 'light') {
|
||||||
|
return 'dark'
|
||||||
|
} else if (theme == 'dark') {
|
||||||
|
return 'system'
|
||||||
|
} else {
|
||||||
|
return 'light'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof localStorage != 'undefined') {
|
||||||
|
const localTheme: 'system' | 'light' | 'dark' =
|
||||||
|
(localStorage.getItem('theme') as 'system' | 'light' | 'dark') || 'system'
|
||||||
|
|
||||||
|
theme.update((theme) => localTheme)
|
||||||
|
|
||||||
|
theme.subscribe((theme) => {
|
||||||
|
if (typeof document != 'undefined') {
|
||||||
|
const prefersDark = window.matchMedia(
|
||||||
|
'(prefers-color-scheme: dark)'
|
||||||
|
).matches
|
||||||
|
|
||||||
|
const html = document.querySelector('html')
|
||||||
|
|
||||||
|
if (theme == 'system') {
|
||||||
|
html?.classList.toggle('dark', prefersDark)
|
||||||
|
} else {
|
||||||
|
html?.classList.toggle('dark', theme === 'dark')
|
||||||
|
}
|
||||||
|
|
||||||
|
localStorage.setItem('theme', theme)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
+4
-6
@@ -2,17 +2,15 @@
|
|||||||
@tailwind components;
|
@tailwind components;
|
||||||
@tailwind utilities;
|
@tailwind utilities;
|
||||||
|
|
||||||
:root {
|
body {
|
||||||
@apply bg-slate-50 dark:bg-zinc-950 text-slate-900
|
@apply bg-slate-50 dark:bg-zinc-950 text-slate-900
|
||||||
dark:text-zinc-100 !important;
|
dark:text-zinc-100 !important;
|
||||||
accent-color: #000;
|
accent-color: #000;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
.dark {
|
||||||
:root {
|
accent-color: #fff;
|
||||||
color-scheme: dark;
|
color-scheme: dark;
|
||||||
accent-color: #fff;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
html,
|
html,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/** @type {import('tailwindcss').Config} */
|
/** @type {import('tailwindcss').Config} */
|
||||||
export default {
|
export default {
|
||||||
content: ['src/**/*.{js,ts,svelte,html}'],
|
content: ['src/**/*.{js,ts,svelte,html}'],
|
||||||
|
darkMode: 'class',
|
||||||
theme: {
|
theme: {
|
||||||
fontFamily: {
|
fontFamily: {
|
||||||
'sans': ['Cantarell', 'system-ui'],
|
'sans': ['Cantarell', 'system-ui'],
|
||||||
|
|||||||
Reference in new issue
Block a user