Skip to content

fix: Fix accordion label inconsistency in stablecoins page #15471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/components/StablecoinAccordion/AccordionCustomItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseHTMLAttributes, ReactNode, useState } from "react"
import { BaseHTMLAttributes, ReactNode } from "react"

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

Expand Down Expand Up @@ -51,15 +51,26 @@ interface AccordionCustomItemProps {
* The category name of each accordion section
*/
category: CategoryNameType
/**
* Whether the accordion item is open
*/
isOpen?: boolean
/**
* Callback when open state changes
*/
onOpenChange?: (isOpen: boolean) => void
children: ReactNode
}

export const AccordionCustomItem = (props: AccordionCustomItemProps) => {
const { category, children } = props
const { category, children, isOpen = false, onOpenChange } = props
const { t } = useTranslation("page-stablecoins")
const [open, setOpen] = useState(false)

const handleOpen = () => setOpen(!open)
const handleOpen = () => {
if (onOpenChange) {
onOpenChange(!isOpen)
}
}

const contentObj = accordionButtonContent[category]

Expand Down Expand Up @@ -97,7 +108,7 @@ export const AccordionCustomItem = (props: AccordionCustomItemProps) => {
</p>
</div>
</Flex>
<MoreOrLessLink isOpen={open} />
<MoreOrLessLink isOpen={isOpen} />
</AccordionTrigger>
<AccordionContent className="-mx-px -mb-px mt-0 border border-border bg-background p-0 text-md md:p-0">
<Flex className="flex-col justify-between p-8 lg:flex-row">
Expand Down
27 changes: 23 additions & 4 deletions src/components/StablecoinAccordion/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useState } from "react"
import { MdArrowForward } from "react-icons/md"

import { ChildOnlyProp, TranslationKey } from "@/lib/types"
Expand All @@ -18,6 +19,7 @@ import {
RightColumnPanel,
} from "./AccordionCustomItem"
import { useStablecoinAccordion } from "./useStablecoinAccordion"
import { CategoryNameType } from "./utils"

import { useTranslation } from "@/hooks/useTranslation"

Expand Down Expand Up @@ -61,13 +63,18 @@ const H4 = (props: ChildOnlyProp) => (
const StablecoinAccordion = () => {
const { cardListGroups } = useStablecoinAccordion()
const { t } = useTranslation("page-stablecoins")
const [openItem, setOpenItem] = useState<CategoryNameType | null>(null)

// Overrides CardList default image width
const DEFAULT_IMAGE_WIDTH = 24

return (
<Accordion type="single" className="w-full rounded" collapsible>
<AccordionCustomItem category="dapps">
<AccordionCustomItem
category="dapps"
isOpen={openItem === "dapps"}
onOpenChange={(isOpen) => setOpenItem(isOpen ? "dapps" : null)}
>
<LeftColumnPanel>
<SectionTitle>
{t("page-stablecoins-accordion-requirements")}
Expand Down Expand Up @@ -110,7 +117,11 @@ const StablecoinAccordion = () => {
/>
</RightColumnPanel>
</AccordionCustomItem>
<AccordionCustomItem category="buy">
<AccordionCustomItem
category="buy"
isOpen={openItem === "buy"}
onOpenChange={(isOpen) => setOpenItem(isOpen ? "buy" : null)}
>
<LeftColumnPanel>
<SectionTitle>
{t("page-stablecoins-accordion-requirements")}
Expand Down Expand Up @@ -139,7 +150,11 @@ const StablecoinAccordion = () => {
/>
</RightColumnPanel>
</AccordionCustomItem>
<AccordionCustomItem category="earn">
<AccordionCustomItem
category="earn"
isOpen={openItem === "earn"}
onOpenChange={(isOpen) => setOpenItem(isOpen ? "earn" : null)}
>
<LeftColumnPanel>
<SectionTitle>
{t("page-stablecoins-accordion-requirements")}
Expand Down Expand Up @@ -168,7 +183,11 @@ const StablecoinAccordion = () => {
/>
</RightColumnPanel>
</AccordionCustomItem>
<AccordionCustomItem category="generate">
<AccordionCustomItem
category="generate"
isOpen={openItem === "generate"}
onOpenChange={(isOpen) => setOpenItem(isOpen ? "generate" : null)}
>
<LeftColumnPanel>
<SectionTitle>
{t("page-stablecoins-accordion-requirements")}
Expand Down