Skip to content

Commit 2ba7087

Browse files
committed
server target
1 parent 52a511b commit 2ba7087

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed
Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
import * as React from "react";
2+
import { cookies } from "next/headers";
3+
import { DEFAULT_ID } from "../../constants";
4+
import type { ColorSchemePreference } from "../../hooks/use-theme";
25

36
interface ServerTargetProps {
4-
children?: React.ReactNode;
7+
tag?: keyof JSX.IntrinsicElements;
8+
targetId?: string;
59
}
610

711
/**
812
* # ServerTarget
9-
*
13+
* --todo
14+
* update comments
15+
* create colorswitch
16+
* update examples
1017
*/
11-
export function ServerTarget({ children }: ServerTargetProps) {
12-
return (
13-
<div>
14-
<h1 data-testid="server-target-h1">server-target</h1>
15-
{children}
16-
</div>
17-
);
18+
export function ServerTarget({ tag, targetId }: ServerTargetProps) {
19+
const key = targetId || DEFAULT_ID;
20+
const [theme, csp, scs] = (cookies().get(key)?.value ?? ",system,light").split(",") as [
21+
string,
22+
ColorSchemePreference,
23+
"dark" | "light",
24+
];
25+
26+
const cls = `th-${theme} ${csp === "system" ? scs : csp}`;
27+
28+
const Tag = tag ?? "div";
29+
return <Tag className={cls} data-nth="next" id={targetId ?? DEFAULT_ID} />;
1830
}

0 commit comments

Comments
 (0)