Skip to content
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

Added accordion component to ui kit #293

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
48 changes: 48 additions & 0 deletions src/components/Accordion/Accordion.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Disclosure } from "@headlessui/react";
import clsx from "clsx";
import React, { Children } from "react";
import { SlideDown } from "../Animation/SlideDown";
import { ChevronRightIcon } from "../../icons/ChevronRightIcon";

export const Accordion = ({ children }) => {
const childrenArray = Children.toArray(children);
return (
<div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disclosure itself should have a div. Remove this div if you don't need it. Simplifies the markup, and if the end-user (seller app, admin etc) need an extra div, they can add it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

<Disclosure>
{({ open }) => (
<>
<Disclosure.Button className="flex items-center">
<div className="mr-2" data-testid="accordion-dropdown-icon">
<ChevronRightIcon className={clsx(open && "rotate-90")} />
</div>

{childrenArray.filter((child) => child?.type === Header)}
</Disclosure.Button>

<SlideDown isOpen={open}>{childrenArray.filter((child) => child?.type === Body)}</SlideDown>
</>
)}
</Disclosure>
</div>
);
};

const Header = ({ className, children, ...rest }) => {
return (
<div className={clsx("flex items-center space-x-3", className)} {...rest}>
{children}
</div>
);
};

Accordion.Header = Header;

const Body = ({ className, children, ...rest }) => {
return (
<Disclosure.Panel as="div" className={clsx("p-2 pb-10", className)} {...rest}>
{children}
</Disclosure.Panel>
);
};

Accordion.Body = Body;
rushi marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export { RelativeDateRange } from "./components/DatePicker/RelativeDateRange";
export { DatePickerPopover } from "./components/DatePicker/DatePickerPopover";
export { InlineValuePopover } from "./components/Forms/InlineValuePopover";
export { ImageUpload } from "./components/ImageUpload";
export { Accordion } from "./components/Accordion/Accordion";

// Utilities
export { Currency } from "./components/Utilities/Currency";
Expand Down
Loading