Skip to content

Commit d4b20f8

Browse files
committed
refactor flex component
1 parent c222ab7 commit d4b20f8

File tree

12 files changed

+103
-170
lines changed

12 files changed

+103
-170
lines changed
Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { Flex } from '@chakra-ui/react'
21
import { ChevronDownIcon } from '@heroicons/react/20/solid'
32
import Image from 'next/image'
43

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

76
type SelectorProps = {
87
onClick: () => void
@@ -19,21 +18,17 @@ export const SelectorButton = ({
1918
showChevron,
2019
visible = true,
2120
}: SelectorProps) => (
22-
<Flex
23-
align='center'
24-
bg={colors.ic.gray[100]}
25-
borderRadius='32'
26-
cursor='pointer'
21+
<div
22+
className={cn(
23+
'bg-ic-gray-100 flex h-11 shrink-0 cursor-pointer items-center rounded-[32px] p-2.5',
24+
visible ? 'visible' : 'invisible',
25+
)}
2726
onClick={onClick}
28-
p='10px'
29-
h='44px'
30-
shrink={0}
31-
visibility={visible ? 'visible' : 'hidden'}
3227
>
3328
<Image alt={`${symbol} logo`} src={image} width={20} height={20} />
3429
<p className='text-ic-black mx-2 text-sm font-medium'>{symbol}</p>
3530
{showChevron !== false && (
3631
<ChevronDownIcon className='text-ic-gray-900 size-6' />
3732
)}
38-
</Flex>
33+
</div>
3934
)

src/app/globals.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,21 @@ body,
127127
background-attachment: fixed;
128128
filter: blur(20px) opacity(20%) saturate(100%);
129129
}
130+
131+
.swap-widget {
132+
background:
133+
linear-gradient(
134+
33deg,
135+
rgba(0, 189, 192, 0.05) -9.23%,
136+
rgba(0, 249, 228, 0.05) 48.82%,
137+
rgba(212, 0, 216, 0.05) 131.54%
138+
),
139+
linear-gradient(
140+
187deg,
141+
rgb(252, 255, 255) -184.07%,
142+
rgb(247, 248, 248) 171.05%
143+
);
144+
box-shadow:
145+
rgba(44, 51, 51, 0.25) 0.5px 1px 2px 0px,
146+
rgb(252, 255, 255) 2px 2px 1px 0px inset;
147+
}

src/app/swap/[[...path]]/page.tsx

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
11
'use client'
22

3-
import { Flex } from '@chakra-ui/react'
4-
53
import { Swap } from '@/components/swap'
64
import { useSelectedToken } from '@/lib/providers/selected-token-provider'
75

86
export default function SwapPage() {
97
const { inputToken, isMinting, outputToken } = useSelectedToken()
108
return (
11-
<Flex
12-
direction={['column', 'column', 'column', 'row']}
13-
mx='auto'
14-
height='inherit'
15-
>
16-
<Flex
17-
className='flex-col gap-8'
18-
mb={[4, 4, 4, 12]}
19-
mr={4}
20-
w={['inherit', '500px']}
21-
>
9+
<div className='mx-auto flex h-full flex-col lg:flex-row'>
10+
<div className='mb-4 mr-1 flex w-full max-w-lg flex-col gap-8 lg:mb-3'>
2211
<Swap
2312
isBuying={isMinting}
2413
inputToken={inputToken}
2514
outputToken={outputToken}
2615
/>
27-
</Flex>
28-
</Flex>
16+
</div>
17+
</div>
2918
)
3019
}

src/app/swap/layout.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Flex } from '@chakra-ui/react'
2-
31
import { Footer } from '@/components/footer'
42
import { Header } from '@/components/header'
53

@@ -14,11 +12,11 @@ export default function Layout({ children }: LayoutProps) {
1412
<div className='bg-ic-white dark:bg-ic-black h-full w-full'>
1513
<Providers>
1614
<Header />
17-
<Flex direction='column' mb='50px'>
18-
<Flex maxWidth='1024px' m={['0 auto']} p='60px 16px 0px 16px'>
15+
<div className='mb-[50px] flex flex-col'>
16+
<div className='mx-auto my-0 flex max-w-5xl px-4 pt-[60px]'>
1917
{children}
20-
</Flex>
21-
</Flex>
18+
</div>
19+
</div>
2220
<Footer />
2321
</Providers>
2422
</div>

src/components/settings/warning.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Flex } from '@chakra-ui/react'
21
import { ExclamationCircleIcon } from '@heroicons/react/20/solid'
32

43
type WarningProps = {
@@ -12,15 +11,15 @@ function getTexts(lowSlippage: boolean) {
1211
}
1312

1413
export const Warning = (props: WarningProps) => (
15-
<Flex direction={'column'}>
16-
<Flex align={'center'} direction={'row'}>
14+
<div className='flex flex-col'>
15+
<div className='flex items-center'>
1716
<ExclamationCircleIcon className='text-ic-yellow size-4' />
1817
<p className='text-ic-gray-600 ml-1.5 text-base font-medium'>
1918
Slippage warning
2019
</p>
21-
</Flex>
20+
</div>
2221
<p className='text-ic-gray-600 mt-0.5 text-sm font-normal'>
2322
{getTexts(props.lowSlippage)}
2423
</p>
25-
</Flex>
24+
</div>
2625
)
Lines changed: 38 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { Flex } from '@chakra-ui/react'
21
import Image from 'next/image'
32

43
import { StyledSkeleton } from '@/components/skeleton'
5-
import { colors } from '@/lib/styles/colors'
64
import { cn } from '@/lib/utils/tailwind'
75

86
import { QuoteDisplay } from './types'
@@ -15,73 +13,58 @@ type QuoteAvailableProps = {
1513
onClick: () => void
1614
}
1715

18-
function getBackgroundColor(isSelected: boolean, isBestQuote: boolean) {
19-
// return for best quote (whether selected or not)
20-
if (isBestQuote) return '#F0FEFF'
21-
if (!isBestQuote && isSelected) return '#FFF5FA'
22-
return colors.ic.gray[50]
23-
}
24-
25-
function useHighlightColor(isSelected: boolean, isBestQuote: boolean) {
26-
if (isBestQuote && isSelected) {
27-
return { border: colors.ic.blue[600], text: 'text-ic-blue-600' }
28-
}
29-
if (isBestQuote && !isSelected) {
30-
return { border: '#CFF5F6', text: 'text-[#CFF5F6]' }
31-
}
32-
if (!isBestQuote && isSelected) {
33-
return {
34-
border: '#F178B6',
35-
text: 'text-[#F178B6]',
36-
}
37-
}
38-
return {
39-
border: colors.ic.gray[400],
40-
text: 'text-ic-gray-400',
41-
}
42-
}
43-
4416
export const QuoteAvailable = (props: QuoteAvailableProps) => {
4517
const { type, isLoading, isSelected, onClick, quote } = props
46-
const background = getBackgroundColor(isSelected, quote?.isBestQuote ?? false)
47-
const highlight = useHighlightColor(isSelected, quote?.isBestQuote ?? false)
48-
const borderWidth = isSelected ? 2 : 0
18+
const isBestQuote = quote?.isBestQuote
4919
return (
50-
<Flex
51-
bg={background}
52-
borderColor={highlight.border}
53-
borderRadius='12'
54-
borderWidth={borderWidth}
55-
cursor='pointer'
56-
direction={'column'}
57-
p='16px'
58-
w='100%'
59-
h='110px'
20+
<div
21+
className={cn(
22+
'border-ic-gray-400 flex h-[110px] w-full cursor-pointer flex-col rounded-xl p-4',
23+
isSelected ? 'border' : 'border-0',
24+
{
25+
'bg-[#F0FEFF]': isBestQuote,
26+
'border-[#F178B6] bg-[#FFF5FA]': !isBestQuote && isSelected,
27+
'bg-ic-gray-50': !isBestQuote && !isSelected,
28+
'border-ic-blue-600': isBestQuote && isSelected,
29+
'border-[#CFF5F6]': isBestQuote && !isSelected,
30+
},
31+
)}
6032
onClick={onClick}
6133
>
62-
<Flex align='space-between' direction='column' justify={'flex-start'}>
63-
<Flex justify={'space-between'}>
34+
<div className='flex flex-col justify-start'>
35+
<div className='flex justify-between'>
6436
<p className='text-ic-gray-500 text-xs font-medium'>
6537
{isLoading && <StyledSkeleton width={50} />}
6638
{!isLoading && quote && quote.inputAmount}
6739
</p>
68-
<Flex direction={'row'} gap={1}>
40+
<div className='flex gap-1'>
6941
{quote?.isBestQuote && (
70-
<Flex opacity={isSelected ? 1 : 0.2}>
42+
<div
43+
className={cn(
44+
'flex',
45+
isSelected ? 'opacity-100' : 'opacity-20',
46+
)}
47+
>
7148
<Image
7249
src={'/assets/icon-trophy.svg'}
7350
alt={'token icon'}
7451
width={12}
7552
height={12}
7653
/>
77-
</Flex>
54+
</div>
7855
)}
79-
<p className={cn('text-sm font-semibold', highlight.text)}>
56+
<p
57+
className={cn('text-ic-gray-400 text-sm font-semibold', {
58+
'text-[#F178B6]': !isBestQuote && isSelected,
59+
'text-ic-blue-600': isBestQuote && isSelected,
60+
'text-[#CFF5F6]': isBestQuote && !isSelected,
61+
})}
62+
>
8063
{type.toUpperCase()}
8164
</p>
82-
</Flex>
83-
</Flex>
84-
</Flex>
65+
</div>
66+
</div>
67+
</div>
8568
<p
8669
className={cn(
8770
'text-2xl font-medium',
@@ -91,16 +74,13 @@ export const QuoteAvailable = (props: QuoteAvailableProps) => {
9174
{isLoading && <StyledSkeleton width={200} />}
9275
{!isLoading && quote && quote.outputAmount}
9376
</p>
94-
<Flex
95-
direction={['column', 'row']}
96-
justify={['flex-start', 'space-between']}
97-
>
77+
<div className='xs:flex-row xs:justify-between flex flex-col justify-start'>
9878
<p className='text-ic-gray-500 text-xs font-medium'>
9979
{isLoading && <StyledSkeleton width={80} />}
10080
{!isLoading && quote && quote.feesTotal}
10181
</p>
10282
{quote && (
103-
<Flex direction='row' gap='6px'>
83+
<div className='flex flex-row gap-1.5'>
10484
<Image
10585
className='text-ic-gray-500'
10686
alt='Gas fees icon'
@@ -111,9 +91,9 @@ export const QuoteAvailable = (props: QuoteAvailableProps) => {
11191
<p className='text-ic-gray-500 text-xs font-medium'>
11292
{quote.feesGas}
11393
</p>
114-
</Flex>
94+
</div>
11595
)}
116-
</Flex>
117-
</Flex>
96+
</div>
97+
</div>
11898
)
11999
}
Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Flex } from '@chakra-ui/react'
2-
31
type QuoteNotAvailableProps = {
42
type: string
53
}
@@ -8,26 +6,18 @@ export const QuoteNotAvailable = ({ type }: QuoteNotAvailableProps) => {
86
const isFlashmint = type === 'Flash Mint'
97
const text = isFlashmint ? 'flash minting' : 'swapping'
108
return (
11-
<Flex
12-
className='bg-ic-gray-50'
13-
borderRadius='12'
14-
cursor='pointer'
15-
direction={'column'}
16-
p='16px'
17-
w='100%'
18-
h='110px'
19-
>
20-
<Flex justify='flex-end' direction='row'>
9+
<div className='bg-ic-gray-50 flex h-[110px] w-full cursor-pointer flex-col rounded-xl p-4'>
10+
<div className='flex justify-end'>
2111
<p className='text-ic-gray-400 text-sm font-semibold'>
2212
{type.toUpperCase()}
2313
</p>
24-
</Flex>
14+
</div>
2515
<p className='text-ic-gray-300 text-base font-medium'>
2616
{type} unavailable
2717
</p>
2818
<p className='text-ic-gray-300 text-sm font-normal'>
2919
{`This token is not available for ${text}.`}
3020
</p>
31-
</Flex>
21+
</div>
3222
)
3323
}
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
import { Flex } from '@chakra-ui/react'
2-
31
interface TradePriceProps {
42
comparisonLabel: string
53
usdLabel: string
64
}
75

86
export const TradePrice = ({ comparisonLabel, usdLabel }: TradePriceProps) => {
97
return (
10-
<Flex align='flex-start' direction={['column', 'row']}>
8+
<div className='xs:flex-row flex flex-col items-start'>
119
<p className='text-ic-gray-600 text-xs font-medium'>{comparisonLabel}</p>
1210
<p className='text-ic-gray-400 ml-0 text-xs font-medium sm:ml-1'>
1311
{usdLabel}
1412
</p>
15-
</Flex>
13+
</div>
1614
)
1715
}

src/components/swap/components/trade-output.tsx

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import { Flex } from '@chakra-ui/react'
2-
31
import { Token } from '@/constants/tokens'
42
import { QuoteType } from '@/lib/hooks/use-best-quote/types'
5-
import { colors } from '@/lib/styles/colors'
63

74
import { FormattedQuoteDisplay } from '../hooks/use-swap/formatters/result'
85

@@ -22,23 +19,16 @@ interface TradeOutputProps {
2219
export const TradeOutput = (props: TradeOutputProps) => {
2320
const { selectedQuote, selectedToken } = props
2421
return (
25-
<Flex
26-
className='bg-ic-white'
27-
border={'1px solid'}
28-
borderColor={colors.ic.gray[100]}
29-
borderRadius={12}
30-
direction={'column'}
31-
p={'16px'}
32-
>
22+
<div className='bg-ic-white border-ic-gray-100 flex flex-col rounded-xl border p-4'>
3323
<Caption caption={props.caption} />
34-
<Flex justify='flex-end' w='100%'>
24+
<div className='flex w-full justify-end'>
3525
<SelectorButton
3626
image={selectedToken.image}
3727
symbol={selectedToken.symbol}
3828
onClick={props.onSelectToken}
3929
/>
40-
</Flex>
41-
<Flex direction='column' gap='8px' mt='20px'>
30+
</div>
31+
<div className='flex flex-col gap-2 pt-5'>
4232
{props.quotes.length > 0 && (
4333
<p className='text-ic-gray-600 text-xs font-medium'>
4434
Select your preferred route
@@ -58,7 +48,7 @@ export const TradeOutput = (props: TradeOutputProps) => {
5848
}}
5949
/>
6050
))}
61-
</Flex>
62-
</Flex>
51+
</div>
52+
</div>
6353
)
6454
}

0 commit comments

Comments
 (0)