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';
|
2023-12-08 14:05:34 +00:00
|
|
|
import { useSettingsStore } from '../store/settings';
|
2023-12-08 13:49:49 +00:00
|
|
|
|
|
|
|
export const ColorSchemeSwitcher: React.FC = React.memo(() => {
|
2023-12-08 14:05:34 +00:00
|
|
|
const colorScheme = useSettingsStore((state) => state.colorScheme);
|
2023-12-08 13:49:49 +00:00
|
|
|
const handleSwitchColorScheme = useEvent(() => {
|
2023-12-08 14:05:34 +00:00
|
|
|
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';
|