Skip to content

Commit 633408e

Browse files
committed
fix CSS modules support
1 parent 30b6821 commit 633408e

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

lib/nthul/src/client/theme-switcher/theme-switcher.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,16 @@ export interface ApplyClassesProps {
8787
}
8888

8989
function applyClasses({ targets, theme, resolvedColorScheme, styles }: ApplyClassesProps) {
90-
let cls = ["dark", "light", theme, resolvedColorScheme];
91-
if (styles) cls = cls.map(c => styles[c]);
90+
let cls = ["dark", "light", `th-${theme}`, resolvedColorScheme];
91+
if (styles) cls = cls.map(c => styles[c] ?? c);
9292

9393
targets.forEach(t => {
9494
t?.classList.remove(cls[0]); // dark
9595
t?.classList.remove(cls[1]); // light
9696
t?.classList.forEach(c => {
9797
if (/(?:^|_)th-/.exec(c)) t.classList.remove(c);
9898
});
99-
t?.classList.add(`th-${cls[2]}`); // theme
99+
t?.classList.add(cls[2]); // theme
100100
t?.classList.add(cls[3]); // resolvedColorScheme
101101
});
102102
}

lib/nthul/src/server/server-target/server-target.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,13 @@ interface ServerTargetProps {
2929
export function ServerTarget({ tag, targetId, styles }: ServerTargetProps) {
3030
const key = targetId || DEFAULT_ID;
3131
const val = cookies().get(key)?.value ?? ",light";
32-
let [theme, cs] = val.split(",") as [string, string];
32+
const [theme, cs] = val.split(",") as [string, string];
3333
/** to increase specificity for scoped targets. */
34-
let specificity = targetId ? "nth-scoped" : "";
34+
const specificity = targetId ? "nth-scoped" : "";
3535

36-
if (styles) {
37-
theme = styles[theme];
38-
cs = styles[cs];
39-
specificity = styles[specificity] ?? "";
40-
}
41-
42-
const cls = `th-${theme} ${cs} ${specificity}`;
36+
let classNames = [`th-${theme}`, cs, specificity];
37+
if (styles) classNames = classNames.map(cls => styles[cls] ?? cls);
4338

4439
const Tag = tag ?? "div";
45-
return <Tag className={cls} data-nth="next" data-testid="server-target" id={key} />;
40+
return <Tag className={classNames.join(" ")} data-nth="next" data-testid="server-target" id={key} />;
4641
}

0 commit comments

Comments
 (0)