Skip to content

Commit 15b9295

Browse files
author
Marcella Malune
committed
start Checkbox migration
1 parent 35e6f4c commit 15b9295

File tree

1 file changed

+44
-58
lines changed

1 file changed

+44
-58
lines changed

src/components/Checkbox.tsx

Lines changed: 44 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,32 @@
11
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"
39

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+
}
2015

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
4317

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
5219

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
5628

29+
// Props
5730
export interface IProps {
5831
children?: React.ReactNode
5932
callback?: () => void
@@ -62,6 +35,7 @@ export interface IProps {
6235
size?: number
6336
}
6437

38+
// Checkbox
6539
const Checkbox: React.FC<IProps> = ({
6640
callback,
6741
checked,
@@ -70,26 +44,38 @@ const Checkbox: React.FC<IProps> = ({
7044
size = 2,
7145
...rest
7246
}) => {
47+
console.log({
48+
checkboxProps: {
49+
callback,
50+
checked,
51+
children,
52+
className,
53+
size,
54+
...rest,
55+
},
56+
})
57+
7358
const handleClick = () => {
7459
if (callback) {
7560
callback()
7661
}
7762
}
63+
7864
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
8268
aria-hidden="true"
8369
checked={checked}
8470
className="styled-checkbox"
8571
size={size}
8672
>
87-
<Icon checked={checked} viewBox="0 0 24 24">
73+
<svg checked={checked} viewBox="0 0 24 24" {...svgProps}>
8874
<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>
9379
)
9480
}
9581

0 commit comments

Comments
 (0)