-
Notifications
You must be signed in to change notification settings - Fork 3
/
RoundCheckbox.tsx
61 lines (57 loc) · 1.41 KB
/
RoundCheckbox.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { CheckIcon } from '@chakra-ui/icons'
import {
Box,
Flex,
FormLabel,
Input,
useColorModeValue,
} from '@chakra-ui/react'
import React from 'react'
interface Props {
id: string
checked: boolean
onToggle: (checked: boolean) => void
}
export default function RoundCheckbox({ id, checked, onToggle }: Props) {
const borderColor = useColorModeValue('secondary.light', 'secondary.dark')
const bgColor = useColorModeValue('primary.light', 'primary.dark')
const handleChange = () => {
onToggle(!checked)
}
return (
<Flex
justifyContent="center"
alignItems="center"
padding="3"
tabIndex={0}
onKeyPress={handleChange}
>
<Input
type="checkbox"
id={id + '-rounded-checkbox'}
hidden
checked={checked}
onChange={handleChange}
/>
<FormLabel
display="flex"
position="relative"
margin="0"
title={checked ? 'Toggle Completed' : 'Complete Todo'}
htmlFor={id + 'rounded-checkbox'}
rounded="full"
h="6"
w="6"
justifyContent="center"
alignItems="center"
userSelect="none"
cursor="pointer"
bgColor={borderColor}
onClick={handleChange}
>
{!checked && <Box bgColor={bgColor} h="5" w="5" rounded="full" />}
{checked && <CheckIcon color={bgColor} h="4" w="4" />}
</FormLabel>
</Flex>
)
}