Skip to content

Commit 027566f

Browse files
committed
chore(ladle): drive global chrome theme from the theme switch (menu accent + active item)
1 parent 1da9647 commit 027566f

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

packages/design-system/.ladle/components.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,18 @@ export const Provider: GlobalProvider = ({ children }) => {
2727
read<boolean>('ladle-dark', false)
2828
)
2929

30+
// Mirror the selection onto <body> as well. Ladle injects this Provider inside
31+
// <main>, so the wrapping ThemeProvider below themes only the story; setting
32+
// `data-theme` / `.dark` on <body> extends the DS theme context to the whole
33+
// Ladle app (the component menu + toolbar chrome), so `var(--primary)` resolves
34+
// per-theme globally and head.html can drive Ladle's own accent from it.
3035
React.useEffect(() => {
3136
window.localStorage.setItem('ladle-theme', JSON.stringify(theme))
37+
document.body.setAttribute('data-theme', theme)
3238
}, [theme])
3339
React.useEffect(() => {
3440
window.localStorage.setItem('ladle-dark', JSON.stringify(dark))
41+
document.body.classList.toggle('dark', dark)
3542
}, [dark])
3643

3744
return (

packages/design-system/.ladle/head.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,18 @@
2323
* {
2424
font-family: var(--theme-font-primary);
2525
}
26+
27+
/* Drive Ladle's own chrome accent (active menu item, focus, links) from the
28+
selected DS theme, so the theme switch is visible on the global view (the
29+
component menu), not just inside a story. `data-theme` is mirrored onto
30+
<body> by the Ladle Provider; `--primary` resolves per-theme there
31+
(UZH blue under uzh, near-black under neutral). */
32+
body[data-theme] {
33+
--ladle-color-accent: var(--primary);
34+
}
35+
/* Also tint the active component in the menu (Ladle bolds it via
36+
`.ladle-active a`) so the selected theme is obvious right in the list. */
37+
.ladle-aside .ladle-active a {
38+
color: var(--primary);
39+
}
2640
</style>

0 commit comments

Comments
 (0)