Skip to content

Commit a077ba8

Browse files
committed
fix(playground): gate Tailwind dark: variant on the theme class
appkit-ui's globals.css already defines dark-theme tokens via two paths — an explicit `.dark` class on <html>, and `@media (prefers-color-scheme: dark)` guarded by `:root:not(.light)` so an explicit `.light` class wins. Tailwind v4's default `dark:` variant, however, is purely media driven. That mismatch shows up when the user forces light via the playground's theme selector while their OS is in dark mode: the bootstrap script sets `<html class="light">`, --card/--background correctly resolve to light, but every `dark:*` utility keeps firing under the media query — cards end up painted with dark-mode backgrounds layered under light-mode chrome. Declare a playground-local `@custom-variant dark` that mirrors the token logic exactly: fire when the element is (or descends from) `.dark`, or when `prefers-color-scheme: dark` matches and no `.light` ancestor is present. This rebinds every `dark:*` utility to respect the theme selector's forced choice, keeping the rest of appkit-ui's consumers — which don't ship the bootstrap script — on the existing media-only behaviour.
1 parent 37fa683 commit a077ba8

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,40 @@
11
@import "@databricks/appkit-ui/styles.css";
2+
3+
/**
4+
* Realign Tailwind v4's `dark:` variant with appkit-ui's theme tokens.
5+
*
6+
* `packages/appkit-ui/.../globals.css` defines two paths into dark theme:
7+
* - An explicit `.dark` class on <html> (wins unconditionally).
8+
* - `@media (prefers-color-scheme: dark)` on `:root:not(.light)` — i.e.
9+
* the media query is ignored when the user has explicitly opted into
10+
* light via the `.light` class.
11+
*
12+
* Tailwind v4's default `dark:` variant, however, is purely media-query
13+
* driven. That mismatch produces a split-personality theme in exactly one
14+
* scenario, which is the one we hit: OS set to dark, user forces light
15+
* via the theme selector (bootstrap script in index.html sets
16+
* `<html class="light">`). `--card`, `--background`, etc. correctly
17+
* resolve to light, but every `dark:*` utility keeps firing under the
18+
* media query — cards end up with dark-mode backgrounds layered under
19+
* light-mode text and chrome.
20+
*
21+
* This `@custom-variant dark` rebinds the variant to mirror the token
22+
* logic exactly:
23+
* - Element is (or descends from) `.dark` → dark utilities fire.
24+
* - `prefers-color-scheme: dark` AND no `.light` ancestor → also fire.
25+
* - Everything else → no-op.
26+
*
27+
* Scoped to the playground because the bootstrap script in index.html is
28+
* what makes the `.light` / `.dark` classes meaningful here; other
29+
* appkit-ui consumers may rely on the current media-only behaviour.
30+
*/
31+
@custom-variant dark {
32+
&:where(.dark, .dark *) {
33+
@slot;
34+
}
35+
@media (prefers-color-scheme: dark) {
36+
&:where(:not(.light):not(.light *)) {
37+
@slot;
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)