Skip to content

Commit

Permalink
feat(Accordion): isDefaultExpanded
Browse files Browse the repository at this point in the history
  • Loading branch information
netpoe committed Jun 8, 2024
1 parent 767edd0 commit 561a69e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/src/ui/accordion/Accordion.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import clsx from "clsx";
import { useState } from "react";
import { useEffect, useState } from "react";

import { Icon } from "ui/icon/Icon";

Expand All @@ -9,9 +9,13 @@ import styles from "./Accordion.module.scss";
export const Accordion: React.FC<AccordionProps> & {
Header: React.FC<AccordionHeaderProps>;
Content: React.FC<AccordionContentProps>;
} = ({ className, accordionHeader, accordionContent }) => {
} = ({ className, accordionHeader, accordionContent, isDefaultExpanded }) => {
const [isExpanded, setIsExpanded] = useState(false);

useEffect(() => {
setIsExpanded(!!isDefaultExpanded);
}, [isDefaultExpanded]);

const onClickHeaderTrigger = () => {
setIsExpanded(!isExpanded);
};
Expand Down
1 change: 1 addition & 0 deletions app/src/ui/accordion/Accordion.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { HTMLAttributes, ReactNode } from "react";
export type AccordionProps = HTMLAttributes<HTMLDivElement> & {
accordionHeader: ReactNode;
accordionContent: ReactNode;
isDefaultExpanded?: boolean;
className?: string;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export const LarsKristoHellheads: React.FC<LatestCollectionProps> = ({ className
}
/>
<Accordion
isDefaultExpanded
accordionHeader={<Typography.Headline3 flat>Where can I purchase a Hellhead?</Typography.Headline3>}
accordionContent={
<>
Expand Down

0 comments on commit 561a69e

Please sign in to comment.