@@ -2,53 +2,30 @@ import React from 'react';
22import propTypes from 'prop-types' ;
33
44import styled , { css } from 'styled-components' ;
5- import { createDisabledTextStyles , createHatchedBackground } from '../common' ;
5+ import { createHatchedBackground } from '../common' ;
66
7- import { padding , fontSizes } from '../common/system' ;
87import useControlledOrUncontrolled from '../common/hooks/useControlledOrUncontrolled' ;
98import Cutout from '../Cutout/Cutout' ;
109import { StyledListItem } from '../ListItem/ListItem' ;
10+ import {
11+ size ,
12+ StyledInput ,
13+ StyledLabel ,
14+ LabelText
15+ } from '../SwitchBase/SwitchBase' ;
1116
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- ` ;
4217const sharedCheckboxStyles = css `
18+ width : ${ size } px;
19+ height : ${ size } px;
4320 display : flex;
4421 align-items : center;
4522 justify-content : space-around;
4623 margin-right : 0.5rem ;
4724` ;
4825const StyledCheckbox = styled ( Cutout ) `
4926 ${ sharedCheckboxStyles }
50- width: ${ checkboxSize } px;
51- height: ${ checkboxSize } px;
27+ width: ${ size } px;
28+ height: ${ size } px;
5229 background: ${ ( { theme, isDisabled } ) =>
5330 isDisabled ? theme . material : theme . canvas } ;
5431 &:before {
@@ -62,8 +39,8 @@ const StyledFlatCheckbox = styled.div`
6239 background : ${ ( { theme, isDisabled } ) =>
6340 isDisabled ? theme . flatLight : theme . canvas } ;
6441 ${ sharedCheckboxStyles }
65- width: ${ checkboxSize - 4 } px;
66- height: ${ checkboxSize - 4 } px;
42+ width : ${ size - 4 } px;
43+ height : ${ size - 4 } px;
6744 outline : none;
6845 border : 2px solid ${ ( { theme } ) => theme . flatDark } ;
6946 background : ${ ( { theme, isDisabled } ) =>
@@ -77,8 +54,8 @@ const StyledMenuCheckbox = styled.div`
7754 background : ${ ( { theme, isDisabled } ) =>
7855 isDisabled ? theme . flatLight : theme . canvas } ;
7956 ${ sharedCheckboxStyles }
80- width: ${ checkboxSize - 4 } px;
81- height: ${ checkboxSize - 4 } px;
57+ width : ${ size - 4 } px;
58+ height : ${ size - 4 } px;
8259 background : none;
8360 border : none;
8461 outline : none;
@@ -172,10 +149,6 @@ const IndeterminateIcon = styled.span.attrs(() => ({
172149 ` } ;
173150 }
174151` ;
175- const LabelText = styled . span `
176- display: inline-block;
177- line-height: 1;
178- ` ;
179152
180153const CheckboxComponents = {
181154 flat : StyledFlatCheckbox ,
@@ -218,15 +191,6 @@ const Checkbox = React.forwardRef(function Checkbox(props, ref) {
218191 }
219192 return (
220193 < 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 > }
230194 < StyledInput
231195 disabled = { disabled }
232196 onChange = { disabled ? undefined : handleChange }
@@ -239,6 +203,15 @@ const Checkbox = React.forwardRef(function Checkbox(props, ref) {
239203 ref = { ref }
240204 { ...otherProps }
241205 />
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 > }
242215 </ StyledLabel >
243216 ) ;
244217} ) ;
0 commit comments