From f7e243586816cd40b693de1e9a7ae7e24738e525 Mon Sep 17 00:00:00 2001 From: hunter Date: Fri, 3 Jun 2022 09:53:09 -0500 Subject: [PATCH] fix: Mobile layout: hide closed positions disappears #3344 (#3858) * Add 'hide closed positions' to mobile pool view * Update 'Hide closed positions' mobile font size * add new toggle from design spec * change off toggle button color * Update SimpleToggle.tsx * update wrapping position for toggle, improve component naming --- src/components/PositionList/index.tsx | 59 ++++++++++++++++++++++++-- src/components/Toggle/SimpleToggle.tsx | 45 ++++++++++++++++++++ 2 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 src/components/Toggle/SimpleToggle.tsx diff --git a/src/components/PositionList/index.tsx b/src/components/PositionList/index.tsx index 4cd574ae32..697b5ba1d2 100644 --- a/src/components/PositionList/index.tsx +++ b/src/components/PositionList/index.tsx @@ -1,6 +1,6 @@ import { Trans } from '@lingui/macro' -import { ButtonText } from 'components/Button' import PositionListItem from 'components/PositionListItem' +import SimpleToggle from 'components/Toggle/SimpleToggle' import React from 'react' import styled from 'styled-components/macro' import { MEDIA_WIDTHS } from 'theme' @@ -28,9 +28,37 @@ const MobileHeader = styled.div` font-size: 16px; font-weight: 500; padding: 8px; + display: flex; + justify-content: space-between; + align-items: center; + @media screen and (min-width: ${MEDIA_WIDTHS.upToSmall}px) { display: none; } + + @media screen and (max-width: ${MEDIA_WIDTHS.upToExtraSmall}px) { + display: flex; + flex-direction: column; + align-items: start; + } +` + +const ToggleWrap = styled.div` + display: flex; + flex-direction: row; + align-items: center; +` + +const ToggleLabel = styled.div` + opacity: 0.6; + margin-right: 10px; +` + +const MobileTogglePosition = styled.div` + @media screen and (max-width: ${MEDIA_WIDTHS.upToExtraSmall}px) { + position: absolute; + right: 20px; + } ` type PositionListProps = React.PropsWithChildren<{ @@ -51,12 +79,35 @@ export default function PositionList({ Your positions {positions && ' (' + positions.length + ')'} - setUserHideClosedPositions(!userHideClosedPositions)}> - Hide closed positions - + + + Show closed positions + + { + setUserHideClosedPositions(!userHideClosedPositions) + }} + /> + Your positions + + + Show closed positions + + + { + setUserHideClosedPositions(!userHideClosedPositions) + }} + /> + + {positions.map((p) => { return diff --git a/src/components/Toggle/SimpleToggle.tsx b/src/components/Toggle/SimpleToggle.tsx new file mode 100644 index 0000000000..2a6fe12bd0 --- /dev/null +++ b/src/components/Toggle/SimpleToggle.tsx @@ -0,0 +1,45 @@ +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 ( + + + + + ) +}