forked from system-ui/theme-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckbox.js
More file actions
82 lines (78 loc) · 1.74 KB
/
Checkbox.js
File metadata and controls
82 lines (78 loc) · 1.74 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
import React from 'react'
import Box from './Box'
import SVG from './SVG'
const CheckboxChecked = props => (
<SVG {...props}>
<path d="M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.11 0 2-.9 2-2V5c0-1.1-.89-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z" />
</SVG>
)
const CheckboxUnchecked = props => (
<SVG {...props}>
<path d="M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z" />
</SVG>
)
const CheckboxIcon = props => (
<React.Fragment>
<CheckboxChecked
{...props}
__css={{
display: 'none',
'input:checked ~ &': {
display: 'block',
},
}}
/>
<CheckboxUnchecked
{...props}
__css={{
display: 'block',
'input:checked ~ &': {
display: 'none',
},
}}
/>
</React.Fragment>
)
export const Checkbox = React.forwardRef(function Checkbox(
{ className, sx, variant = 'checkbox', ...props },
ref
) {
return (
<Box __css={{ label: 'Checkbox' }}>
<Box
ref={ref}
as="input"
type="checkbox"
{...props}
sx={{
position: 'absolute',
opacity: 0,
zIndex: -1,
width: 1,
height: 1,
overflow: 'hidden',
}}
/>
<Box
as={CheckboxIcon}
aria-hidden="true"
__themeKey="forms"
variant={variant}
className={className}
sx={sx}
__css={{
mr: 2,
borderRadius: 4,
color: 'gray',
'input:checked ~ &': {
color: 'primary',
},
'input:focus ~ &': {
color: 'primary',
bg: 'highlight',
},
}}
/>
</Box>
)
})