diff --git a/packages/docusaurus-theme-classic/src/theme/Toggle/index.tsx b/packages/docusaurus-theme-classic/src/theme/Toggle/index.tsx
index ed449e3cad..59c5d8d881 100644
--- a/packages/docusaurus-theme-classic/src/theme/Toggle/index.tsx
+++ b/packages/docusaurus-theme-classic/src/theme/Toggle/index.tsx
@@ -5,46 +5,27 @@
* LICENSE file in the root directory of this source tree.
*/
-import React, {useState, useRef, memo, CSSProperties} from 'react';
+import React, {useState, useRef, memo} from 'react';
import type {Props} from '@theme/Toggle';
-import {useThemeConfig} from '@docusaurus/theme-common';
+import {useThemeConfig, ColorModeConfig} from '@docusaurus/theme-common';
import useIsBrowser from '@docusaurus/useIsBrowser';
import clsx from 'clsx';
import styles from './styles.module.css';
-interface IconProps {
- icon: string;
- style: CSSProperties;
-}
-
-function Dark({icon, style}: IconProps): JSX.Element {
- return (
-
- {icon}
-
- );
-}
-function Light({icon, style}: IconProps): JSX.Element {
- return (
-
- {icon}
-
- );
-}
-
// Based on react-toggle (https://github.com/aaronshaf/react-toggle/).
-const Toggle = memo(
+const ToggleComponent = memo(
({
className,
- icons,
+ switchConfig,
checked: defaultChecked,
disabled,
onChange,
}: Props & {
- icons: {checked: JSX.Element; unchecked: JSX.Element};
+ switchConfig: ColorModeConfig['switchConfig'];
disabled: boolean;
}): JSX.Element => {
+ const {darkIcon, darkIconStyle, lightIcon, lightIconStyle} = switchConfig;
const [checked, setChecked] = useState(defaultChecked);
const [focused, setFocused] = useState(false);
const inputRef = useRef(null);
@@ -62,8 +43,16 @@ const Toggle = memo(
role="button"
tabIndex={-1}
onClick={() => inputRef.current?.click()}>
- {icons.checked}
- {icons.unchecked}
+
+
+ {darkIcon}
+
+
+
+
+ {lightIcon}
+
+
@@ -88,21 +77,16 @@ const Toggle = memo(
},
);
-export default function (props: Props): JSX.Element {
+export default function Toggle(props: Props): JSX.Element {
const {
- colorMode: {
- switchConfig: {darkIcon, darkIconStyle, lightIcon, lightIconStyle},
- },
+ colorMode: {switchConfig},
} = useThemeConfig();
const isBrowser = useIsBrowser();
return (
- ,
- unchecked: ,
- }}
{...props}
/>
);
diff --git a/packages/docusaurus-theme-classic/src/theme/Toggle/styles.module.css b/packages/docusaurus-theme-classic/src/theme/Toggle/styles.module.css
index c3053a44eb..2cbd0c8cdc 100644
--- a/packages/docusaurus-theme-classic/src/theme/Toggle/styles.module.css
+++ b/packages/docusaurus-theme-classic/src/theme/Toggle/styles.module.css
@@ -103,6 +103,3 @@
justify-content: center;
width: 10px;
}
-.toggle::before {
- position: absolute;
-}
diff --git a/packages/docusaurus-theme-common/src/index.ts b/packages/docusaurus-theme-common/src/index.ts
index a47275476b..c53792b012 100644
--- a/packages/docusaurus-theme-common/src/index.ts
+++ b/packages/docusaurus-theme-common/src/index.ts
@@ -16,6 +16,7 @@ export type {
Footer,
FooterLinks,
FooterLinkItem,
+ ColorModeConfig,
} from './utils/useThemeConfig';
export {createStorageSlot, listStorageKeys} from './utils/storageUtils';