@@ -2,53 +2,30 @@ import React from 'react';
2
2
import propTypes from 'prop-types' ;
3
3
4
4
import styled , { css } from 'styled-components' ;
5
- import { createDisabledTextStyles , createHatchedBackground } from '../common' ;
5
+ import { createHatchedBackground } from '../common' ;
6
6
7
- import { padding , fontSizes } from '../common/system' ;
8
7
import useControlledOrUncontrolled from '../common/hooks/useControlledOrUncontrolled' ;
9
8
import Cutout from '../Cutout/Cutout' ;
10
9
import { StyledListItem } from '../ListItem/ListItem' ;
10
+ import {
11
+ size ,
12
+ StyledInput ,
13
+ StyledLabel ,
14
+ LabelText
15
+ } from '../SwitchBase/SwitchBase' ;
11
16
12
- const checkboxSize = 20 ;
13
-
14
- const StyledLabel = styled . label `
15
- display: inline-flex;
16
- align-items: center;
17
- position: relative;
18
- margin: ${ padding . sm } 0;
19
- cursor: pointer;
20
- -webkit-user-select: none;
21
- -moz-user-select: none;
22
- -ms-user-select: none;
23
- user-select: none;
24
- font-size: ${ fontSizes . md } ;
25
- ${ props => props . isDisabled && createDisabledTextStyles ( ) }
26
-
27
- ${ StyledListItem } & {
28
- margin: 0;
29
- height: 100%;
30
- }
31
- ` ;
32
-
33
- const StyledInput = styled . input `
34
- position: absolute;
35
- left: 0;
36
- margin: 0;
37
- width: ${ checkboxSize } px;
38
- height: ${ checkboxSize } px;
39
- opacity: 0;
40
- z-index: -99;
41
- ` ;
42
17
const sharedCheckboxStyles = css `
18
+ width : ${ size } px;
19
+ height : ${ size } px;
43
20
display : flex;
44
21
align-items : center;
45
22
justify-content : space-around;
46
23
margin-right : 0.5rem ;
47
24
` ;
48
25
const StyledCheckbox = styled ( Cutout ) `
49
26
${ sharedCheckboxStyles }
50
- width: ${ checkboxSize } px;
51
- height: ${ checkboxSize } px;
27
+ width: ${ size } px;
28
+ height: ${ size } px;
52
29
background: ${ ( { theme, isDisabled } ) =>
53
30
isDisabled ? theme . material : theme . canvas } ;
54
31
&:before {
@@ -62,8 +39,8 @@ const StyledFlatCheckbox = styled.div`
62
39
background : ${ ( { theme, isDisabled } ) =>
63
40
isDisabled ? theme . flatLight : theme . canvas } ;
64
41
${ sharedCheckboxStyles }
65
- width: ${ checkboxSize - 4 } px;
66
- height: ${ checkboxSize - 4 } px;
42
+ width : ${ size - 4 } px;
43
+ height : ${ size - 4 } px;
67
44
outline : none;
68
45
border : 2px solid ${ ( { theme } ) => theme . flatDark } ;
69
46
background : ${ ( { theme, isDisabled } ) =>
@@ -77,8 +54,8 @@ const StyledMenuCheckbox = styled.div`
77
54
background : ${ ( { theme, isDisabled } ) =>
78
55
isDisabled ? theme . flatLight : theme . canvas } ;
79
56
${ sharedCheckboxStyles }
80
- width: ${ checkboxSize - 4 } px;
81
- height: ${ checkboxSize - 4 } px;
57
+ width : ${ size - 4 } px;
58
+ height : ${ size - 4 } px;
82
59
background : none;
83
60
border : none;
84
61
outline : none;
@@ -172,10 +149,6 @@ const IndeterminateIcon = styled.span.attrs(() => ({
172
149
` } ;
173
150
}
174
151
` ;
175
- const LabelText = styled . span `
176
- display: inline-block;
177
- line-height: 1;
178
- ` ;
179
152
180
153
const CheckboxComponents = {
181
154
flat : StyledFlatCheckbox ,
@@ -218,15 +191,6 @@ const Checkbox = React.forwardRef(function Checkbox(props, ref) {
218
191
}
219
192
return (
220
193
< StyledLabel isDisabled = { disabled } className = { className } style = { style } >
221
- < CheckboxComponent
222
- checked = { state }
223
- indeterminate = { indeterminate }
224
- isDisabled = { disabled }
225
- role = 'presentation'
226
- >
227
- { Icon && < Icon isDisabled = { disabled } variant = { variant } /> }
228
- </ CheckboxComponent >
229
- { label && < LabelText > { label } </ LabelText > }
230
194
< StyledInput
231
195
disabled = { disabled }
232
196
onChange = { disabled ? undefined : handleChange }
@@ -239,6 +203,15 @@ const Checkbox = React.forwardRef(function Checkbox(props, ref) {
239
203
ref = { ref }
240
204
{ ...otherProps }
241
205
/>
206
+ < CheckboxComponent
207
+ checked = { state }
208
+ indeterminate = { indeterminate }
209
+ isDisabled = { disabled }
210
+ role = 'presentation'
211
+ >
212
+ { Icon && < Icon isDisabled = { disabled } variant = { variant } /> }
213
+ </ CheckboxComponent >
214
+ { label && < LabelText > { label } </ LabelText > }
242
215
</ StyledLabel >
243
216
) ;
244
217
} ) ;
0 commit comments