-
Notifications
You must be signed in to change notification settings - Fork 513
/
Checkbox.tsx
89 lines (77 loc) · 2.22 KB
/
Checkbox.tsx
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
83
84
85
86
87
88
89
import React, {FormEvent} from 'react';
import styled, {css} from 'styled-components';
import {CheckIcon} from '../../icons/CheckIcon';
/**
* @TODO use blue20 instead of #dee9f4
* @TODO use blue40 instead of #bdd3e9
* @TODO use blue100 instead of #5992c7
* @TODO use grey60 instead of #f9f9fb
* @TODO use grey100 instead of #a1a9b7
* @TODO use grey140 instead of #11324d
*/
const CheckboxContainer = styled.div < {checked: boolean, readOnly: boolean } > `
background-color: transparent;
height: 20px;
width: 20px;
border: 1px solid #5992c7;
border-radius: 3px;
display: inline-block;
${props =>
props.checked && css`
background-color: #5992c7
`
}
${props =>
props.checked && props.readOnly && css`
background-color: #dee9f4
border-color: #bdd3e9
`
}
${props =>
!props.checked && props.readOnly && css`
background-color: #f9f9fb
border-color: #a1a9b7
`
}
`;
const LabelContainer = styled.div < {readOnly: boolean} > `
font-color: "#11324d";
font-weight: 400;
font-size: 15px;
padding-left: 10px;
display: inline-block;
${props =>
props.readOnly && `
font-color: "#a1a9b7";
`
}
`;
type CheckboxProps = {
checked: boolean,
readOnly: boolean,
label?: string,
onChange?: (value: boolean) => void,
};
/**
* The checkboxes are applied when users can select all, several, or none of the options from a given list.
*/
const Checkbox = ({label, checked, onChange, readOnly = false}: CheckboxProps) => {
const handleChange = (e: FormEvent<HTMLDivElement>) => onChange && !readOnly && onChange(!checked);
console.log(checked);
console.log(readOnly);
return (
<label>
<CheckboxContainer onClick={handleChange} checked={checked} readOnly={readOnly}>
{checked ? (
<CheckIcon height={20} width={20}/>
) : null}
</CheckboxContainer>
{label ? (
<LabelContainer readOnly={readOnly}>
{label}
</LabelContainer>
) : null}
</label>
);
};
export {Checkbox};