-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradioAvatar.js
70 lines (64 loc) · 1.51 KB
/
radioAvatar.js
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
62
63
64
65
66
67
68
69
70
/* eslint-disable no-sparse-arrays */
/* eslint-disable react/destructuring-assignment */
import {
useRadio,
Box,
useRadioGroup,
HStack,
Img,
} from '@chakra-ui/react';
import { avatarURLs } from './review';
function RadioCard(props) {
const { getInputProps, getCheckboxProps } = useRadio(props);
const input = getInputProps();
const checkbox = getCheckboxProps();
return (
<Box as='label' p={0}>
<input name='avatar' {...input} />
<Box
{...checkbox}
cursor='pointer'
borderRadius='100%'
_checked={{
bg: 'gt.400',
color: 'white',
borderColor: 'gt.400',
borderWidth: '2px',
}}
_focus={{
// boxShadow: 'outline',
}}
mb={2}
p={0}
>
{props.children}
</Box>
</Box>
);
}
export default function RadioAvatar({ onChange, value }) {
const { getRootProps, getRadioProps } = useRadioGroup({
name: 'avatar',
onChange,
value,
});
const group = getRootProps();
return (
<HStack {...group} wrap={['wrap',, 'nowrap']}>
{Object.keys(avatarURLs).map((value) => {
const radio = getRadioProps({ value });
return (
<RadioCard key={value} {...radio}>
<Img
borderRadius='full'
src={avatarURLs[value]}
alt='Avatar'
objectFit='contain'
w={['50px', '60px', 'auto']}
/>
</RadioCard>
);
})}
</HStack>
);
}