From abb823fafe7ad1f1872220071a8dc9832a0efc95 Mon Sep 17 00:00:00 2001 From: fairlighteth <31534717+fairlighteth@users.noreply.github.com> Date: Thu, 2 Jan 2025 16:05:33 +0000 Subject: [PATCH] feat: make prepend symbol non selectable --- .../common/pure/CurrencyInputPanel/styled.tsx | 1 - .../components/NumericalInput/index.tsx | 101 +++++++++++------- .../containers/RateInput/styled.ts | 3 +- 3 files changed, 62 insertions(+), 43 deletions(-) diff --git a/apps/cowswap-frontend/src/common/pure/CurrencyInputPanel/styled.tsx b/apps/cowswap-frontend/src/common/pure/CurrencyInputPanel/styled.tsx index 2df15709f0..c33e868bad 100644 --- a/apps/cowswap-frontend/src/common/pure/CurrencyInputPanel/styled.tsx +++ b/apps/cowswap-frontend/src/common/pure/CurrencyInputPanel/styled.tsx @@ -48,7 +48,6 @@ export const CurrencyInputBox = styled.div` > div { display: flex; - flex-flow: row wrap; align-items: center; color: inherit; } diff --git a/apps/cowswap-frontend/src/legacy/components/NumericalInput/index.tsx b/apps/cowswap-frontend/src/legacy/components/NumericalInput/index.tsx index 9cd1042f43..652d95991f 100644 --- a/apps/cowswap-frontend/src/legacy/components/NumericalInput/index.tsx +++ b/apps/cowswap-frontend/src/legacy/components/NumericalInput/index.tsx @@ -3,27 +3,39 @@ import React from 'react' import { escapeRegExp } from '@cowprotocol/common-utils' import { UI } from '@cowprotocol/ui' -import styled from 'styled-components/macro' +import styled, { css } from 'styled-components/macro' import { autofocus } from 'common/utils/autofocus' -const StyledInput = styled.input<{ error?: boolean; fontSize?: string; align?: string }>` +const textStyle = css<{ error?: boolean; fontSize?: string }>` color: ${({ error }) => (error ? `var(${UI.COLOR_DANGER})` : 'inherit')}; + font-size: ${({ fontSize }) => fontSize ?? '28px'}; + font-weight: 500; +` + +const PrependSymbol = styled.span<{ error?: boolean; fontSize?: string }>` + display: flex; + align-items: center; + justify-content: center; + height: 100%; + user-select: none; + ${textStyle} +` + +const StyledInput = styled.input<{ error?: boolean; fontSize?: string; align?: string }>` + ${textStyle} width: 0; position: relative; - font-weight: 500; outline: none; border: none; flex: 1 1 auto; background-color: var(${UI.COLOR_PAPER}); - font-size: ${({ fontSize }) => fontSize ?? '28px'}; - text-align: ${({ align }) => align && align}; + text-align: ${({ align }) => align || 'right'}; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0px; appearance: textfield; - text-align: right; ::-webkit-search-decoration { -webkit-appearance: none; @@ -70,41 +82,48 @@ export const Input = React.memo(function InnerInput({ } return ( - { - autofocus(event) - onFocus?.(event) - }} - onChange={(event) => { - if (prependSymbol) { - const value = event.target.value - - // cut off prepended symbol - const formattedValue = value.toString().includes(prependSymbol) - ? value.toString().slice(1, value.toString().length + 1) - : value - - // replace commas with periods, because uniswap exclusively uses period as the decimal separator - enforcer(formattedValue.replace(/,/g, '.')) - } else { - enforcer(event.target.value.replace(/,/g, '.')) - } - }} - // universal input options - inputMode="decimal" - autoComplete="off" - autoCorrect="off" - // text-specific options - type={type || 'text'} - pattern="^[0-9]*[.,]?[0-9]*$" - placeholder={placeholder || '0.0'} - minLength={1} - maxLength={32} - spellCheck="false" - /> + <> + {prependSymbol && ( + + {prependSymbol} + + )} + { + autofocus(event) + onFocus?.(event) + }} + onChange={(event) => { + if (prependSymbol) { + const value = event.target.value + + // cut off prepended symbol + const formattedValue = value.toString().includes(prependSymbol) + ? value.toString().slice(1, value.toString().length + 1) + : value + + // replace commas with periods, because uniswap exclusively uses period as the decimal separator + enforcer(formattedValue.replace(/,/g, '.')) + } else { + enforcer(event.target.value.replace(/,/g, '.')) + } + }} + // universal input options + inputMode="decimal" + autoComplete="off" + autoCorrect="off" + // text-specific options + type={type || 'text'} + pattern="^[0-9]*[.,]?[0-9]*$" + placeholder={placeholder || '0.0'} + minLength={1} + maxLength={32} + spellCheck="false" + /> + ) }) diff --git a/apps/cowswap-frontend/src/modules/limitOrders/containers/RateInput/styled.ts b/apps/cowswap-frontend/src/modules/limitOrders/containers/RateInput/styled.ts index c56abdaaa8..773ab8b8e5 100644 --- a/apps/cowswap-frontend/src/modules/limitOrders/containers/RateInput/styled.ts +++ b/apps/cowswap-frontend/src/modules/limitOrders/containers/RateInput/styled.ts @@ -82,7 +82,7 @@ export const Body = styled.div` justify-content: space-between; width: 100%; max-width: 100%; - gap: 8px; + gap: 0; padding: 12px 0 4px; color: inherit; ` @@ -109,6 +109,7 @@ export const CurrencyToggleGroup = styled.div` align-items: center; background: transparent; overflow: hidden; + margin: 0 0 0 8px; ` export const ActiveCurrency = styled.button<{ $active?: boolean }>`