1
1
import React from "react"
2
- import styled from "@emotion/styled"
2
+ import {
3
+ Checkbox as ChakraCheckbox ,
4
+ Icon ,
5
+ VisuallyHiddenInput ,
6
+ Text ,
7
+ VStack ,
8
+ } from "@chakra-ui/react"
3
9
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
- `
10
+ // Checkbox Container
11
+ const containerProps = {
12
+ display : "inline-block" ,
13
+ verticalAlign : "middle" ,
14
+ }
20
15
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
- `
16
+ // Hidden input
43
17
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
- `
18
+ // StyledCheckbox
52
19
53
- const Label = styled . span `
54
- margin-left: 0.5rem;
55
- `
20
+ // Icon
21
+ const svgProps = {
22
+ fill : "none" ,
23
+ stroke : `${ ( props ) => props . theme . colors . white } ` ,
24
+ strokeWidth : "2px" ,
25
+ visibility : `${ ( props ) => ( props . checked ? "visible" : "hidden" ) } ` ,
26
+ }
27
+ // Label
56
28
29
+ // Props
57
30
export interface IProps {
58
31
children ?: React . ReactNode
59
32
callback ?: ( ) => void
@@ -62,6 +35,7 @@ export interface IProps {
62
35
size ?: number
63
36
}
64
37
38
+ // Checkbox
65
39
const Checkbox : React . FC < IProps > = ( {
66
40
callback,
67
41
checked,
@@ -70,26 +44,38 @@ const Checkbox: React.FC<IProps> = ({
70
44
size = 2 ,
71
45
...rest
72
46
} ) => {
47
+ console . log ( {
48
+ checkboxProps : {
49
+ callback,
50
+ checked,
51
+ children,
52
+ className,
53
+ size,
54
+ ...rest ,
55
+ } ,
56
+ } )
57
+
73
58
const handleClick = ( ) => {
74
59
if ( callback ) {
75
60
callback ( )
76
61
}
77
62
}
63
+
78
64
return (
79
- < CheckboxContainer className = { className } onClick = { handleClick } >
80
- < HiddenCheckbox type = "checkbox" checked = { checked } readOnly { ... rest } />
81
- < StyledCheckbox
65
+ < VStack className = { className } onClick = { handleClick } { ... containerProps } >
66
+ < VisuallyHiddenInput type = "checkbox" checked = { checked } readOnly />
67
+ < ChakraCheckbox
82
68
aria-hidden = "true"
83
69
checked = { checked }
84
70
className = "styled-checkbox"
85
71
size = { size }
86
72
>
87
- < Icon checked = { checked } viewBox = "0 0 24 24" >
73
+ < svg checked = { checked } viewBox = "0 0 24 24" { ... svgProps } >
88
74
< polyline points = "20 6 9 17 4 12" />
89
- </ Icon >
90
- </ StyledCheckbox >
91
- { children && < Label > { children } </ Label > }
92
- </ CheckboxContainer >
75
+ </ svg >
76
+ </ ChakraCheckbox >
77
+ { children && < Text > { children } </ Text > }
78
+ </ VStack >
93
79
)
94
80
}
95
81
0 commit comments