@@ -9,6 +9,8 @@ interface ServerTargetProps {
9
9
* make sure you pass same targetId to corresponding `ThemeSwitcher`, `ColorSwitch` and `useTheme` hook as well.
10
10
* @defaultValue undefined*/
11
11
targetId ?: string ;
12
+ /** provide styles object if you are using CSS/SCSS modules. */
13
+ styles ?: Record < string , string > ;
12
14
}
13
15
14
16
/**
@@ -24,12 +26,20 @@ interface ServerTargetProps {
24
26
* </html>
25
27
* ```
26
28
*/
27
- export function ServerTarget ( { tag, targetId } : ServerTargetProps ) {
29
+ export function ServerTarget ( { tag, targetId, styles } : ServerTargetProps ) {
28
30
const key = targetId || DEFAULT_ID ;
29
31
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" : "" ;
31
35
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 } ` ;
33
43
34
44
const Tag = tag ?? "div" ;
35
45
return < Tag className = { cls } data-nth = "next" data-testid = "server-target" id = { key } /> ;
0 commit comments