11import styled from 'styled-components' ;
22
33interface Props {
4- isCheckedIcon ?: boolean ;
4+ checked ?: boolean ;
55}
66
7- export const StyledLabel = styled . label < Props > `
7+ export const StyledLabel = styled . label `
88 position: relative;
99 display: inline-block;
10- width: ${ ( { isCheckedIcon } ) => ( isCheckedIcon ? '40px' : ' 34px' ) } ;
10+ width: 34px;
1111 height: 20px;
1212 margin-right: 8px;
1313` ;
@@ -32,14 +32,12 @@ export const StyledSlider = styled.span<Props>`
3232 left: 0;
3333 right: 0;
3434 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 } ;
3937 transition: 0.4s;
4038 border-radius: 20px;
4139
42- :hover {
40+ & :hover {
4341 background-color: ${ ( { theme } ) => theme . switch . hover } ;
4442 }
4543
@@ -48,7 +46,7 @@ export const StyledSlider = styled.span<Props>`
4846 content: '';
4947 height: 14px;
5048 width: 14px;
51- left: 3px;
49+ left: ${ ( { checked } ) => ( checked ? '17px' : ' 3px' ) } ;
5250 bottom: 3px;
5351 background-color: ${ ( { theme } ) => theme . switch . circle } ;
5452 transition: 0.4s;
@@ -57,25 +55,8 @@ export const StyledSlider = styled.span<Props>`
5755 }
5856` ;
5957
60- export const StyledInput = styled . input < Props > `
58+ export const StyledInput = styled . input `
6159 opacity: 0;
6260 width: 0;
6361 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- }
8162` ;
0 commit comments