-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathindex.tsx
46 lines (43 loc) Β· 1.16 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { useId } from 'react';
import {
FormControl,
FormLabel,
HStack,
Switch,
useColorMode,
} from '@chakra-ui/react';
import { useTranslation } from 'react-i18next';
export const DarkModeSwitch = () => {
const { t } = useTranslation(['account']);
const { colorMode, setColorMode } = useColorMode();
const id = useId();
return (
<FormControl display="flex" alignItems="center">
<HStack>
<FormLabel
as={colorMode === 'light' ? 'span' : undefined}
opacity={colorMode !== 'light' ? 0.5 : undefined}
htmlFor={id}
mb="0"
mr={0}
>
{t('account:preferences.theme.light')}
</FormLabel>
<Switch
colorScheme="brand"
id={id}
isChecked={colorMode === 'dark'}
onChange={(e) => setColorMode(e.target.checked ? 'dark' : 'light')}
/>
<FormLabel
as={colorMode === 'dark' ? 'span' : undefined}
opacity={colorMode !== 'dark' ? 0.5 : undefined}
htmlFor={id}
mb="0"
>
{t('account:preferences.theme.dark')}
</FormLabel>
</HStack>
</FormControl>
);
};