Commit bc9bb39a authored by Charles Bachmeier's avatar Charles Bachmeier Committed by GitHub

chore: Migrate List PriceInput from vanilla-extract to styled-components (#5792)

* wrapper

* wrap currency type

* global price icon

* style warning message

* rename style

* style warning message

* style input border

* remove useMemo

* simplify boolean
Co-authored-by: default avatarCharles Bachmeier <charlie@genie.xyz>
parent 0cc68796
import { Trans } from '@lingui/macro' import { Trans } from '@lingui/macro'
import { Box } from 'nft/components/Box' import Column from 'components/Column'
import { Column, Row } from 'nft/components/Flex' import Row from 'components/Row'
import { AttachPriceIcon, EditPriceIcon } from 'nft/components/icons' import { AttachPriceIcon, EditPriceIcon } from 'nft/components/icons'
import { NumericInput } from 'nft/components/layout/Input' import { NumericInput } from 'nft/components/layout/Input'
import { badge, body } from 'nft/css/common.css' import { body } from 'nft/css/common.css'
import { useSellAsset } from 'nft/hooks' import { useSellAsset } from 'nft/hooks'
import { ListingWarning, WalletAsset } from 'nft/types' import { ListingWarning, WalletAsset } from 'nft/types'
import { formatEth } from 'nft/utils/currency' import { formatEth } from 'nft/utils/currency'
import { Dispatch, FormEvent, useEffect, useRef, useState } from 'react' import { Dispatch, FormEvent, useEffect, useRef, useState } from 'react'
import styled, { useTheme } from 'styled-components/macro'
import { BREAKPOINTS } from 'theme'
import { colors } from 'theme/colors'
const PriceTextInputWrapper = styled(Column)`
gap: 12px;
position: relative;
`
const InputWrapper = styled(Row)<{ borderColor: string }>`
height: 44px;
color: ${({ theme }) => theme.textTertiary};
padding: 4px;
border: 2px solid;
border-radius: 8px;
border-color: ${({ borderColor }) => borderColor};
margin-right: auto;
box-sizing: border-box;
`
const CurrencyWrapper = styled.div<{ listPrice: number | undefined }>`
margin-right: 16px;
color: ${({ listPrice, theme }) => (listPrice ? theme.textPrimary : theme.textSecondary)};
`
const GlobalPriceIcon = styled.div`
display: block;
cursor: pointer;
position: absolute;
top: -6px;
right: -4px;
background-color: ${({ theme }) => theme.backgroundSurface};
`
const WarningMessage = styled(Row)<{ warningType: WarningType }>`
top: 52px;
width: max-content;
position: absolute;
right: 0;
font-weight: 600;
font-size: 10px;
line-height: 12px;
color: ${({ warningType, theme }) => (warningType === WarningType.BELOW_FLOOR ? colors.red400 : theme.textSecondary)};
@media screen and (min-width: ${BREAKPOINTS.md}px) {
right: unset;
}
`
const WarningAction = styled.div<{ warningType: WarningType }>`
margin-left: 8px;
cursor: pointer;
color: ${({ warningType, theme }) => (warningType === WarningType.BELOW_FLOOR ? theme.accentAction : colors.red400)};
`
enum WarningType { enum WarningType {
BELOW_FLOOR, BELOW_FLOOR,
...@@ -54,6 +108,7 @@ export const PriceTextInput = ({ ...@@ -54,6 +108,7 @@ export const PriceTextInput = ({
const removeMarketplaceWarning = useSellAsset((state) => state.removeMarketplaceWarning) const removeMarketplaceWarning = useSellAsset((state) => state.removeMarketplaceWarning)
const removeSellAsset = useSellAsset((state) => state.removeSellAsset) const removeSellAsset = useSellAsset((state) => state.removeSellAsset)
const inputRef = useRef() as React.MutableRefObject<HTMLInputElement> const inputRef = useRef() as React.MutableRefObject<HTMLInputElement>
const theme = useTheme()
useEffect(() => { useEffect(() => {
inputRef.current.value = listPrice !== undefined ? `${listPrice}` : '' inputRef.current.value = listPrice !== undefined ? `${listPrice}` : ''
...@@ -66,27 +121,18 @@ export const PriceTextInput = ({ ...@@ -66,27 +121,18 @@ export const PriceTextInput = ({
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [listPrice]) }, [listPrice])
const borderColor =
warningType !== WarningType.NONE && !focused
? colors.red400
: isGlobalPrice
? theme.accentAction
: listPrice != null
? theme.textSecondary
: theme.accentAction
return ( return (
<Column gap="12" position="relative"> <PriceTextInputWrapper>
<Row <InputWrapper borderColor={borderColor}>
color="textTertiary"
height="44"
width="min"
padding="4"
borderRadius="8"
borderWidth="2px"
borderStyle="solid"
marginRight="auto"
borderColor={
warningType !== WarningType.NONE && !focused
? 'orange'
: isGlobalPrice
? 'accentAction'
: listPrice != null
? 'textSecondary'
: 'blue400'
}
>
<NumericInput <NumericInput
as="input" as="input"
pattern="[0-9]" pattern="[0-9]"
...@@ -111,28 +157,14 @@ export const PriceTextInput = ({ ...@@ -111,28 +157,14 @@ export const PriceTextInput = ({
setListPrice(isNaN(val) ? undefined : val) setListPrice(isNaN(val) ? undefined : val)
}} }}
/> />
<Box color={listPrice && listPrice >= 0 ? 'textPrimary' : 'textSecondary'} marginRight="16"> <CurrencyWrapper listPrice={listPrice}>&nbsp;ETH</CurrencyWrapper>
&nbsp;ETH {(isGlobalPrice || globalOverride) && (
</Box> <GlobalPriceIcon onClick={() => setGlobalOverride(!globalOverride)}>
<Box {globalOverride ? <AttachPriceIcon /> : <EditPriceIcon />}
cursor="pointer" </GlobalPriceIcon>
display={isGlobalPrice || globalOverride ? 'block' : 'none'} )}
position="absolute" </InputWrapper>
style={{ marginTop: '-36px', marginLeft: '124px' }} <WarningMessage warningType={warningType}>
backgroundColor="backgroundSurface"
onClick={() => setGlobalOverride(!globalOverride)}
>
{globalOverride ? <AttachPriceIcon /> : <EditPriceIcon />}
</Box>
</Row>
<Row
top="52"
width="max"
className={badge}
color={warningType === WarningType.BELOW_FLOOR && !focused ? 'orange' : 'textSecondary'}
position="absolute"
right={{ sm: '0', md: 'unset' }}
>
{warning {warning
? warning.message ? warning.message
: warningType !== WarningType.NONE && ( : warningType !== WarningType.NONE && (
...@@ -143,20 +175,18 @@ export const PriceTextInput = ({ ...@@ -143,20 +175,18 @@ export const PriceTextInput = ({
? formatEth(asset?.floorPrice ?? 0) ? formatEth(asset?.floorPrice ?? 0)
: formatEth(asset?.floor_sell_order_price ?? 0)} : formatEth(asset?.floor_sell_order_price ?? 0)}
ETH ETH
<Box <WarningAction
color={warningType === WarningType.BELOW_FLOOR ? 'accentAction' : 'orange'} warningType={warningType}
marginLeft="8"
cursor="pointer"
onClick={() => { onClick={() => {
warningType === WarningType.ALREADY_LISTED && removeSellAsset(asset) warningType === WarningType.ALREADY_LISTED && removeSellAsset(asset)
setWarningType(WarningType.NONE) setWarningType(WarningType.NONE)
}} }}
> >
{warningType === WarningType.BELOW_FLOOR ? <Trans>DISMISS</Trans> : <Trans>REMOVE ITEM</Trans>} {warningType === WarningType.BELOW_FLOOR ? <Trans>DISMISS</Trans> : <Trans>REMOVE ITEM</Trans>}
</Box> </WarningAction>
</> </>
)} )}
</Row> </WarningMessage>
</Column> </PriceTextInputWrapper>
) )
} }
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