From 6bc0dfd6ddc7f1609b1d0afc00958e52c54f9788 Mon Sep 17 00:00:00 2001 From: Mayank Kumar Chaudhari Date: Tue, 27 Feb 2024 20:39:01 +0530 Subject: [PATCH] fix deepsource - anti-pattern --- .../server-side-wrapper.tsx | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/nextjs-themes/src/server/nextjs/server-side-wrapper/server-side-wrapper.tsx b/lib/nextjs-themes/src/server/nextjs/server-side-wrapper/server-side-wrapper.tsx index 06fce3a2..6be0eaf5 100644 --- a/lib/nextjs-themes/src/server/nextjs/server-side-wrapper/server-side-wrapper.tsx +++ b/lib/nextjs-themes/src/server/nextjs/server-side-wrapper/server-side-wrapper.tsx @@ -20,6 +20,30 @@ export interface NextJsSSRThemeSwitcherProps extends HTMLProps { styles?: Record; } +function getDataProps(resolvedData: UpdateProps, styles?: Record) { + const dataProps: DataProps = { className: "" }; + let classeNames = []; + if (resolvedData.resolvedColorScheme !== undefined) { + dataProps["data-color-scheme"] = resolvedData.resolvedColorScheme; + classeNames.push(resolvedData.resolvedColorScheme); + } + if (resolvedData.resolvedTheme !== undefined) { + dataProps["data-theme"] = resolvedData.resolvedTheme; + classeNames.push(`theme-${resolvedData.resolvedTheme}`); + } + if (resolvedData.th) { + dataProps["data-th"] = resolvedData.th; + classeNames.push(`th-${resolvedData.th}`); + } + if (resolvedData.resolvedColorSchemePref !== undefined) { + dataProps["data-csp"] = resolvedData.resolvedColorSchemePref; + classeNames.push(`csp-${resolvedData.resolvedColorSchemePref}`); + } + if (styles) classeNames = classeNames.map(cls => styles[cls] ?? cls); + dataProps.className = classeNames.join(" "); + return dataProps; +} + function sharedServerComponentRenderer( { children, tag, forcedPages, targetId, styles, ...props }: NextJsSSRThemeSwitcherProps, defaultTag: "div" | "html", @@ -48,30 +72,6 @@ function sharedServerComponentRenderer( ); } -function getDataProps(resolvedData: UpdateProps, styles?: Record) { - const dataProps: DataProps = { className: "" }; - let classeNames = []; - if (resolvedData.resolvedColorScheme !== undefined) { - dataProps["data-color-scheme"] = resolvedData.resolvedColorScheme; - classeNames.push(resolvedData.resolvedColorScheme); - } - if (resolvedData.resolvedTheme !== undefined) { - dataProps["data-theme"] = resolvedData.resolvedTheme; - classeNames.push(`theme-${resolvedData.resolvedTheme}`); - } - if (resolvedData.th) { - dataProps["data-th"] = resolvedData.th; - classeNames.push(`th-${resolvedData.th}`); - } - if (resolvedData.resolvedColorSchemePref !== undefined) { - dataProps["data-csp"] = resolvedData.resolvedColorSchemePref; - classeNames.push(`csp-${resolvedData.resolvedColorSchemePref}`); - } - if (styles) classeNames = classeNames.map(cls => styles[cls] ?? cls); - dataProps.className = classeNames.join(" "); - return dataProps; -} - /** * @example * ```tsx