Skip to content

Commit 63e9921

Browse files
authored
FE: Topics: Fix "Show internal topics" switch (#446)
1 parent 1196f9f commit 63e9921

File tree

2 files changed

+11
-43
lines changed

2 files changed

+11
-43
lines changed
Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import styled from 'styled-components';
22

33
interface 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
`;

frontend/src/components/common/Switch/Switch.tsx

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,17 @@ export interface SwitchProps {
66
onChange(): void;
77
checked: boolean;
88
name: string;
9-
checkedIcon?: React.ReactNode;
10-
unCheckedIcon?: React.ReactNode;
11-
bgCustomColor?: string;
129
}
13-
const Switch: React.FC<SwitchProps> = ({
14-
name,
15-
checked,
16-
onChange,
17-
checkedIcon,
18-
unCheckedIcon,
19-
}) => {
20-
const isCheckedIcon = !!(checkedIcon || unCheckedIcon);
10+
const Switch: React.FC<SwitchProps> = ({ name, checked, onChange }) => {
2111
return (
22-
<S.StyledLabel isCheckedIcon={isCheckedIcon}>
12+
<S.StyledLabel>
2313
<S.StyledInput
2414
name={name}
2515
type="checkbox"
2616
onChange={onChange}
2717
checked={checked}
28-
isCheckedIcon={isCheckedIcon}
2918
/>
30-
<S.StyledSlider isCheckedIcon={isCheckedIcon} />
31-
{checkedIcon && <S.CheckedIcon>{checkedIcon}</S.CheckedIcon>}
32-
{unCheckedIcon && <S.UnCheckedIcon>{unCheckedIcon}</S.UnCheckedIcon>}
19+
<S.StyledSlider checked={checked} />
3320
</S.StyledLabel>
3421
);
3522
};

0 commit comments

Comments
 (0)