-
Notifications
You must be signed in to change notification settings - Fork 4
support light and dark #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JerryWu1234
wants to merge
20
commits into
QwikDev:main
Choose a base branch
from
JerryWu1234:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d170676
feat(ui): integrate devtools plugin and add dark mode support
JerryWu1234 ab9b2d4
Add light and dark mode support using Tailwind CSS
openhands-agent bc6f85f
Fix ThemeToggle component and update vite.config.mts for server confi…
openhands-agent b343c14
refactor(ui): remove unused CSS variables and streamline theme config…
JerryWu1234 89c6302
refactor(vite): remove dev server host and port config
JerryWu1234 2022ec4
refactor(vite): remove dev server host and port config
JerryWu1234 bb24361
Merge pull request #3 from JerryWu1234/textDarkAndLight
JerryWu1234 2353764
feat(theme): implement theme switching with persistence
JerryWu1234 3a81fff
style(ui): standardize code formatting and fix linting issues
JerryWu1234 f11cc88
refactor(theme): simplify theme handling and remove unused code
JerryWu1234 6943d10
fix(devtools): remove unused ThemeScript import and fix panel visibil…
JerryWu1234 177a8be
style: enforce single quotes in codebase and update prettier config
JerryWu1234 52356f6
refactor(theme): consolidate theme handling and cleanup
JerryWu1234 437278b
feat(ThemeToggle): add auto theme option and improve theme handling
JerryWu1234 6db10ec
formate
JerryWu1234 3bd77e0
feat(ui): add ThemeToggle component with persistent theme selection
JerryWu1234 02ddcd0
fix situation which didn't set default value
JerryWu1234 3699f57
chore: update @qwik.dev/core and @qwik.dev/router to beta versions, u…
JerryWu1234 9e4be8f
refactor(ThemeToggle): remove console logs and improve type annotatio…
JerryWu1234 ec2f527
fix
JerryWu1234 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { component$, createSignal, isBrowser, Signal,event$ } from "@qwik.dev/core"; | ||
import { HiMoonMini, HiSunMini } from "@qwikest/icons/heroicons"; | ||
import { useDark } from "../../hooks/useDark"; | ||
import { themeStorageKey } from '../router-head/theme-script'; | ||
|
||
type ThemeName = 'dark' | 'light' | undefined; | ||
|
||
export const getTheme = (): ThemeName => { | ||
let theme; | ||
try { | ||
theme = localStorage.getItem(themeStorageKey); | ||
} catch { | ||
// | ||
} | ||
if (theme) { | ||
return theme as ThemeName; | ||
} else { | ||
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; | ||
} | ||
}; | ||
|
||
let currentThemeSignal: Signal<ThemeName>; | ||
export const getThemeSignal = () => { | ||
if (!isBrowser) { | ||
throw new Error('getThemeSignal is only available in the browser'); | ||
} | ||
if (!currentThemeSignal) { | ||
currentThemeSignal = createSignal(getTheme()); | ||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => { | ||
currentThemeSignal.value = getTheme(); | ||
}); | ||
} | ||
return currentThemeSignal; | ||
}; | ||
|
||
export const setTheme = (theme: ThemeName) => { | ||
if (!theme) { | ||
localStorage.removeItem(themeStorageKey); | ||
theme = getTheme(); | ||
} else { | ||
localStorage.setItem(themeStorageKey, theme); | ||
} | ||
document.firstElementChild?.setAttribute('data-theme', theme!); | ||
if (currentThemeSignal) { | ||
currentThemeSignal.value = theme; | ||
} | ||
}; | ||
|
||
export const ThemeToggle = component$(() => { | ||
const dark = useDark(); | ||
const onClick$ = event$(() => { | ||
const currentTheme = getTheme(); | ||
setTheme(currentTheme === 'dark' ? 'light' : 'dark'); | ||
}); | ||
return ( | ||
<button | ||
onClick$={onClick$} | ||
class="flex h-8 w-8 items-center justify-center rounded-md bg-background text-foreground hover:bg-accent/10" | ||
> | ||
{dark.isDark.value ? ( | ||
<HiSunMini class="h-5 w-5" /> | ||
) : ( | ||
<HiMoonMini class="h-5 w-5" /> | ||
)} | ||
</button> | ||
); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const themeStorageKey = 'theme-preference'; | ||
export const ThemeScript = () => { | ||
const themeScript = ` | ||
try { | ||
document.firstElementChild | ||
.setAttribute('data-theme', | ||
localStorage.getItem('${themeStorageKey}') ?? | ||
(window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') | ||
); | ||
} catch (e) { }`.replace(/\s+/g, ''); | ||
return themeScript | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.