Skip to content

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
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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 May 22, 2025
ab9b2d4
Add light and dark mode support using Tailwind CSS
openhands-agent May 23, 2025
bc6f85f
Fix ThemeToggle component and update vite.config.mts for server confi…
openhands-agent May 23, 2025
b343c14
refactor(ui): remove unused CSS variables and streamline theme config…
JerryWu1234 May 24, 2025
89c6302
refactor(vite): remove dev server host and port config
JerryWu1234 May 24, 2025
2022ec4
refactor(vite): remove dev server host and port config
JerryWu1234 May 24, 2025
bb24361
Merge pull request #3 from JerryWu1234/textDarkAndLight
JerryWu1234 May 24, 2025
2353764
feat(theme): implement theme switching with persistence
JerryWu1234 May 28, 2025
3a81fff
style(ui): standardize code formatting and fix linting issues
JerryWu1234 May 29, 2025
f11cc88
refactor(theme): simplify theme handling and remove unused code
JerryWu1234 May 29, 2025
6943d10
fix(devtools): remove unused ThemeScript import and fix panel visibil…
JerryWu1234 Jun 3, 2025
177a8be
style: enforce single quotes in codebase and update prettier config
JerryWu1234 Jun 3, 2025
52356f6
refactor(theme): consolidate theme handling and cleanup
JerryWu1234 Jun 3, 2025
437278b
feat(ThemeToggle): add auto theme option and improve theme handling
JerryWu1234 Jun 4, 2025
6db10ec
formate
JerryWu1234 Jun 5, 2025
3bd77e0
feat(ui): add ThemeToggle component with persistent theme selection
JerryWu1234 Jun 5, 2025
02ddcd0
fix situation which didn't set default value
JerryWu1234 Jun 5, 2025
3699f57
chore: update @qwik.dev/core and @qwik.dev/router to beta versions, u…
JerryWu1234 Jun 6, 2025
9e4be8f
refactor(ThemeToggle): remove console logs and improve type annotatio…
JerryWu1234 Jun 6, 2025
ec2f527
fix
JerryWu1234 Jun 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,389 changes: 3,389 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"import": "./lib/index.qwik.mjs"
}
},
"types": "./lib-types/ui/src/index.d.ts",
"files": [
"lib",
"lib-types"
Expand All @@ -33,7 +34,8 @@
"qwik": "qwik"
},
"peerDependencies": {
"@qwik.dev/core": "^2.0.0-alpha.9"
"@qwik.dev/core": "^2.0.0-alpha.9",
"@devtools/plugin": "workspace:*"
},
"devDependencies": {
"@devtools/kit": "workspace:*",
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/components/DevtoolsButton/DevtoolsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ export const DevtoolsButton = component$(({ state }: DevtoolsButtonProps) => {
<div
ref={elementRef}
class={{
"fixed flex h-9 w-9 origin-center items-center justify-center rounded-lg border border-white/10 bg-zinc-900 backdrop-blur-md select-none": true,
"rotate-90 border-emerald-500/50 bg-zinc-900/95 shadow-lg shadow-emerald-500/35": state.isOpen.value && !isDragging.value,
"fixed flex h-9 w-9 origin-center items-center justify-center rounded-lg border border-border bg-background backdrop-blur-md select-none": true,
"rotate-90 border-accent/50 bg-background/95 shadow-lg shadow-accent/35": state.isOpen.value && !isDragging.value,
"cursor-grab": !isDragging.value,
"cursor-grabbing": isDragging.value,
"transition-all duration-300 ease-in-out": !isDragging.value,
Expand Down
5 changes: 3 additions & 2 deletions packages/ui/src/components/DevtoolsPanel/DevtoolsPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { component$, Slot, useSignal, useTask$,isBrowser } from "@qwik.dev/core";
import { component$, Slot, useSignal, useTask$, isBrowser } from "@qwik.dev/core";
import { State } from "../../types/state";


interface DevtoolsPanelProps {
state: State;
}
Expand Down Expand Up @@ -42,7 +43,7 @@ export const DevtoolsPanel = component$(({ state }: DevtoolsPanelProps) => {
return (
<div
ref={panelRef}
class="fixed bottom-6 right-6 flex h-[calc(100vh-3rem)] w-[calc(100vw-3rem)] translate-y-0 transform overflow-hidden rounded-lg border-2 border-white/10 bg-zinc-900 text-white backdrop-blur-lg transition-transform duration-300 ease-in-out"
class="fixed bottom-6 right-6 flex h-[calc(100vh-3rem)] w-[calc(100vw-3rem)] translate-y-0 transform overflow-hidden rounded-lg border-2 border-border bg-background text-foreground backdrop-blur-lg transition-transform duration-300 ease-in-out"
>
<Slot />
</div>
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/components/Tab/Tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export const Tab = component$<TabProps>(({ state, id, title }) => {
class={{
"flex h-10 w-10 items-center justify-center rounded-lg p-2.5 transition-all duration-200":
true,
"bg-white/5 text-zinc-400 hover:bg-white/10 hover:text-white":
"bg-foreground/5 text-muted-foreground hover:bg-foreground/10 hover:text-foreground":
state.activeTab !== id,
"bg-emerald-500 text-white shadow-lg shadow-emerald-500/35":
"bg-accent text-accent-foreground shadow-lg shadow-accent/35":
state.activeTab === id,
}}
>
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/TabContent/TabContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { component$, Slot } from "@qwik.dev/core";
export const TabContent = component$(() => {
return (
<div class="space-y-6 flex-col flex h-full w-full">
<div class="flex items-center justify-between border-b border-zinc-700 pb-4">
<div class="flex items-center justify-between border-b border-border pb-4">
<Slot name="title" />
</div>

Expand Down
67 changes: 67 additions & 0 deletions packages/ui/src/components/ThemeToggle/ThemeToggle.tsx
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>
);
});
12 changes: 12 additions & 0 deletions packages/ui/src/components/router-head/theme-script.tsx
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
};
Loading