Skip to content

Commit 26619ff

Browse files
authored
Merge pull request #14371 from Baystef/migrate/stableaccordioncustomitem
Migrate StablecoinAccordion/AccordionCustomItem Component to tailwind/shadcn
2 parents 12595c4 + 5cbca61 commit 26619ff

File tree

4 files changed

+69
-85
lines changed

4 files changed

+69
-85
lines changed
Lines changed: 65 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,47 @@
1-
import { ReactNode } from "react"
1+
import { BaseHTMLAttributes, ReactNode, useState } from "react"
22
import { useTranslation } from "next-i18next"
3-
import {
4-
AccordionButton,
5-
AccordionItem,
6-
AccordionPanel,
7-
Box,
8-
BoxProps,
9-
Flex,
10-
Heading,
11-
Text,
12-
} from "@chakra-ui/react"
133

144
import type { ChildOnlyProp } from "@/lib/types"
155

6+
import { Flex } from "@/components/ui/flex"
7+
import { Tag } from "@/components/ui/tag"
8+
9+
import {
10+
AccordionContent,
11+
AccordionItem,
12+
AccordionTrigger,
13+
} from "../../../tailwind/ui/accordion"
1614
import Emoji from "../Emoji"
17-
import Pill from "../Pill"
1815

1916
import { accordionButtonContent, CategoryNameType } from "./utils"
2017

21-
export const LeftColumnPanel = (props: ChildOnlyProp & Partial<BoxProps>) => (
22-
<Box flex="0 0 50%" maxW={{ lg: "75%" }} me={{ lg: 16 }} {...props} />
18+
type LeftColumnPanelElement = BaseHTMLAttributes<HTMLDivElement>
19+
20+
export const LeftColumnPanel = (
21+
props: ChildOnlyProp & LeftColumnPanelElement
22+
) => (
23+
<div
24+
className="flex-shrink-0 flex-grow-0 basis-1/2 lg:me-16 lg:max-w-[75%]"
25+
{...props}
26+
/>
2327
)
2428

2529
export const RightColumnPanel = (props: ChildOnlyProp) => (
26-
<LeftColumnPanel me={0} flex="0 1 50%" mt={{ base: 12, lg: 0 }} {...props} />
30+
<LeftColumnPanel
31+
className="me-0 mt-12 flex-shrink flex-grow-0 basis-1/2 lg:mt-0"
32+
{...props}
33+
/>
2734
)
2835

2936
const MoreOrLessLink = ({ isOpen }: { isOpen: boolean }) => {
3037
const { t } = useTranslation("page-stablecoins")
3138

3239
return (
33-
<Box me={6} color="primary.base">
40+
<div className="me-6 text-md text-primary">
3441
{isOpen
3542
? t("page-stablecoins-accordion-less")
3643
: t("page-stablecoins-accordion-more")}
37-
</Box>
44+
</div>
3845
)
3946
}
4047

@@ -49,74 +56,52 @@ interface AccordionCustomItemProps {
4956
export const AccordionCustomItem = (props: AccordionCustomItemProps) => {
5057
const { category, children } = props
5158
const { t } = useTranslation("page-stablecoins")
59+
const [open, setOpen] = useState(false)
60+
61+
const handleOpen = () => setOpen(!open)
5262

5363
const contentObj = accordionButtonContent[category]
5464

5565
return (
56-
<AccordionItem border="1px" borderColor="border !important">
57-
{({ isExpanded }) => (
58-
<>
59-
<AccordionButton
60-
justifyContent="space-between"
61-
alignItems="center"
62-
px="0"
63-
py="0"
64-
_expanded={{ background: "transparent" }}
65-
_hover={{ background: "ednBackground" }}
66-
>
67-
<Flex
68-
alignItems={{ base: "flex-start", lg: "center" }}
69-
flexDirection={{ base: "column", md: "row" }}
70-
m={6}
71-
me={4}
72-
{...props}
73-
>
74-
<Emoji
75-
text={contentObj.emoji}
76-
className="mb-2 me-6 text-[3rem] md:mb-0 md:text-[4rem]"
77-
/>
78-
<Box>
79-
<Flex alignItems="center" mb={2}>
80-
<Heading
81-
as="h3"
82-
fontSize={{ base: "1.25rem", md: "1.5rem" }}
83-
lineHeight={1.4}
84-
>
85-
{t(contentObj.title)}
86-
</Heading>
87-
{!!contentObj.pill && (
88-
<Pill ms={4} background={contentObj.pill.color}>
89-
{t(contentObj.pill.name)}
90-
</Pill>
91-
)}
92-
</Flex>
93-
<Text color="text200" textAlign="start">
94-
{t(contentObj.textPreview)}
95-
</Text>
96-
</Box>
97-
</Flex>
98-
<MoreOrLessLink isOpen={isExpanded} />
99-
</AccordionButton>
100-
<AccordionPanel
101-
background="ednBackground"
102-
border="1px"
103-
borderColor="border"
104-
mb="-1px"
105-
mx="-1px"
106-
mt="0"
107-
p="0"
108-
fontSize="md"
109-
>
110-
<Flex
111-
p={8}
112-
justifyContent="space-between"
113-
flexDirection={{ base: "column", lg: "row" }}
114-
>
115-
{children}
66+
<AccordionItem value={contentObj.title} className="border">
67+
<AccordionTrigger
68+
hideIcon
69+
className="items-center justify-between px-0 py-0 text-body-medium hover:text-body-medium md:px-0"
70+
onClick={handleOpen}
71+
>
72+
<Flex
73+
className="lg:center m-6 me-4 flex-col items-start md:flex-row"
74+
{...props}
75+
>
76+
<Emoji
77+
text={contentObj.emoji}
78+
className="mb-2 me-6 text-5xl md:mb-0 md:text-6xl"
79+
/>
80+
<div>
81+
<Flex className="mb-2 items-center">
82+
<h3 className="text-xl text-body hover:text-body md:text-2xl">
83+
{t(contentObj.title)}
84+
</h3>
85+
{!!contentObj.pill && (
86+
<Tag
87+
className="ms-4"
88+
variant="solid"
89+
status={contentObj.pill.color}
90+
>
91+
{t(contentObj.pill.name)}
92+
</Tag>
93+
)}
11694
</Flex>
117-
</AccordionPanel>
118-
</>
119-
)}
95+
<p className="text-start text-md">{t(contentObj.textPreview)}</p>
96+
</div>
97+
</Flex>
98+
<MoreOrLessLink isOpen={open} />
99+
</AccordionTrigger>
100+
<AccordionContent className="-mx-px -mb-px mt-0 border border-border bg-background p-0 text-md md:p-0">
101+
<Flex className="flex-col justify-between p-8 lg:flex-row">
102+
{children}
103+
</Flex>
104+
</AccordionContent>
120105
</AccordionItem>
121106
)
122107
}

src/components/StablecoinAccordion/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useTranslation } from "next-i18next"
22
import { MdArrowForward } from "react-icons/md"
33
import {
4-
Accordion,
54
Box,
65
Flex,
76
Heading,
@@ -12,6 +11,7 @@ import {
1211

1312
import { ChildOnlyProp, TranslationKey } from "@/lib/types"
1413

14+
import { Accordion } from "../../../tailwind/ui/accordion"
1515
import { ButtonLink } from "../Buttons"
1616
import CardList from "../CardList"
1717
import InfoBanner from "../InfoBanner"
@@ -104,7 +104,7 @@ const StablecoinAccordion = () => {
104104
const DEFAULT_IMAGE_WIDTH = 24
105105

106106
return (
107-
<Accordion borderRadius="base" width="full" allowToggle>
107+
<Accordion type="single" className="w-full rounded" collapsible>
108108
<AccordionCustomItem category="dapps">
109109
<LeftColumnPanel>
110110
<SectionTitle>

src/components/StablecoinAccordion/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type AccordionButtonContentType = {
66
emoji: string
77
title: TranslationKey
88
pill?: {
9-
color: string
9+
color: "success" | "warning"
1010
name: TranslationKey
1111
}
1212
textPreview: TranslationKey
@@ -19,7 +19,7 @@ export const accordionButtonContent: {
1919
emoji: ":twisted_rightwards_arrows:",
2020
title: "page-stablecoins-accordion-swap-title",
2121
pill: {
22-
color: "success100",
22+
color: "success",
2323
name: "page-stablecoins-accordion-swap-pill",
2424
},
2525
textPreview: "page-stablecoins-accordion-swap-text-preview",

tailwind/ui/accordion.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const AccordionTrigger = React.forwardRef<
2626
ref={ref}
2727
className={cn(
2828
"flex flex-1 items-center justify-between gap-2 px-2 py-2 font-medium transition-all hover:bg-background-highlight hover:text-primary-hover focus-visible:outline-1 focus-visible:-outline-offset-1 focus-visible:outline-primary-hover md:px-4 [&[data-state=open]:dir(rtl)>svg]:rotate-90 [&[data-state=open]>svg]:-rotate-90 [&[data-state=open]]:bg-background-highlight [&[data-state=open]]:text-primary-high-contrast",
29-
3029
className
3130
)}
3231
{...props}

0 commit comments

Comments
 (0)