1
1
import styled from 'styled-components' ;
2
2
3
3
interface Props {
4
- isCheckedIcon ?: boolean ;
4
+ checked ?: boolean ;
5
5
}
6
6
7
- export const StyledLabel = styled . label < Props > `
7
+ export const StyledLabel = styled . label `
8
8
position: relative;
9
9
display: inline-block;
10
- width: ${ ( { isCheckedIcon } ) => ( isCheckedIcon ? '40px' : ' 34px' ) } ;
10
+ width: 34px;
11
11
height: 20px;
12
12
margin-right: 8px;
13
13
` ;
@@ -32,14 +32,12 @@ export const StyledSlider = styled.span<Props>`
32
32
left: 0;
33
33
right: 0;
34
34
bottom: 0;
35
- background-color: ${ ( { isCheckedIcon, theme } ) =>
36
- isCheckedIcon
37
- ? theme . switch . checkedIcon . backgroundColor
38
- : theme . switch . unchecked } ;
35
+ background-color: ${ ( { checked, theme } ) =>
36
+ checked ? theme . switch . checked : theme . switch . unchecked } ;
39
37
transition: 0.4s;
40
38
border-radius: 20px;
41
39
42
- :hover {
40
+ & :hover {
43
41
background-color: ${ ( { theme } ) => theme . switch . hover } ;
44
42
}
45
43
@@ -48,7 +46,7 @@ export const StyledSlider = styled.span<Props>`
48
46
content: '';
49
47
height: 14px;
50
48
width: 14px;
51
- left: 3px;
49
+ left: ${ ( { checked } ) => ( checked ? '17px' : ' 3px' ) } ;
52
50
bottom: 3px;
53
51
background-color: ${ ( { theme } ) => theme . switch . circle } ;
54
52
transition: 0.4s;
@@ -57,25 +55,8 @@ export const StyledSlider = styled.span<Props>`
57
55
}
58
56
` ;
59
57
60
- export const StyledInput = styled . input < Props > `
58
+ export const StyledInput = styled . input `
61
59
opacity: 0;
62
60
width: 0;
63
61
height: 0;
64
-
65
- &:checked + ${ StyledSlider } {
66
- background-color: ${ ( { isCheckedIcon, theme } ) =>
67
- isCheckedIcon
68
- ? theme . switch . checkedIcon . backgroundColor
69
- : theme . switch . checked } ;
70
- }
71
-
72
- &:focus + ${ StyledSlider } {
73
- box-shadow: 0 0 1px ${ ( { theme } ) => theme . switch . checked } ;
74
- }
75
-
76
- :checked + ${ StyledSlider } :before {
77
- transform: translateX(
78
- ${ ( { isCheckedIcon } ) => ( isCheckedIcon ? '20px' : '14px' ) }
79
- );
80
- }
81
62
` ;
0 commit comments