1
1
import React from "react"
2
- import {
3
- Checkbox as ChakraCheckbox ,
4
- Icon ,
5
- VisuallyHiddenInput ,
6
- Text ,
7
- VStack ,
8
- } from "@chakra-ui/react"
2
+ import { Box , VisuallyHiddenInput , Text } from "@chakra-ui/react"
9
3
10
- // Checkbox Container
11
- const containerProps = {
12
- display : "inline-block" ,
13
- verticalAlign : "middle" ,
14
- }
15
-
16
- // Hidden input
17
-
18
- // StyledCheckbox
19
-
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
28
-
29
- // Props
30
4
export interface IProps {
31
5
children ?: React . ReactNode
32
6
callback ?: ( ) => void
@@ -35,7 +9,6 @@ export interface IProps {
35
9
size ?: number
36
10
}
37
11
38
- // Checkbox
39
12
const Checkbox : React . FC < IProps > = ( {
40
13
callback,
41
14
checked,
@@ -44,38 +17,69 @@ const Checkbox: React.FC<IProps> = ({
44
17
size = 2 ,
45
18
...rest
46
19
} ) => {
47
- console . log ( {
48
- checkboxProps : {
49
- callback,
50
- checked,
51
- children,
52
- className,
53
- size,
54
- ...rest ,
55
- } ,
56
- } )
57
-
58
20
const handleClick = ( ) => {
59
21
if ( callback ) {
60
22
callback ( )
61
23
}
62
24
}
63
25
26
+ const checkboxContainerAttributes = {
27
+ display : "inline-block" ,
28
+ verticalAlign : "middle" ,
29
+ className : className ,
30
+ onClick : handleClick ,
31
+ }
32
+
33
+ const hiddenCheckboxAttributes = {
34
+ type : "checkbox" ,
35
+ checked : checked ,
36
+ readOnly : true ,
37
+ ...rest ,
38
+ }
39
+
40
+ const styledCheckboxAttributes = {
41
+ "aria-hidden" : true ,
42
+ className : "styled-checkbox" ,
43
+ display : "inline-block" ,
44
+ w : `${ size } rem` ,
45
+ h : `${ size } rem` ,
46
+ minW : `${ size } rem` ,
47
+ bg : `${ checked ? "primary400" : "background" } ` ,
48
+ border : "px" ,
49
+ borderStyle : "solid" ,
50
+ borderColor : "black50" ,
51
+ borderRadius : "3px" ,
52
+ transition : "all 150ms" ,
53
+ _hover : {
54
+ boxShadow : "tableItemBoxShadow" ,
55
+ border : "px" ,
56
+ borderStyle : "solid" ,
57
+ borderColor : "primary600" ,
58
+ transition : "transform 0.1s" ,
59
+ transform : "scale(1.02)" ,
60
+ } ,
61
+ }
62
+
64
63
return (
65
- < VStack className = { className } onClick = { handleClick } { ...containerProps } >
66
- < VisuallyHiddenInput type = "checkbox" checked = { checked } readOnly />
67
- < ChakraCheckbox
68
- aria-hidden = "true"
69
- checked = { checked }
70
- className = "styled-checkbox"
71
- size = { size }
72
- >
73
- < svg checked = { checked } viewBox = "0 0 24 24" { ...svgProps } >
64
+ < Box { ...checkboxContainerAttributes } >
65
+ < VisuallyHiddenInput { ...hiddenCheckboxAttributes } />
66
+ < Box { ...styledCheckboxAttributes } >
67
+ < svg
68
+ viewBox = "0 0 24 24"
69
+ fill = "none"
70
+ stroke = "white"
71
+ strokeWidth = { 0.5 }
72
+ visibility = { `${ checked ? "visible" : "hidden" } ` }
73
+ >
74
74
< polyline points = "20 6 9 17 4 12" />
75
75
</ svg >
76
- </ ChakraCheckbox >
77
- { children && < Text > { children } </ Text > }
78
- </ VStack >
76
+ </ Box >
77
+ { children && (
78
+ < Text as = "span" ml = { 2 } >
79
+ { children }
80
+ </ Text >
81
+ ) }
82
+ </ Box >
79
83
)
80
84
}
81
85
0 commit comments