tianji/src/client/components/ColorSchemeSwitcher.tsx

31 lines
838 B
TypeScript
Raw Normal View History

2023-12-08 13:49:49 +00:00
import React from 'react';
import { LuMoon, LuSun } from 'react-icons/lu';
import { useEvent } from '../hooks/useEvent';
import { Button } from 'antd';
import { useSettingsStore } from '../store/settings';
2023-12-08 13:49:49 +00:00
export const ColorSchemeSwitcher: React.FC = React.memo(() => {
const colorScheme = useSettingsStore((state) => state.colorScheme);
2023-12-08 13:49:49 +00:00
const handleSwitchColorScheme = useEvent(() => {
useSettingsStore.setState({
2023-12-08 13:49:49 +00:00
colorScheme: colorScheme === 'dark' ? 'light' : 'dark',
});
});
return (
<Button
icon={
colorScheme === 'dark' ? (
<LuMoon className="anticon" />
) : (
<LuSun className="anticon" />
)
}
shape="circle"
size="large"
onClick={handleSwitchColorScheme}
/>
);
});
ColorSchemeSwitcher.displayName = 'ColorSchemeSwitcher';