Commit 31da6cdb authored by Justin Domingue's avatar Justin Domingue Committed by GitHub

fix: new toggle theme (#1782)

* new toggle theme

* moved trans to default

* update radius

* fianlize styles
parent 4079d8a5
import { Trans } from '@lingui/macro' import { Trans } from '@lingui/macro'
import React from 'react' import { darken } from 'polished'
import React, { ReactNode } from 'react'
import styled from 'styled-components/macro' import styled from 'styled-components/macro'
const ToggleElement = styled.span<{ isActive?: boolean; isOnSwitch?: boolean }>` const ToggleElement = styled.span<{ isActive?: boolean; isOnSwitch?: boolean }>`
padding: 0.25rem 0.5rem; padding: 0.25rem 0.6rem;
border-radius: 14px; border-radius: 9px;
background: ${({ theme, isActive, isOnSwitch }) => (isActive ? (isOnSwitch ? theme.primary1 : theme.text4) : 'none')}; background: ${({ theme, isActive, isOnSwitch }) => (isActive ? (isOnSwitch ? theme.primary1 : theme.bg4) : 'none')};
color: ${({ theme, isActive, isOnSwitch }) => (isActive ? (isOnSwitch ? theme.white : theme.text2) : theme.text3)}; color: ${({ theme, isActive }) => (isActive ? theme.white : theme.text2)};
font-size: 1rem;
font-weight: 400;
padding: 0.35rem 0.6rem;
border-radius: 12px;
background: ${({ theme, isActive, isOnSwitch }) => (isActive ? (isOnSwitch ? theme.primary1 : theme.text5) : 'none')};
color: ${({ theme, isActive, isOnSwitch }) => (isActive ? (isOnSwitch ? theme.white : theme.text2) : theme.text2)};
font-size: 1rem; font-size: 1rem;
font-weight: ${({ isOnSwitch }) => (isOnSwitch ? '500' : '400')}; font-weight: ${({ isOnSwitch }) => (isOnSwitch ? '500' : '400')};
:hover { :hover {
user-select: ${({ isOnSwitch }) => (isOnSwitch ? 'none' : 'initial')}; user-select: ${({ isOnSwitch }) => (isOnSwitch ? 'none' : 'initial')};
background: ${({ theme, isActive, isOnSwitch }) => background: ${({ theme, isActive, isOnSwitch }) =>
isActive ? (isOnSwitch ? theme.primary1 : theme.text5) : 'none'}; isActive ? (isOnSwitch ? darken(0.05, theme.primary1) : darken(0.05, theme.bg4)) : 'none'};
color: ${({ theme, isActive, isOnSwitch }) => (isActive ? (isOnSwitch ? theme.white : theme.text3) : theme.text3)}; color: ${({ theme, isActive, isOnSwitch }) => (isActive ? (isOnSwitch ? theme.white : theme.white) : theme.text3)};
} }
` `
const StyledToggle = styled.button<{ isActive?: boolean; activeElement?: boolean }>` const StyledToggle = styled.button<{ isActive?: boolean; activeElement?: boolean }>`
border-radius: 12px; border-radius: 12px;
border: none; border: 2px solid;
background: ${({ theme }) => theme.bg3}; border-color: ${({ theme, isActive }) => (isActive ? theme.primary1 : theme.bg3)};
background: ${({ theme }) => theme.bg1};
display: flex; display: flex;
width: fit-content; width: fit-content;
cursor: pointer; cursor: pointer;
outline: none; outline: none;
padding: 0; padding: 2px;
` `
export interface ToggleProps { export interface ToggleProps {
id?: string id?: string
isActive: boolean isActive: boolean
toggle: () => void toggle: () => void
checked?: ReactNode
unchecked?: ReactNode
} }
export default function Toggle({ id, isActive, toggle }: ToggleProps) { export default function Toggle({
id,
isActive,
toggle,
checked = <Trans>On</Trans>,
unchecked = <Trans>Off</Trans>,
}: ToggleProps) {
return ( return (
<StyledToggle id={id} isActive={isActive} onClick={toggle}> <StyledToggle id={id} isActive={isActive} onClick={toggle}>
<ToggleElement isActive={isActive} isOnSwitch={true}> <ToggleElement isActive={isActive} isOnSwitch={true}>
<Trans>On</Trans> {checked}
</ToggleElement> </ToggleElement>
<ToggleElement isActive={!isActive} isOnSwitch={false}> <ToggleElement isActive={!isActive} isOnSwitch={false}>
<Trans>Off</Trans> {unchecked}
</ToggleElement> </ToggleElement>
</StyledToggle> </StyledToggle>
) )
......
...@@ -204,11 +204,13 @@ export default function Pool() { ...@@ -204,11 +204,13 @@ export default function Pool() {
{closedPositions.length > 0 ? ( {closedPositions.length > 0 ? (
<ShowInactiveToggle> <ShowInactiveToggle>
<TYPE.darkGray> <TYPE.darkGray>
<Trans>Hide closed positions</Trans> <Trans>Closed positions</Trans>
</TYPE.darkGray> </TYPE.darkGray>
<Toggle <Toggle
isActive={userHideClosedPositions} isActive={!userHideClosedPositions}
toggle={() => setUserHideClosedPositions(!userHideClosedPositions)} toggle={() => setUserHideClosedPositions(!userHideClosedPositions)}
checked={<Trans>Show</Trans>}
unchecked={<Trans>Hide</Trans>}
/> />
</ShowInactiveToggle> </ShowInactiveToggle>
) : null} ) : null}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment