fix(theme): reactive ThemeToggle component with visible label
Previous topbar theme button used useApp.getState() inline in JSX which doesn't subscribe — clicking changed state but the icon never re-rendered. Replace with proper component that subscribes via hook. Also add visible 'DARK'/'LIGHT' label so the button is discoverable without hover-tooltip-only labelling. Confidence: high Scope-risk: trivial
This commit is contained in:
+19
-3
@@ -133,9 +133,8 @@ export default function App() {
|
|||||||
<Layers size={12} /> Console
|
<Layers size={12} /> Console
|
||||||
{apiLogCount > 0 && <span className="badge mono">{apiLogCount}</span>}
|
{apiLogCount > 0 && <span className="badge mono">{apiLogCount}</span>}
|
||||||
</button>
|
</button>
|
||||||
<button className="link-btn" onClick={() => useApp.getState().setTheme(useApp.getState().theme === "dark" ? "light" : "dark")} title="Toggle theme">
|
<ThemeToggle />
|
||||||
{useApp.getState().theme === "dark" ? <Sun size={13} /> : <Moon size={13} />}
|
|
||||||
</button>
|
|
||||||
<button className="link-btn" onClick={() => setCmdOpen(true)}>
|
<button className="link-btn" onClick={() => setCmdOpen(true)}>
|
||||||
<Cmd size={13} /> <kbd>⌘K</kbd>
|
<Cmd size={13} /> <kbd>⌘K</kbd>
|
||||||
</button>
|
</button>
|
||||||
@@ -159,3 +158,20 @@ export default function App() {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ThemeToggle() {
|
||||||
|
const theme = useApp((s) => s.theme);
|
||||||
|
const setTheme = useApp((s) => s.setTheme);
|
||||||
|
const isDark = theme === "dark";
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
className="link-btn theme-toggle"
|
||||||
|
onClick={() => setTheme(isDark ? "light" : "dark")}
|
||||||
|
title={isDark ? "Switch to light theme" : "Switch to dark theme"}
|
||||||
|
aria-label={isDark ? "Switch to light theme" : "Switch to dark theme"}
|
||||||
|
>
|
||||||
|
{isDark ? <Sun size={13} /> : <Moon size={13} />}
|
||||||
|
<span className="theme-toggle-label">{isDark ? "LIGHT" : "DARK"}</span>
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1787,3 +1787,6 @@ select.studio-input { background: var(--bp-paper); }
|
|||||||
gap: var(--space-md);
|
gap: var(--space-md);
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.theme-toggle { display: inline-flex; align-items: center; gap: 6px; }
|
||||||
|
.theme-toggle-label { font-size: 10px; letter-spacing: 0.08em; font-weight: 600; text-transform: uppercase; }
|
||||||
|
|||||||
Reference in New Issue
Block a user