Skip to content

Commit c222ab7

Browse files
committed
refactor accordion components
1 parent f58e683 commit c222ab7

File tree

1 file changed

+54
-87
lines changed
  • src/components/swap/components/trade-details

1 file changed

+54
-87
lines changed
Lines changed: 54 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
import {
2-
Accordion,
3-
AccordionButton,
4-
AccordionIcon,
5-
AccordionItem,
6-
AccordionPanel,
7-
Flex,
8-
} from '@chakra-ui/react'
2+
Disclosure,
3+
DisclosureButton,
4+
DisclosurePanel,
5+
} from '@headlessui/react'
96
import { ExclamationTriangleIcon } from '@heroicons/react/20/solid'
107
import Image from 'next/image'
118
import { useState } from 'react'
129

1310
import { StyledSkeleton } from '@/components/skeleton'
1411
import { Tag } from '@/components/swap/components/trade-details/tag'
1512
import { QuoteType } from '@/lib/hooks/use-best-quote/types'
16-
import { colors, useColorStyles } from '@/lib/styles/colors'
1713
import { cn } from '@/lib/utils/tailwind'
1814

1915
import { TradeInfoItem } from '../../types'
@@ -39,7 +35,6 @@ interface TradeDetailsProps {
3935

4036
export const TradeDetails = (props: TradeDetailsProps) => {
4137
const { data, isLoading, prices, showWarning } = props
42-
const { styles } = useColorStyles()
4338

4439
const [showInputTokenPrice, setShowInputTokenPrice] = useState(true)
4540

@@ -57,83 +52,55 @@ export const TradeDetails = (props: TradeDetailsProps) => {
5752
: prices.outputTokenPriceUsd
5853

5954
return (
60-
<Flex mb={'6px'}>
61-
<Accordion allowToggle border={0} borderColor='transparent' w='100%'>
62-
<AccordionItem isDisabled={isLoading}>
63-
{({ isExpanded }) => (
64-
<>
65-
<h4>
66-
<AccordionButton
67-
border='1px solid'
68-
borderColor={styles.border}
69-
borderRadius={12}
70-
color={colors.ic.gray[400]}
71-
_expanded={{
72-
borderBottomColor: 'transparent',
73-
borderBottomRadius: 0,
74-
}}
75-
p={'16px 20px'}
76-
>
77-
<Flex
78-
align='center'
79-
flex='1'
80-
justify='space-between'
81-
pr='4px'
82-
>
83-
<>
84-
<Flex>
85-
{showWarning && (
86-
<ExclamationTriangleIcon className='text-ic-gray-600 dark:text-ic-gray-400 mr-2 size-5' />
87-
)}
88-
{!showWarning && (
89-
<Image
90-
className='text-ic-gray-600 mr-1'
91-
alt='Swap icon'
92-
src='/assets/swap-icon.svg'
93-
width={16}
94-
height={16}
95-
/>
96-
)}
97-
<div onClick={onToggleTokenPrice}>
98-
{isLoading ? (
99-
<StyledSkeleton width={200} />
100-
) : (
101-
<TradePrice
102-
comparisonLabel={comparisonLabel}
103-
usdLabel={usdLabel}
104-
/>
105-
)}
106-
</div>
107-
</Flex>
108-
<div className={cn('flex gap-4', isExpanded && 'hidden')}>
109-
{!isLoading &&
110-
props.selectedQuoteType === QuoteType.index && (
111-
<Tag label={'LI.FI'} />
112-
)}
113-
{!isLoading &&
114-
props.selectedQuoteType === QuoteType.flashmint && (
115-
<FlashMintTag />
116-
)}
117-
{isLoading && <StyledSkeleton width={70} />}
118-
</div>
119-
</>
120-
</Flex>
121-
<AccordionIcon />
122-
</AccordionButton>
123-
</h4>
124-
<AccordionPanel
125-
border='1px solid'
126-
borderColor={styles.border}
127-
borderRadius='0 0 12px 12px'
128-
borderTopColor={'transparent'}
129-
p={'4px 20px 16px'}
130-
>
131-
<TradeInfoItemsContainer items={data} isLoading={isLoading} />
132-
</AccordionPanel>
133-
</>
134-
)}
135-
</AccordionItem>
136-
</Accordion>
137-
</Flex>
55+
<div className='mb-1.5 flex'>
56+
<Disclosure>
57+
{({ open }) => (
58+
<>
59+
<DisclosureButton className='py-2'>
60+
<div className='flex flex-1 items-center justify-between pr-1'>
61+
<div className='flex'>
62+
{showWarning && (
63+
<ExclamationTriangleIcon className='text-ic-gray-600 dark:text-ic-gray-400 mr-2 size-5' />
64+
)}
65+
{!showWarning && (
66+
<Image
67+
className='text-ic-gray-600 mr-1'
68+
alt='Swap icon'
69+
src='/assets/swap-icon.svg'
70+
width={16}
71+
height={16}
72+
/>
73+
)}
74+
<div onClick={onToggleTokenPrice}>
75+
{isLoading ? (
76+
<StyledSkeleton width={200} />
77+
) : (
78+
<TradePrice
79+
comparisonLabel={comparisonLabel}
80+
usdLabel={usdLabel}
81+
/>
82+
)}
83+
</div>
84+
</div>
85+
<div className={cn('flex gap-4', open && 'hidden')}>
86+
{!isLoading &&
87+
props.selectedQuoteType === QuoteType.index && (
88+
<Tag label={'LI.FI'} />
89+
)}
90+
{!isLoading &&
91+
props.selectedQuoteType === QuoteType.flashmint && (
92+
<FlashMintTag />
93+
)}
94+
{isLoading && <StyledSkeleton width={70} />}
95+
</div>
96+
</div>
97+
</DisclosureButton>
98+
<DisclosurePanel className='px-5 pb-4 pt-1'>
99+
<TradeInfoItemsContainer items={data} isLoading={isLoading} />
100+
</DisclosurePanel>
101+
</>
102+
)}
103+
</Disclosure>
104+
</div>
138105
)
139106
}

0 commit comments

Comments
 (0)