From a5b1445a509b022902e97c0df9b7e8d4e4b5e4b9 Mon Sep 17 00:00:00 2001 From: Mayank Date: Tue, 25 Jun 2024 03:35:08 +0530 Subject: [PATCH 01/17] Update typedoc config --- typedoc.config.js | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/typedoc.config.js b/typedoc.config.js index c027a109..c65db0e2 100644 --- a/typedoc.config.js +++ b/typedoc.config.js @@ -1,20 +1,40 @@ /** @type {import('typedoc').TypeDocOptions} */ module.exports = { tsconfig: "tsconfig.docs.json", - name: "React18 Themes", + name: "Nextjs Themes", entryPoints: ["./lib/src"], - exclude: ["**/*.test.tsx", "**/index.ts", "**/declaration.d.ts"], + exclude: [ + "**/*.test.tsx", + "**/index.ts", + "**/server/**", + "**/constants.ts", + "**/store.ts", + "**/no-fouc.ts", + "**/declaration.d.ts", + ], entryPointStrategy: "Expand", out: "./docs", commentStyle: "all", searchInComments: true, + searchInDocuments: true, + cleanOutputDir: true, + excludePrivate: true, excludeExternals: true, + excludeInternal: true, + projectDocuments: ["guides/*.md"], + hideGenerator: true, + cleanOutputDir: true, + navigationLinks: { + GitHub: "https://github.com/react18-tools/nextjs-themes", + }, + navigation: { + includeFolders: false, + }, plugin: [ "typedoc-plugin-mdn-links", "typedoc-plugin-rename-defaults", "typedoc-plugin-missing-exports", "typedoc-plugin-zod", - "typedoc-plugin-inline-sources", // "typedoc-plugin-extras", ], }; From 865ffd4719392cbc073b6546527ef56d02cd0bb5 Mon Sep 17 00:00:00 2001 From: Mayank Date: Tue, 25 Jun 2024 03:36:01 +0530 Subject: [PATCH 02/17] remove inline source plugin --- lib/src/client/theme-switcher/theme-switcher.tsx | 2 -- package.json | 3 +-- scripts/templates/component.hbs | 2 -- scripts/templates/hook.hbs | 2 -- 4 files changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/src/client/theme-switcher/theme-switcher.tsx b/lib/src/client/theme-switcher/theme-switcher.tsx index 56d98697..1930b4b4 100644 --- a/lib/src/client/theme-switcher/theme-switcher.tsx +++ b/lib/src/client/theme-switcher/theme-switcher.tsx @@ -74,8 +74,6 @@ const modifyTransition = (themeTransition = "none") => { * ```tsx * * ``` - * - * @source - Source code */ export const ThemeSwitcher = ({ forcedTheme, diff --git a/package.json b/package.json index 6b7967fe..09682465 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,6 @@ "turbo": "^2.0.4", "typedoc": "^0.26.2", "typedoc-plugin-extras": "^3.0.0", - "typedoc-plugin-inline-sources": "^1.0.2", "typedoc-plugin-mdn-links": "^3.2.1", "typedoc-plugin-missing-exports": "^3.0.0", "typedoc-plugin-rename-defaults": "^0.7.1", @@ -32,4 +31,4 @@ "node": ">=18" }, "name": "turborepo-template" -} \ No newline at end of file +} diff --git a/scripts/templates/component.hbs b/scripts/templates/component.hbs index d5acbe28..65386918 100644 --- a/scripts/templates/component.hbs +++ b/scripts/templates/component.hbs @@ -12,8 +12,6 @@ export interface {{ pascalCase name }}Props extends HTMLProps { * ```tsx * <{{ pascalCase name }} /> * ``` - * - * @source - Source code */ export const {{ pascalCase name }} = ({ children, ...props }: {{ pascalCase name }}Props) => { const className = [props.className, styles["{{ kebabCase name }}"]].filter(Boolean).join(" "); diff --git a/scripts/templates/hook.hbs b/scripts/templates/hook.hbs index c7b3b954..5c354a0f 100644 --- a/scripts/templates/hook.hbs +++ b/scripts/templates/hook.hbs @@ -12,8 +12,6 @@ export interface {{ pascalCase name }}Options { * ```tsx * const [] = {{ camelCase name }}(options); * ``` - * - * @source - Source code */ export const {{ camelCase name }} = (options?: {{ pascalCase name }}Options) => { From ba7f8df9322ca410963184e842f4cb966be01bee Mon Sep 17 00:00:00 2001 From: Mayank Date: Tue, 25 Jun 2024 03:42:14 +0530 Subject: [PATCH 03/17] remove moduled styles and targetSelector --- lib/src/client/color-switch/color-switch.tsx | 11 ++-------- lib/src/client/theme-switcher/no-fouc.ts | 2 -- .../client/theme-switcher/theme-switcher.tsx | 21 +++++++------------ lib/src/hooks/use-theme.ts | 6 +++--- lib/src/store.ts | 8 +++---- package.json | 2 +- pnpm-lock.yaml | 13 ------------ 7 files changed, 17 insertions(+), 46 deletions(-) diff --git a/lib/src/client/color-switch/color-switch.tsx b/lib/src/client/color-switch/color-switch.tsx index 1d21cd7f..a374cae0 100644 --- a/lib/src/client/color-switch/color-switch.tsx +++ b/lib/src/client/color-switch/color-switch.tsx @@ -7,7 +7,6 @@ export interface ColorSwitchProps extends HTMLProps { size?: number; /** Skip system colorScheme while toggling */ skipSystem?: boolean; - targetSelector?: string; } /** @@ -24,14 +23,8 @@ export interface ColorSwitchProps extends HTMLProps { * * ``` */ -export const ColorSwitch = ({ - size = 25, - skipSystem, - targetSelector, - className, - ...props -}: ColorSwitchProps) => { - const { toggleColorScheme } = useTheme(targetSelector); +export const ColorSwitch = ({ size = 25, skipSystem, className, ...props }: ColorSwitchProps) => { + const { toggleColorScheme } = useTheme(); const cls = [styles["color-switch"], className].join(" "); return ( diff --git a/lib/src/client/theme-switcher/no-fouc.ts b/lib/src/client/theme-switcher/no-fouc.ts index 56f98585..514ade99 100644 --- a/lib/src/client/theme-switcher/no-fouc.ts +++ b/lib/src/client/theme-switcher/no-fouc.ts @@ -28,7 +28,6 @@ declare global { export const noFOUCScript = ( key: string, initialState: ThemeStoreType, - styles?: Record, forcedTheme_?: string, forcedColorScheme_?: ColorSchemeType, ) => { @@ -42,7 +41,6 @@ export const noFOUCScript = ( el.setAttribute(`data-${key}`, values[index]); }); classes[0] = values[0]; - if (styles) classes = classes.map(cls => styles[cls] ?? cls); el.className = classes.join(" "); }; diff --git a/lib/src/client/theme-switcher/theme-switcher.tsx b/lib/src/client/theme-switcher/theme-switcher.tsx index 1930b4b4..f4670eac 100644 --- a/lib/src/client/theme-switcher/theme-switcher.tsx +++ b/lib/src/client/theme-switcher/theme-switcher.tsx @@ -7,10 +7,7 @@ import { DARK, DEFAULT_ID, LIGHT } from "../../constants"; export interface ThemeSwitcherProps { forcedTheme?: string; forcedColorScheme?: ColorSchemeType; - targetSelector?: string; themeTransition?: string; - /** provide styles object imported from CSS/SCSS modules, if you are using CSS/SCSS modules. */ - styles?: Record; /** The nonce value for your Content Security Policy. */ nonce?: string; } @@ -20,8 +17,6 @@ interface ScriptProps { k: string; /** nonce */ n?: string; - /** styles */ - s?: Record; /** forcedTheme */ t?: string; /** forcedColorScheme */ @@ -35,7 +30,7 @@ let updateForcedProps: UpdateForcedPropsFunc; let updateForcedState: UpdateForcedPropsFunc; const Script = memo( - ({ k, n = "", s, t, c }: ScriptProps) => { + ({ k, n = "", t, c }: ScriptProps) => { if (typeof m !== "undefined") [media, updateDOM, resolveTheme, updateForcedProps, updateForcedState] = [m, u, r, f, g]; return ( @@ -43,7 +38,7 @@ const Script = memo( suppressHydrationWarning // skipcq: JS-0440 dangerouslySetInnerHTML={{ - __html: `(${noFOUCScript.toString()})(${JSON.stringify([k, initialState, s, t, c]).slice(1, -1)})`, + __html: `(${noFOUCScript.toString()})(${JSON.stringify([k, initialState, t, c]).slice(1, -1)})`, }} nonce={n} /> @@ -78,18 +73,16 @@ const modifyTransition = (themeTransition = "none") => { export const ThemeSwitcher = ({ forcedTheme, forcedColorScheme, - targetSelector, themeTransition, - styles, nonce, }: ThemeSwitcherProps) => { - const k = targetSelector || `#${DEFAULT_ID}`; + const k = DEFAULT_ID; // handle client side exceptions when script is not run. <- for client side apps like vite or CRA if (typeof window !== "undefined" && !window.m) - noFOUCScript(k, initialState, styles, forcedTheme, forcedColorScheme); + noFOUCScript(k, initialState, forcedTheme, forcedColorScheme); - const [state, setState] = useThemeStore(targetSelector); - const [forced] = useForcedStore(targetSelector); + const [state, setState] = useThemeStore(); + const [forced] = useForcedStore(); useEffect(() => { media.addEventListener("change", () => @@ -117,5 +110,5 @@ export const ThemeSwitcher = ({ updateDOM(resolveTheme(state)); }, [forced]); - return