1
1
import React from "react"
2
- import styled from "@emotion/styled"
3
-
4
- const CheckboxContainer = styled . div `
5
- display: inline-block;
6
- vertical-align: middle;
7
- `
8
-
9
- const HiddenCheckbox = styled . input `
10
- border: 0;
11
- clip: rect(0 0 0 0);
12
- height: 1px;
13
- margin: -1px;
14
- overflow: hidden;
15
- padding: 0;
16
- position: absolute;
17
- white-space: nowrap;
18
- width: 1px;
19
- `
20
-
21
- const StyledCheckbox = styled . div < {
22
- size : number
23
- checked : boolean
24
- } > `
25
- display: inline-block;
26
- width: ${ ( props ) => props . size } rem;
27
- height: ${ ( props ) => props . size } rem;
28
- min-width: ${ ( props ) => props . size } rem;
29
- background: ${ ( props ) =>
30
- props . checked
31
- ? props . theme . colors . primary400
32
- : props . theme . colors . background } ;
33
- border: 1px solid ${ ( props ) => props . theme . colors . black50 } ;
34
- border-radius: 3px;
35
- transition: all 150ms;
36
- &:hover {
37
- box-shadow: ${ ( props ) => props . theme . colors . tableItemBoxShadow } ;
38
- border: 1px solid ${ ( props ) => props . theme . colors . primary600 } ;
39
- transition: transform 0.1s;
40
- transform: scale(1.02);
41
- }
42
- `
43
-
44
- const Icon = styled . svg < {
45
- checked : boolean
46
- } > `
47
- fill: none;
48
- stroke: ${ ( props ) => props . theme . colors . white } ;
49
- stroke-width: 2px;
50
- visibility: ${ ( props ) => ( props . checked ? "visible" : "hidden" ) } ;
51
- `
52
-
53
- const Label = styled . span `
54
- margin-left: 0.5rem;
55
- `
2
+ import { Box , VisuallyHiddenInput , Text } from "@chakra-ui/react"
56
3
57
4
export interface IProps {
58
5
children ?: React . ReactNode
@@ -76,20 +23,56 @@ const Checkbox: React.FC<IProps> = ({
76
23
}
77
24
}
78
25
return (
79
- < CheckboxContainer className = { className } onClick = { handleClick } >
80
- < HiddenCheckbox type = "checkbox" checked = { checked } readOnly { ...rest } />
81
- < StyledCheckbox
82
- aria-hidden = "true"
26
+ < Box
27
+ display = "inline-block"
28
+ verticalAlign = "middle"
29
+ className = { className }
30
+ onClick = { handleClick }
31
+ >
32
+ < VisuallyHiddenInput
33
+ type = "checkbox"
83
34
checked = { checked }
35
+ readOnly
36
+ { ...rest }
37
+ />
38
+ < Box
39
+ aria-hidden = { true }
84
40
className = "styled-checkbox"
85
- size = { size }
41
+ display = "inline-block"
42
+ w = { `${ size } rem` }
43
+ h = { `${ size } rem` }
44
+ minW = { `${ size } rem` }
45
+ bg = { `${ checked ? "primary400" : "background" } ` }
46
+ border = "1px"
47
+ borderStyle = "solid"
48
+ borderColor = "black50"
49
+ borderRadius = "3px"
50
+ transition = "all 150ms"
51
+ _hover = { {
52
+ boxShadow : "tableItemBoxShadow" ,
53
+ border : "1px" ,
54
+ borderStyle : "solid" ,
55
+ borderColor : "primary600" ,
56
+ transition : "transform 0.1s" ,
57
+ transform : "scale(1.02)" ,
58
+ } }
86
59
>
87
- < Icon checked = { checked } viewBox = "0 0 24 24" >
60
+ < svg
61
+ viewBox = "0 0 24 24"
62
+ fill = "none"
63
+ stroke = "white"
64
+ strokeWidth = "2px"
65
+ visibility = { `${ checked ? "visible" : "hidden" } ` }
66
+ >
88
67
< polyline points = "20 6 9 17 4 12" />
89
- </ Icon >
90
- </ StyledCheckbox >
91
- { children && < Label > { children } </ Label > }
92
- </ CheckboxContainer >
68
+ </ svg >
69
+ </ Box >
70
+ { children && (
71
+ < Text as = "span" ml = { 2 } >
72
+ { children }
73
+ </ Text >
74
+ ) }
75
+ </ Box >
93
76
)
94
77
}
95
78
0 commit comments