Skip to content

Commit 6bc0dfd

Browse files
committed
fix deepsource - anti-pattern
1 parent f94ccfc commit 6bc0dfd

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

lib/nextjs-themes/src/server/nextjs/server-side-wrapper/server-side-wrapper.tsx

+24-24
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,30 @@ export interface NextJsSSRThemeSwitcherProps extends HTMLProps<HTMLElement> {
2020
styles?: Record<string, string>;
2121
}
2222

23+
function getDataProps(resolvedData: UpdateProps, styles?: Record<string, string>) {
24+
const dataProps: DataProps = { className: "" };
25+
let classeNames = [];
26+
if (resolvedData.resolvedColorScheme !== undefined) {
27+
dataProps["data-color-scheme"] = resolvedData.resolvedColorScheme;
28+
classeNames.push(resolvedData.resolvedColorScheme);
29+
}
30+
if (resolvedData.resolvedTheme !== undefined) {
31+
dataProps["data-theme"] = resolvedData.resolvedTheme;
32+
classeNames.push(`theme-${resolvedData.resolvedTheme}`);
33+
}
34+
if (resolvedData.th) {
35+
dataProps["data-th"] = resolvedData.th;
36+
classeNames.push(`th-${resolvedData.th}`);
37+
}
38+
if (resolvedData.resolvedColorSchemePref !== undefined) {
39+
dataProps["data-csp"] = resolvedData.resolvedColorSchemePref;
40+
classeNames.push(`csp-${resolvedData.resolvedColorSchemePref}`);
41+
}
42+
if (styles) classeNames = classeNames.map(cls => styles[cls] ?? cls);
43+
dataProps.className = classeNames.join(" ");
44+
return dataProps;
45+
}
46+
2347
function sharedServerComponentRenderer(
2448
{ children, tag, forcedPages, targetId, styles, ...props }: NextJsSSRThemeSwitcherProps,
2549
defaultTag: "div" | "html",
@@ -48,30 +72,6 @@ function sharedServerComponentRenderer(
4872
);
4973
}
5074

51-
function getDataProps(resolvedData: UpdateProps, styles?: Record<string, string>) {
52-
const dataProps: DataProps = { className: "" };
53-
let classeNames = [];
54-
if (resolvedData.resolvedColorScheme !== undefined) {
55-
dataProps["data-color-scheme"] = resolvedData.resolvedColorScheme;
56-
classeNames.push(resolvedData.resolvedColorScheme);
57-
}
58-
if (resolvedData.resolvedTheme !== undefined) {
59-
dataProps["data-theme"] = resolvedData.resolvedTheme;
60-
classeNames.push(`theme-${resolvedData.resolvedTheme}`);
61-
}
62-
if (resolvedData.th) {
63-
dataProps["data-th"] = resolvedData.th;
64-
classeNames.push(`th-${resolvedData.th}`);
65-
}
66-
if (resolvedData.resolvedColorSchemePref !== undefined) {
67-
dataProps["data-csp"] = resolvedData.resolvedColorSchemePref;
68-
classeNames.push(`csp-${resolvedData.resolvedColorSchemePref}`);
69-
}
70-
if (styles) classeNames = classeNames.map(cls => styles[cls] ?? cls);
71-
dataProps.className = classeNames.join(" ");
72-
return dataProps;
73-
}
74-
7575
/**
7676
* @example
7777
* ```tsx

0 commit comments

Comments
 (0)