@@ -22,39 +22,63 @@ export enum CheckboxSize {
22
22
type CheckboxProps = {
23
23
checked : boolean ;
24
24
indeterminate ?: boolean ;
25
+ hoverable ?: boolean ;
25
26
onChange ?: ( event : React . ChangeEvent < HTMLInputElement > ) => void ;
26
27
onCheckedChange ?: ( value : boolean ) => void ;
27
28
variant ?: CheckboxVariant ;
28
29
size ?: CheckboxSize ;
29
30
shape ?: CheckboxShape ;
30
31
className ?: string ;
32
+ disabled ?: boolean ;
31
33
} ;
32
34
33
- const StyledInputContainer = styled . div `
34
- align-items: center;
35
- display: flex;
36
- position: relative;
37
- ` ;
38
-
39
35
type InputProps = {
40
36
checkboxSize : CheckboxSize ;
41
37
variant : CheckboxVariant ;
42
38
indeterminate ?: boolean ;
39
+ hoverable ?: boolean ;
43
40
shape ?: CheckboxShape ;
44
41
isChecked ?: boolean ;
42
+ disabled ?: boolean ;
45
43
} ;
46
44
45
+ const StyledInputContainer = styled . div < InputProps > `
46
+ --size: ${ ( { checkboxSize } ) =>
47
+ checkboxSize === CheckboxSize . Large ? '32px' : '24px' } ;
48
+ align-items: center;
49
+ border-radius: ${ ( { theme, shape } ) =>
50
+ shape === CheckboxShape . Rounded
51
+ ? theme . border . radius . rounded
52
+ : theme . border . radius . sm } ;
53
+
54
+ cursor: ${ ( { disabled } ) => ( disabled ? 'not-allowed' : 'pointer' ) } ;
55
+ display: flex;
56
+ padding: ${ ( { checkboxSize } ) =>
57
+ checkboxSize === CheckboxSize . Large ? '6px' : '5px' } ;
58
+ position: relative;
59
+ ${ ( { hoverable, isChecked, theme, indeterminate, disabled } ) => {
60
+ if ( ! hoverable || disabled === true ) return '' ;
61
+ return `&:hover{
62
+ background-color: ${
63
+ indeterminate || isChecked
64
+ ? theme . color . blue10
65
+ : theme . background . transparent . light
66
+ } ;
67
+ }}
68
+ }` ;
69
+ } }
70
+ ` ;
71
+
47
72
const StyledInput = styled . input < InputProps > `
48
- cursor: pointer;
73
+ cursor: ${ ( { disabled } ) => ( disabled ? 'not-allowed' : ' pointer' ) } ;
49
74
margin: 0;
50
75
opacity: 0;
51
76
position: absolute;
52
77
z-index: 10;
53
-
54
78
& + label {
55
79
--size: ${ ( { checkboxSize } ) =>
56
80
checkboxSize === CheckboxSize . Large ? '18px' : '12px' } ;
57
- cursor: pointer;
81
+ cursor: ${ ( { disabled } ) => ( disabled ? 'not-allowed' : ' pointer' ) } ;
58
82
height: calc(var(--size) + 2px);
59
83
padding: 0;
60
84
position: relative;
@@ -66,8 +90,16 @@ const StyledInput = styled.input<InputProps>`
66
90
checkboxSize === CheckboxSize . Large ? '18px' : '12px' } ;
67
91
background: ${ ( { theme, indeterminate, isChecked } ) =>
68
92
indeterminate || isChecked ? theme . color . blue : 'transparent' } ;
69
- border-color: ${ ( { theme, indeterminate, isChecked, variant } ) => {
93
+ border-color: ${ ( {
94
+ theme,
95
+ indeterminate,
96
+ isChecked,
97
+ variant,
98
+ disabled,
99
+ } ) => {
70
100
switch ( true ) {
101
+ case disabled :
102
+ return theme . background . transparent . medium ;
71
103
case indeterminate || isChecked :
72
104
return theme . color . blue ;
73
105
case variant === CheckboxVariant . Primary :
@@ -83,21 +115,21 @@ const StyledInput = styled.input<InputProps>`
83
115
? theme . border . radius . rounded
84
116
: theme . border . radius . sm } ;
85
117
border-style: solid;
86
- border-width: ${ ( { variant } ) =>
87
- variant === CheckboxVariant . Tertiary ? '2px' : '1px' } ;
118
+ border-width: ${ ( { variant, checkboxSize } ) =>
119
+ checkboxSize === CheckboxSize . Large ||
120
+ variant === CheckboxVariant . Tertiary
121
+ ? '1.43px'
122
+ : '1px' } ;
88
123
content: '';
89
- cursor: pointer;
124
+ cursor: ${ ( { disabled } ) => ( disabled ? 'not-allowed' : ' pointer' ) } ;
90
125
display: inline-block;
91
126
height: var(--size);
92
127
width: var(--size);
93
128
}
94
129
95
130
& + label > svg {
96
- --padding: ${ ( { checkboxSize, variant } ) =>
97
- checkboxSize === CheckboxSize . Large ||
98
- variant === CheckboxVariant . Tertiary
99
- ? '2px'
100
- : '1px' } ;
131
+ --padding: ${ ( { checkboxSize } ) =>
132
+ checkboxSize === CheckboxSize . Large ? '2px' : '1px' } ;
101
133
--size: ${ ( { checkboxSize } ) =>
102
134
checkboxSize === CheckboxSize . Large ? '16px' : '12px' } ;
103
135
height: var(--size);
@@ -117,7 +149,9 @@ export const Checkbox = ({
117
149
variant = CheckboxVariant . Primary ,
118
150
size = CheckboxSize . Small ,
119
151
shape = CheckboxShape . Squared ,
152
+ hoverable = false ,
120
153
className,
154
+ disabled = false ,
121
155
} : CheckboxProps ) => {
122
156
const [ isInternalChecked , setIsInternalChecked ] =
123
157
React . useState < boolean > ( false ) ;
@@ -135,7 +169,16 @@ export const Checkbox = ({
135
169
const checkboxId = 'checkbox' + v4 ( ) ;
136
170
137
171
return (
138
- < StyledInputContainer className = { className } >
172
+ < StyledInputContainer
173
+ checkboxSize = { size }
174
+ variant = { variant }
175
+ shape = { shape }
176
+ isChecked = { isInternalChecked }
177
+ hoverable = { hoverable }
178
+ indeterminate = { indeterminate }
179
+ className = { className }
180
+ disabled = { disabled }
181
+ >
139
182
< StyledInput
140
183
autoComplete = "off"
141
184
type = "checkbox"
@@ -149,6 +192,7 @@ export const Checkbox = ({
149
192
shape = { shape }
150
193
isChecked = { isInternalChecked }
151
194
onChange = { handleChange }
195
+ disabled = { disabled }
152
196
/>
153
197
< label htmlFor = { checkboxId } >
154
198
{ indeterminate ? (
0 commit comments