-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Feat/console dark #1566
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
Merged
xieyxclack
merged 6 commits into
agentscope-ai:main
from
zhaozhuang521:feat/console_dark
Mar 17, 2026
Merged
Feat/console dark #1566
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9dcf753
feat(console): Added night mode to the console
22b98bd
feat(console): Added night mode to the console
c045d30
Merge branch 'main' into feat/console_dark
6fffb7b
Merge latest main into feat/console_dark
47eed5d
Merge remote-tracking branch 'origin/main' into feat/console_dark
18147a4
fix(console_Models): card sets minimum width
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
36 changes: 36 additions & 0 deletions
36
console/src/components/ThemeToggleButton/index.module.less
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,36 @@ | ||
| /* ---- Theme toggle button ---- */ | ||
| .toggleBtn { | ||
| display: inline-flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| height: 32px; | ||
| border: none; | ||
| border-radius: 8px; | ||
| background: transparent; | ||
| cursor: pointer; | ||
| transition: | ||
| background 0.15s ease, | ||
| color 0.15s ease; | ||
| color: #555; | ||
| padding: 0; | ||
| flex-shrink: 0; | ||
|
|
||
| &:hover { | ||
| background: rgba(97, 92, 237, 0.08); | ||
| color: #615ced; | ||
| } | ||
| } | ||
|
|
||
| .icon { | ||
| font-size: 16px; | ||
| } | ||
|
|
||
| /* Dark mode overrides */ | ||
| :global(.dark-mode) .toggleBtn { | ||
| color: #ccc; | ||
|
|
||
| &:hover { | ||
| background: rgba(255, 255, 255, 0.1); | ||
| color: #fff; | ||
| } | ||
| } |
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,26 @@ | ||
| import { Tooltip, Button } from "antd"; | ||
| import { SunOutlined, MoonOutlined } from "@ant-design/icons"; | ||
| import { useTheme } from "../../contexts/ThemeContext"; | ||
| import styles from "./index.module.less"; | ||
|
|
||
| /** | ||
| * ThemeToggleButton - toggles between light and dark theme. | ||
| * Displays a sun icon in dark mode and a moon icon in light mode. | ||
| */ | ||
| export default function ThemeToggleButton() { | ||
| const { isDark, toggleTheme } = useTheme(); | ||
|
|
||
| return ( | ||
| <Tooltip title={isDark ? "Light mode" : "Dark mode"}> | ||
| <Button | ||
| className={styles.toggleBtn} | ||
| onClick={toggleTheme} | ||
| aria-label={isDark ? "Switch to light mode" : "Switch to dark mode"} | ||
| type="text" | ||
| icon={isDark ? <SunOutlined /> : <MoonOutlined />} | ||
| > | ||
| {isDark ? "Light" : "Dark"} | ||
| </Button> | ||
| </Tooltip> | ||
| ); | ||
| } |
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,104 @@ | ||
| import { | ||
| createContext, | ||
| useContext, | ||
| useEffect, | ||
| useState, | ||
| useCallback, | ||
| type ReactNode, | ||
| } from "react"; | ||
|
|
||
| export type ThemeMode = "light" | "dark" | "system"; | ||
| export type ResolvedTheme = "light" | "dark"; | ||
|
|
||
| const STORAGE_KEY = "copaw-theme"; | ||
|
|
||
| interface ThemeContextValue { | ||
| /** User selected preference: light / dark / system */ | ||
| themeMode: ThemeMode; | ||
| /** Resolved final theme after applying system preference */ | ||
| isDark: boolean; | ||
| setThemeMode: (mode: ThemeMode) => void; | ||
| /** Convenience toggle: light ↔ dark (skips system) */ | ||
| toggleTheme: () => void; | ||
| } | ||
|
|
||
| const ThemeContext = createContext<ThemeContextValue>({ | ||
| themeMode: "light", | ||
| isDark: false, | ||
| setThemeMode: () => {}, | ||
| toggleTheme: () => {}, | ||
| }); | ||
|
|
||
| function getInitialMode(): ThemeMode { | ||
| try { | ||
| const stored = localStorage.getItem(STORAGE_KEY); | ||
| if (stored === "light" || stored === "dark" || stored === "system") { | ||
| return stored; | ||
| } | ||
| } catch { | ||
| // ignore storage errors | ||
| } | ||
| return "system"; | ||
| } | ||
|
|
||
| function resolveIsDark(mode: ThemeMode): boolean { | ||
| if (mode === "dark") return true; | ||
| if (mode === "light") return false; | ||
| // system | ||
| return window.matchMedia?.("(prefers-color-scheme: dark)").matches ?? false; | ||
| } | ||
|
|
||
| export function ThemeProvider({ children }: { children: ReactNode }) { | ||
| const [themeMode, setThemeModeState] = useState<ThemeMode>(getInitialMode); | ||
| const [isDark, setIsDark] = useState<boolean>(() => | ||
| resolveIsDark(getInitialMode()), | ||
| ); | ||
zhaozhuang521 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Apply dark/light class to <html> element for global CSS variable overrides | ||
| useEffect(() => { | ||
| const html = document.documentElement; | ||
| if (isDark) { | ||
| html.classList.add("dark-mode"); | ||
| } else { | ||
| html.classList.remove("dark-mode"); | ||
| } | ||
| }, [isDark]); | ||
|
|
||
| // Listen to system theme changes when mode is "system" | ||
| useEffect(() => { | ||
| if (themeMode !== "system") return; | ||
|
|
||
| const mq = window.matchMedia("(prefers-color-scheme: dark)"); | ||
| const handler = (e: MediaQueryListEvent) => { | ||
| setIsDark(e.matches); | ||
| }; | ||
| mq.addEventListener("change", handler); | ||
| return () => mq.removeEventListener("change", handler); | ||
| }, [themeMode]); | ||
|
|
||
| const setThemeMode = useCallback((mode: ThemeMode) => { | ||
| setThemeModeState(mode); | ||
| setIsDark(resolveIsDark(mode)); | ||
| try { | ||
| localStorage.setItem(STORAGE_KEY, mode); | ||
| } catch { | ||
| // ignore | ||
| } | ||
| }, []); | ||
|
|
||
| const toggleTheme = useCallback(() => { | ||
| setThemeMode(isDark ? "light" : "dark"); | ||
| }, [isDark, setThemeMode]); | ||
|
|
||
| return ( | ||
| <ThemeContext.Provider | ||
| value={{ themeMode, isDark, setThemeMode, toggleTheme }} | ||
| > | ||
| {children} | ||
| </ThemeContext.Provider> | ||
| ); | ||
| } | ||
|
|
||
| export function useTheme(): ThemeContextValue { | ||
| return useContext(ThemeContext); | ||
| } | ||
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
Oops, something went wrong.
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.