/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import React, { useState, useRef, memo } from 'react';
import { useThemeConfig } from '@docusaurus/theme-common';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import clsx from 'clsx';
import styles from './styles.module.css';
import DarkIcon from "./icon_night.svg"
import LightIcon from "./icon_day.svg"
const Dark = ({ icon, style }) => (
);
const Light = ({ icon, style }) => (
); // Based on react-toggle (https://github.com/aaronshaf/react-toggle/).
const Toggle = memo(
({ className, icons, checked: defaultChecked, disabled, onChange }) => {
const [checked, setChecked] = useState(defaultChecked);
const [focused, setFocused] = useState(false);
const inputRef = useRef(null);
const handleToggle = (e) => {
const checkbox = inputRef.current;
if (!checkbox) {
return;
}
if (e.target !== checkbox) {
e.preventDefault();
checkbox.focus();
checkbox.click();
return;
}
setChecked(checkbox?.checked);
};
return (
{icons.checked}
{icons.unchecked}
setFocused(true)}
onBlur={() => setFocused(false)}
/>
);
},
);
export default function (props) {
const {
colorMode: {
switchConfig: { darkIcon, darkIconStyle, lightIcon, lightIconStyle },
},
} = useThemeConfig();
const { isClient } = useDocusaurusContext();
return (
,
unchecked: ,
}}
{...props}
/>
);
}