Skip to content

Commit 2434174

Browse files
committed
1. add support for CSS modules
2. Add nth-scoped class to increase specificity for scoped containers.
1 parent 6023a47 commit 2434174

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ interface ServerTargetProps {
99
* make sure you pass same targetId to corresponding `ThemeSwitcher`, `ColorSwitch` and `useTheme` hook as well.
1010
* @defaultValue undefined*/
1111
targetId?: string;
12+
/** provide styles object if you are using CSS/SCSS modules. */
13+
styles?: Record<string, string>;
1214
}
1315

1416
/**
@@ -24,12 +26,20 @@ interface ServerTargetProps {
2426
* </html>
2527
* ```
2628
*/
27-
export function ServerTarget({ tag, targetId }: ServerTargetProps) {
29+
export function ServerTarget({ tag, targetId, styles }: ServerTargetProps) {
2830
const key = targetId || DEFAULT_ID;
2931
const val = cookies().get(key)?.value ?? ",light";
30-
const [theme, cs] = val.split(",") as [string, "dark" | "light"];
32+
let [theme, cs] = val.split(",") as [string, string];
33+
/** to increase specificity for scoped targets. */
34+
let specificity = targetId ? "nth-scoped" : "";
3135

32-
const cls = `th-${theme} ${cs}`;
36+
if (styles) {
37+
theme = styles[theme];
38+
cs = styles[cs];
39+
specificity = styles[specificity];
40+
}
41+
42+
const cls = `th-${theme} ${cs} ${specificity}`;
3343

3444
const Tag = tag ?? "div";
3545
return <Tag className={cls} data-nth="next" data-testid="server-target" id={key} />;

0 commit comments

Comments
 (0)