Skip to content

Commit f58e683

Browse files
authored
Merge pull request #1883 from IndexCoop/feat/chakra-popover-input-refactor
feat: chakra popover/input refactor
2 parents d03d264 + af749ad commit f58e683

File tree

9 files changed

+101
-261
lines changed

9 files changed

+101
-261
lines changed
Lines changed: 21 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { Flex, Input } from '@chakra-ui/react'
1+
import { Input } from '@headlessui/react'
22
import { useState } from 'react'
33

4-
import { colors } from '@/lib/styles/colors'
54
import { cn } from '@/lib/utils/tailwind'
65

76
import { Caption } from './caption'
@@ -13,13 +12,7 @@ export type InputSelectorToken = {
1312
symbol: string
1413
}
1514

16-
interface TradeInputSelectorConfig {
17-
isInputDisabled?: boolean
18-
isReadOnly?: boolean
19-
isSelectorDisabled?: boolean
20-
}
2115
interface TradeInputSelectorProps {
22-
config: TradeInputSelectorConfig
2316
caption: string
2417
balance: string
2518
formattedFiat: string
@@ -36,7 +29,6 @@ interface TradeInputSelectorProps {
3629
export const TradeInputSelector = (props: TradeInputSelectorProps) => {
3730
const {
3831
balance,
39-
config,
4032
formattedFiat,
4133
selectedToken,
4234
showSelectorButton = true,
@@ -45,13 +37,7 @@ export const TradeInputSelector = (props: TradeInputSelectorProps) => {
4537
const [isFocused, setIsFocused] = useState(false)
4638

4739
const onChangeInput = (amount: string) => {
48-
if (
49-
props.onChangeInput === undefined ||
50-
config.isInputDisabled === true ||
51-
config.isSelectorDisabled === true ||
52-
config.isReadOnly === true
53-
)
54-
return
40+
if (props.onChangeInput === undefined) return
5541
props.onChangeInput(selectedToken, amount)
5642
}
5743

@@ -63,61 +49,34 @@ export const TradeInputSelector = (props: TradeInputSelectorProps) => {
6349
)}
6450
>
6551
<Caption caption={props.caption} />
66-
<Flex align='center' direction='row' justify='space-between' mt='6px'>
67-
{config.isReadOnly ? (
68-
<p
69-
className={cn(
70-
'text-ellipsis whitespace-nowrap pr-1 text-[25px] font-medium',
71-
props.selectedTokenAmount === '0'
72-
? 'text-ic-gray-400'
73-
: 'text-ic-black',
74-
)}
75-
>
76-
{props.selectedTokenAmount}
77-
</p>
78-
) : (
79-
<Input
80-
className='text-ic-black dark:text-ic-white bg-transparent pr-1 text-3xl'
81-
fontSize='25px'
82-
fontWeight={500}
83-
overflow='hidden'
84-
placeholder='0'
85-
_placeholder={{ color: colors.ic.gray[400] }}
86-
type='number'
87-
onWheel={(e) => e.target instanceof HTMLElement && e.target.blur()}
88-
step='any'
89-
textOverflow='ellipsis'
90-
variant='unstyled'
91-
whiteSpace='nowrap'
92-
disabled={config.isInputDisabled ?? false}
93-
isReadOnly={config.isReadOnly ?? false}
94-
value={props.selectedTokenAmount}
95-
onChange={(event) => {
96-
onChangeInput(event.target.value)
97-
}}
98-
onFocus={() => setIsFocused(true)}
99-
onBlur={() => setIsFocused(false)}
100-
/>
101-
)}
52+
<div className='mt-1.5 flex items-center justify-between'>
53+
<Input
54+
className='placeholder:text-ic-gray-400 text-ic-black dark:text-ic-white w-full overflow-hidden text-ellipsis whitespace-nowrap bg-transparent pr-1 text-[25px] font-medium outline-none'
55+
placeholder='0'
56+
type='number'
57+
onWheel={(e) => e.target instanceof HTMLElement && e.target.blur()}
58+
step='any'
59+
value={props.selectedTokenAmount}
60+
onChange={(event) => {
61+
onChangeInput(event.target.value)
62+
}}
63+
onFocus={() => setIsFocused(true)}
64+
onBlur={() => setIsFocused(false)}
65+
/>
10266
<SelectorButton
10367
image={selectedToken.image}
10468
symbol={selectedToken.symbol}
10569
showChevron={props.showSelectorButtonChevron}
10670
visible={showSelectorButton}
10771
onClick={props.onSelectToken}
10872
/>
109-
</Flex>
110-
<Flex
111-
align='flex-start'
112-
direction='row'
113-
justify='space-between'
114-
mt='10px'
115-
>
73+
</div>
74+
<div className='mt-2.5 flex items-start justify-between'>
11675
<PriceUsd fiat={formattedFiat} priceImpact={props.priceImpact} />
11776
{showSelectorButton ? (
11877
<Balance balance={balance} onClick={props.onClickBalance} />
11978
) : null}
120-
</Flex>
79+
</div>
12180
</div>
12281
)
12382
}
@@ -155,12 +114,12 @@ interface PriceUsdProps {
155114
}
156115

157116
const PriceUsd = (props: PriceUsdProps) => (
158-
<Flex>
117+
<div className='flex'>
159118
<p className='text-ic-gray-400 text-xs font-medium'>{props.fiat}</p>
160119
{props.priceImpact && (
161120
<p className={cn('text-xs', props.priceImpact.colorCoding)}>
162121
&nbsp;{props.priceImpact.value}
163122
</p>
164123
)}
165-
</Flex>
124+
</div>
166125
)

src/app/earn/components/earn-widget/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ export function EarnWidget() {
120120
/>
121121
<TradeInputSelector
122122
showSelectorButtonChevron={isMinting}
123-
config={{ isReadOnly: false }}
124123
balance={inputBalanceFormatted}
125124
caption={isMinting ? 'Deposit' : 'Withdraw'}
126125
formattedFiat={inputAmoutUsd}

src/app/legacy/components/redeem-widget/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ export function RedeemWidget() {
135135
<div className='widget w-full min-w-80 max-w-xl flex-1 flex-col space-y-4 self-center rounded-3xl p-6'>
136136
<Title />
137137
<TradeInputSelector
138-
config={{ isReadOnly: false }}
139138
balance={inputTokenBalanceFormatted}
140139
caption='You redeem'
141140
formattedFiat={inputAmoutUsd}

src/app/leverage/components/leverage-widget/index.tsx

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { supportedNetworks } from '@/app/leverage/constants'
1010
import { useLeverageToken } from '@/app/leverage/provider'
1111
import { tradeMachineAtom } from '@/app/store/trade-machine'
1212
import { Receive } from '@/components/receive'
13-
import { Settings } from '@/components/settings'
1413
import { SmartTradeButton } from '@/components/smart-trade-button'
1514
import { SelectTokenModal } from '@/components/swap/components/select-token-modal'
1615
import { TransactionReviewModal } from '@/components/swap/components/transaction-review'
@@ -21,7 +20,6 @@ import { useGasData } from '@/lib/hooks/use-gas-data'
2120
import { useSupportedNetworks } from '@/lib/hooks/use-network'
2221
import { useQueryParams } from '@/lib/hooks/use-query-params'
2322
import { useWallet } from '@/lib/hooks/use-wallet'
24-
import { useSlippage } from '@/lib/providers/slippage'
2523
import { formatWei } from '@/lib/utils'
2624
import { getMaxBalance } from '@/lib/utils/max-balance'
2725

@@ -87,13 +85,6 @@ export function LeverageWidget() {
8785
onClose: onCloseSelectOutputToken,
8886
} = useDisclosure()
8987

90-
const {
91-
auto: autoSlippage,
92-
isAuto: isAutoSlippage,
93-
set: setSlippage,
94-
slippage,
95-
} = useSlippage()
96-
9788
const onClickBalance = useCallback(() => {
9889
if (!inputBalance) return
9990
const maxBalance = getMaxBalance(inputToken, inputBalance, gasData)
@@ -136,7 +127,6 @@ export function LeverageWidget() {
136127
/>
137128
<div className='relative'>
138129
<TradeInputSelector
139-
config={{ isReadOnly: false }}
140130
balance={inputBalanceFormatted}
141131
caption='Pay'
142132
formattedFiat={inputAmoutUsd}
@@ -146,15 +136,6 @@ export function LeverageWidget() {
146136
onClickBalance={onClickBalance}
147137
onSelectToken={onOpenSelectInputToken}
148138
/>
149-
<div className='absolute right-2 top-2'>
150-
<Settings
151-
isAuto={isAutoSlippage}
152-
isDarkMode={true}
153-
slippage={slippage}
154-
onChangeSlippage={setSlippage}
155-
onClickAuto={autoSlippage}
156-
/>
157-
</div>
158139
</div>
159140

160141
<Receive
Lines changed: 39 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Flex, Input } from '@chakra-ui/react'
1+
import { Input } from '@headlessui/react'
22

3+
import { Settings } from '@/components/settings'
34
import { Caption } from '@/components/swap/components/caption'
45
import { SelectorButton } from '@/components/swap/components/selector-button'
5-
import { colors } from '@/lib/styles/colors'
6+
import { useSlippage } from '@/lib/providers/slippage'
67
import { cn } from '@/lib/utils/tailwind'
78

89
export type InputSelectorToken = {
@@ -11,13 +12,7 @@ export type InputSelectorToken = {
1112
symbol: string
1213
}
1314

14-
interface TradeInputSelectorConfig {
15-
isInputDisabled?: boolean
16-
isReadOnly?: boolean
17-
isSelectorDisabled?: boolean
18-
}
1915
interface TradeInputSelectorProps {
20-
config: TradeInputSelectorConfig
2116
caption: string
2217
balance: string
2318
formattedFiat: string
@@ -34,79 +29,61 @@ interface TradeInputSelectorProps {
3429
export const TradeInputSelector = (props: TradeInputSelectorProps) => {
3530
const {
3631
balance,
37-
config,
3832
formattedFiat,
3933
selectedToken,
4034
showSelectorButton = true,
4135
} = props
4236

37+
const {
38+
auto: autoSlippage,
39+
isAuto: isAutoSlippage,
40+
set: setSlippage,
41+
slippage,
42+
} = useSlippage()
43+
4344
const onChangeInput = (amount: string) => {
44-
if (
45-
props.onChangeInput === undefined ||
46-
config.isInputDisabled === true ||
47-
config.isSelectorDisabled === true ||
48-
config.isReadOnly === true
49-
)
50-
return
45+
if (props.onChangeInput === undefined) return
5146
props.onChangeInput(selectedToken, amount)
5247
}
5348

5449
return (
55-
<div className='bg-ic-white border-ic-gray-100 flex flex-col rounded-lg border px-4 py-5 dark:border-[#D4D4D4] dark:bg-zinc-800'>
56-
<Caption caption={props.caption} />
57-
<Flex align='center' direction='row' justify='space-between' mt='6px'>
58-
{config.isReadOnly ? (
59-
<p
60-
className={cn(
61-
'text-ellipsis whitespace-nowrap pr-1 text-[25px] font-medium',
62-
props.selectedTokenAmount === '0'
63-
? 'text-ic-gray-400'
64-
: 'text-ic-black',
65-
)}
66-
>
67-
{props.selectedTokenAmount}
68-
</p>
69-
) : (
70-
<Input
71-
className='text-ic-black dark:text-ic-white bg-transparent pr-1 text-3xl'
72-
fontSize='25px'
73-
fontWeight={500}
74-
overflow='hidden'
75-
placeholder='0'
76-
_placeholder={{ color: colors.ic.gray[400] }}
77-
type='number'
78-
onWheel={(e) => e.target instanceof HTMLElement && e.target.blur()}
79-
step='any'
80-
textOverflow='ellipsis'
81-
variant='unstyled'
82-
whiteSpace='nowrap'
83-
disabled={config.isInputDisabled ?? false}
84-
isReadOnly={config.isReadOnly ?? false}
85-
value={props.selectedTokenAmount}
86-
onChange={(event) => {
87-
onChangeInput(event.target.value)
88-
}}
89-
/>
90-
)}
50+
<div className='bg-ic-white border-ic-gray-100 flex flex-col rounded-lg border px-4 py-4 dark:border-[#D4D4D4] dark:bg-zinc-800'>
51+
<div className='flex justify-between'>
52+
<Caption caption={props.caption} />
53+
<Settings
54+
isAuto={isAutoSlippage}
55+
isDarkMode={true}
56+
slippage={slippage}
57+
onChangeSlippage={setSlippage}
58+
onClickAuto={autoSlippage}
59+
/>
60+
</div>
61+
<div className='mt-1.5 flex items-center justify-between'>
62+
<Input
63+
className='placeholder:text-ic-gray-400 text-ic-black dark:text-ic-white w-full overflow-hidden text-ellipsis whitespace-nowrap bg-transparent pr-1 text-[25px] font-medium outline-none'
64+
placeholder='0'
65+
type='number'
66+
onWheel={(e) => e.target instanceof HTMLElement && e.target.blur()}
67+
step='any'
68+
value={props.selectedTokenAmount}
69+
onChange={(event) => {
70+
onChangeInput(event.target.value)
71+
}}
72+
/>
9173
<SelectorButton
9274
image={selectedToken.image}
9375
symbol={selectedToken.symbol}
9476
showChevron={props.showSelectorButtonChevron}
9577
visible={showSelectorButton}
9678
onClick={props.onSelectToken}
9779
/>
98-
</Flex>
99-
<Flex
100-
align='flex-start'
101-
direction='row'
102-
justify='space-between'
103-
mt='10px'
104-
>
80+
</div>
81+
<div className='mt-3 flex items-start justify-between'>
10582
<PriceUsd fiat={formattedFiat} priceImpact={props.priceImpact} />
10683
{showSelectorButton ? (
10784
<Balance balance={balance} onClick={props.onClickBalance} />
10885
) : null}
109-
</Flex>
86+
</div>
11087
</div>
11188
)
11289
}
@@ -146,12 +123,12 @@ interface PriceUsdProps {
146123
}
147124

148125
const PriceUsd = (props: PriceUsdProps) => (
149-
<Flex>
126+
<div className='flex'>
150127
<p className='text-xs font-medium text-neutral-400'>{props.fiat}</p>
151128
{props.priceImpact && (
152129
<p className={cn('text-xs', props.priceImpact.colorCoding)}>
153130
&nbsp;{props.priceImpact.value}
154131
</p>
155132
)}
156-
</Flex>
133+
</div>
157134
)

src/app/prt-staking/components/prt-section/prt-widget.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ export function PrtWidget({ token, onClose }: Props) {
188188
<WidgetTabs currentTab={currentTab} setCurrentTab={setCurrentTab} />
189189
{currentTab === WidgetTab.CLAIM ? <ClaimablePanel /> : <StakedPanel />}
190190
<TradeInputSelector
191-
config={{ isReadOnly: false }}
192191
balance={balance.toString()}
193192
caption={inputSelectorCaption}
194193
formattedFiat=''

0 commit comments

Comments
 (0)