rc-plugin/server/components/ThemeToggle.jsx
2024-11-20 11:28:38 +08:00

24 lines
589 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React, { useState } from 'react';
function ThemeToggle() {
// 用于保存主题状态默认为“light”主题
const [isDarkTheme, setIsDarkTheme] = useState(false);
// 切换主题时的处理函数
const handleThemeChange = () => {
setIsDarkTheme(!isDarkTheme);
};
return (
<input
type="checkbox"
checked={isDarkTheme}
onChange={handleThemeChange}
className="toggle theme-controller"
value={isDarkTheme ? 'dark' : 'light'}
/>
);
}
export default ThemeToggle;