diff --git a/src/components/PositionList/index.tsx b/src/components/PositionList/index.tsx index 697b5ba1d2..62a023bc40 100644 --- a/src/components/PositionList/index.tsx +++ b/src/components/PositionList/index.tsx @@ -1,6 +1,6 @@ import { Trans } from '@lingui/macro' import PositionListItem from 'components/PositionListItem' -import SimpleToggle from 'components/Toggle/SimpleToggle' +import Toggle from 'components/Toggle' import React from 'react' import styled from 'styled-components/macro' import { MEDIA_WIDTHS } from 'theme' @@ -83,7 +83,7 @@ export default function PositionList({ Show closed positions - { @@ -99,7 +99,7 @@ export default function PositionList({ Show closed positions - { diff --git a/src/components/SearchModal/ManageLists.tsx b/src/components/SearchModal/ManageLists.tsx index 0ae9adf1da..8d808e0506 100644 --- a/src/components/SearchModal/ManageLists.tsx +++ b/src/components/SearchModal/ManageLists.tsx @@ -26,7 +26,7 @@ import { ButtonEmpty, ButtonPrimary } from '../Button' import Column, { AutoColumn } from '../Column' import ListLogo from '../ListLogo' import Row, { RowBetween, RowFixed } from '../Row' -import ListToggle from '../Toggle/ListToggle' +import Toggle from '../Toggle' import { CurrencyModalView } from './CurrencySearchModal' import { PaddedColumn, SearchInput, Separator, SeparatorDark } from './styleds' @@ -215,7 +215,7 @@ const ListRow = memo(function ListRow({ listUrl }: { listUrl: string }) { - { diff --git a/src/components/Toggle/ListToggle.tsx b/src/components/Toggle/ListToggle.tsx deleted file mode 100644 index 8816a02d0e..0000000000 --- a/src/components/Toggle/ListToggle.tsx +++ /dev/null @@ -1,57 +0,0 @@ -import { Trans } from '@lingui/macro' -import styled from 'styled-components/macro' - -import { ThemedText } from '../../theme' - -const Wrapper = styled.button<{ isActive?: boolean; activeElement?: boolean }>` - border-radius: 20px; - border: none; - background: ${({ theme }) => theme.bg1}; - display: flex; - width: fit-content; - cursor: pointer; - outline: none; - padding: 0.4rem 0.4rem; - align-items: center; -` - -const ToggleElement = styled.span<{ isActive?: boolean; bgColor?: string }>` - border-radius: 50%; - height: 24px; - width: 24px; - background-color: ${({ isActive, bgColor, theme }) => (isActive ? bgColor : theme.bg4)}; - :hover { - opacity: 0.8; - } -` - -const StatusText = styled(ThemedText.Main)<{ isActive?: boolean }>` - margin: 0 10px; - width: 24px; - color: ${({ theme, isActive }) => (isActive ? theme.text1 : theme.text3)}; -` - -interface ToggleProps { - id?: string - isActive: boolean - bgColor: string - toggle: () => void -} - -export default function ListToggle({ id, isActive, bgColor, toggle }: ToggleProps) { - return ( - - {isActive && ( - - ON - - )} - - {!isActive && ( - - OFF - - )} - - ) -} diff --git a/src/components/Toggle/SimpleToggle.tsx b/src/components/Toggle/SimpleToggle.tsx deleted file mode 100644 index 2a6fe12bd0..0000000000 --- a/src/components/Toggle/SimpleToggle.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import { darken } from 'polished' -import styled from 'styled-components/macro' - -const Wrapper = styled.button<{ isActive?: boolean; activeElement?: boolean }>` - border-radius: 20px; - border: none; - background: ${({ theme }) => theme.bg1}; - display: flex; - cursor: pointer; - outline: none; - padding: 0.4rem 0.4rem; - align-items: center; - height: 32px; - width: 56px; - position: relative; -` - -const ToggleElement = styled.span<{ isActive?: boolean; isOnSwitch?: boolean }>` - border-radius: 50%; - height: 24px; - width: 24px; - position: absolute; - background: ${({ theme, isActive, isOnSwitch }) => (isActive ? (isOnSwitch ? theme.primary1 : theme.text3) : 'none')}; - :hover { - user-select: ${({ isOnSwitch }) => (isOnSwitch ? 'none' : 'initial')}; - background: ${({ theme, isActive, isOnSwitch }) => - isActive ? (isOnSwitch ? darken(0.05, theme.primary1) : darken(0.05, theme.bg4)) : 'none'}; - color: ${({ theme, isActive, isOnSwitch }) => (isActive ? (isOnSwitch ? theme.white : theme.white) : theme.text3)}; - } -` - -interface ToggleProps { - id?: string - isActive: boolean - toggle: () => void -} - -export default function SimpleToggle({ id, isActive, toggle }: ToggleProps) { - return ( - - - - - ) -} diff --git a/src/components/Toggle/index.tsx b/src/components/Toggle/index.tsx index 26e23cecb6..3ed7445a36 100644 --- a/src/components/Toggle/index.tsx +++ b/src/components/Toggle/index.tsx @@ -1,57 +1,75 @@ -import { Trans } from '@lingui/macro' import { darken } from 'polished' -import { ReactNode } from 'react' -import styled from 'styled-components/macro' +import styled, { keyframes } from 'styled-components/macro' -const ToggleElement = styled.span<{ isActive?: boolean; isOnSwitch?: boolean }>` - padding: 0.25rem 0.6rem; - border-radius: 9px; - background: ${({ theme, isActive, isOnSwitch }) => (isActive ? (isOnSwitch ? theme.primary1 : theme.bg4) : 'none')}; - color: ${({ theme, isActive }) => (isActive ? theme.white : theme.text2)}; - font-size: 14px; - font-weight: ${({ isOnSwitch }) => (isOnSwitch ? '500' : '400')}; - :hover { - user-select: ${({ isOnSwitch }) => (isOnSwitch ? 'none' : 'initial')}; - background: ${({ theme, isActive, isOnSwitch }) => - isActive ? (isOnSwitch ? darken(0.05, theme.primary1) : darken(0.05, theme.bg4)) : 'none'}; - color: ${({ theme, isActive, isOnSwitch }) => (isActive ? (isOnSwitch ? theme.white : theme.white) : theme.text3)}; +const Wrapper = styled.button<{ isActive?: boolean; activeElement?: boolean }>` + align-items: center; + background: ${({ theme }) => theme.bg1}; + border: none; + border-radius: 20px; + cursor: pointer; + display: flex; + outline: none; + padding: 0.4rem 0.4rem; + width: fit-content; +` + +const turnOnToggle = keyframes` + from { + margin-left: 0em; + margin-right: 2.2em; + } + to { + margin-left: 2.2em; + margin-right: 0em; } ` -const StyledToggle = styled.button<{ isActive?: boolean; activeElement?: boolean }>` - border-radius: 12px; - border: none; - background: ${({ theme }) => theme.bg0}; - display: flex; - width: fit-content; - cursor: pointer; - outline: none; - padding: 2px; +const turnOffToggle = keyframes` + from { + margin-left: 2.2em; + margin-right: 0em; + } + to { + margin-left: 0em; + margin-right: 2.2em; + } +` + +const ToggleElementHoverStyle = (hasBgColor: boolean, theme: any, isActive?: boolean) => + hasBgColor + ? { + opacity: '0.8', + } + : { + background: isActive ? darken(0.05, theme.primary1) : darken(0.05, theme.bg4), + color: isActive ? theme.white : theme.text3, + } + +const ToggleElement = styled.span<{ isActive?: boolean; bgColor?: string }>` + animation: 0.1s ${({ isActive }) => (isActive ? turnOnToggle : turnOffToggle)} ease-in; + background: ${({ theme, bgColor, isActive }) => + isActive ? bgColor ?? theme.primary1 : !!bgColor ? theme.bg4 : theme.text3}; + border-radius: 50%; + height: 24px; + :hover { + ${({ bgColor, theme, isActive }) => ToggleElementHoverStyle(!!bgColor, theme, isActive)} + } + margin-left: ${({ isActive }) => (isActive ? '2.2em' : '0em')}; + margin-right: ${({ isActive }) => (!isActive ? '2.2em' : '0em')}; + width: 24px; ` interface ToggleProps { id?: string + bgColor?: string isActive: boolean toggle: () => void - checked?: ReactNode - unchecked?: ReactNode } -export default function Toggle({ - id, - isActive, - toggle, - checked = On, - unchecked = Off, -}: ToggleProps) { +export default function Toggle({ id, bgColor, isActive, toggle }: ToggleProps) { return ( - - - {checked} - - - {unchecked} - - + + + ) }