From 63e99210af4deb26a2b4b5bb75e4d9ad1d443118 Mon Sep 17 00:00:00 2001 From: Renat Kalimulin <103274228+Nilumilak@users.noreply.github.com> Date: Tue, 18 Jun 2024 02:09:58 +0300 Subject: [PATCH] FE: Topics: Fix "Show internal topics" switch (#446) --- .../components/common/Switch/Switch.styled.ts | 35 +++++-------------- .../src/components/common/Switch/Switch.tsx | 19 ++-------- 2 files changed, 11 insertions(+), 43 deletions(-) diff --git a/frontend/src/components/common/Switch/Switch.styled.ts b/frontend/src/components/common/Switch/Switch.styled.ts index 0f4f2c1d11c..780506569a3 100644 --- a/frontend/src/components/common/Switch/Switch.styled.ts +++ b/frontend/src/components/common/Switch/Switch.styled.ts @@ -1,13 +1,13 @@ import styled from 'styled-components'; interface Props { - isCheckedIcon?: boolean; + checked?: boolean; } -export const StyledLabel = styled.label` +export const StyledLabel = styled.label` position: relative; display: inline-block; - width: ${({ isCheckedIcon }) => (isCheckedIcon ? '40px' : '34px')}; + width: 34px; height: 20px; margin-right: 8px; `; @@ -32,14 +32,12 @@ export const StyledSlider = styled.span` left: 0; right: 0; bottom: 0; - background-color: ${({ isCheckedIcon, theme }) => - isCheckedIcon - ? theme.switch.checkedIcon.backgroundColor - : theme.switch.unchecked}; + background-color: ${({ checked, theme }) => + checked ? theme.switch.checked : theme.switch.unchecked}; transition: 0.4s; border-radius: 20px; - :hover { + &:hover { background-color: ${({ theme }) => theme.switch.hover}; } @@ -48,7 +46,7 @@ export const StyledSlider = styled.span` content: ''; height: 14px; width: 14px; - left: 3px; + left: ${({ checked }) => (checked ? '17px' : '3px')}; bottom: 3px; background-color: ${({ theme }) => theme.switch.circle}; transition: 0.4s; @@ -57,25 +55,8 @@ export const StyledSlider = styled.span` } `; -export const StyledInput = styled.input` +export const StyledInput = styled.input` opacity: 0; width: 0; height: 0; - - &:checked + ${StyledSlider} { - background-color: ${({ isCheckedIcon, theme }) => - isCheckedIcon - ? theme.switch.checkedIcon.backgroundColor - : theme.switch.checked}; - } - - &:focus + ${StyledSlider} { - box-shadow: 0 0 1px ${({ theme }) => theme.switch.checked}; - } - - :checked + ${StyledSlider}:before { - transform: translateX( - ${({ isCheckedIcon }) => (isCheckedIcon ? '20px' : '14px')} - ); - } `; diff --git a/frontend/src/components/common/Switch/Switch.tsx b/frontend/src/components/common/Switch/Switch.tsx index e1cb56d7a03..3c6598c27c6 100644 --- a/frontend/src/components/common/Switch/Switch.tsx +++ b/frontend/src/components/common/Switch/Switch.tsx @@ -6,30 +6,17 @@ export interface SwitchProps { onChange(): void; checked: boolean; name: string; - checkedIcon?: React.ReactNode; - unCheckedIcon?: React.ReactNode; - bgCustomColor?: string; } -const Switch: React.FC = ({ - name, - checked, - onChange, - checkedIcon, - unCheckedIcon, -}) => { - const isCheckedIcon = !!(checkedIcon || unCheckedIcon); +const Switch: React.FC = ({ name, checked, onChange }) => { return ( - + - - {checkedIcon && {checkedIcon}} - {unCheckedIcon && {unCheckedIcon}} + ); };