Skip to content

Commit

Permalink
fix deepsource - anti-pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
mayank1513 committed Feb 27, 2024
1 parent f94ccfc commit 6bc0dfd
Showing 1 changed file with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,30 @@ export interface NextJsSSRThemeSwitcherProps extends HTMLProps<HTMLElement> {
styles?: Record<string, string>;
}

function getDataProps(resolvedData: UpdateProps, styles?: Record<string, string>) {
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",
Expand Down Expand Up @@ -48,30 +72,6 @@ function sharedServerComponentRenderer(
);
}

function getDataProps(resolvedData: UpdateProps, styles?: Record<string, string>) {
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
Expand Down

0 comments on commit 6bc0dfd

Please sign in to comment.