diff --git a/src/components/Accordion/Accordion.jsx b/src/components/Accordion/Accordion.jsx new file mode 100644 index 000000000..6a5391ebe --- /dev/null +++ b/src/components/Accordion/Accordion.jsx @@ -0,0 +1,61 @@ +import { Disclosure } from "@headlessui/react"; +import clsx from "clsx"; +import React, { Children } from "react"; +import PropTypes from "prop-types"; +import { SlideDown } from "../Animation/SlideDown"; +import { ChevronRightIcon } from "../../icons/ChevronRightIcon"; + +export const Accordion = ({ children }) => { + const childrenArray = Children.toArray(children); + return ( + + {({ open }) => ( + <> + +
+ +
+ + {childrenArray.filter((child) => child?.type === Header)} +
+ + {childrenArray.filter((child) => child?.type === Body)} + + )} +
+ ); +}; + +const Header = ({ className, children, ...rest }) => { + return ( +
+ {children} +
+ ); +}; + +Accordion.Header = Header; + +const Body = ({ className, children, ...rest }) => { + return ( + + {children} + + ); +}; + +Accordion.Body = Body; + +Accordion.prototype = { + children: PropTypes.node, +}; + +Header.prototype = { + className: PropTypes.string, + children: PropTypes.node, +}; + +Body.prototype = { + className: PropTypes.string, + children: PropTypes.node, +}; diff --git a/src/index.js b/src/index.js index ba2df7c9d..d93c36fc4 100644 --- a/src/index.js +++ b/src/index.js @@ -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"; diff --git a/src/stories/DataDisplay/Accordion.stories.js b/src/stories/DataDisplay/Accordion.stories.js new file mode 100644 index 000000000..34722d080 --- /dev/null +++ b/src/stories/DataDisplay/Accordion.stories.js @@ -0,0 +1,63 @@ +import React from "react"; +import { Accordion } from "../../components/Accordion/Accordion"; + +const AccordionStories = { + title: "Data Display/Accordion", + component: Accordion, + parameters: { + docs: { + description: { + component: "Accordions are collapsible content UI element", + }, + } + }, + args: { + heading: "This is Accordion heading", + headingClass: "text-xl", + content: `Space, the final frontier. These are the voyages of the starship Enterprise. + Its five year mission: to explore strange new worlds, to seek out new life and + new civilizations, to boldly go where no man has gone before!`, + contentClass: "p1" + }, + argTypes: { + heading: { + type: { required: false }, + description: "This is accordion heading", + control: { type: "text" }, + }, + headingClass: { + type: { required: false }, + control: { type: "text" }, + table: { + type: { summary: "Classes for heading" }, + }, + }, + content: { + type: { required: false }, + description: "This is body content", + control: { type: "text" }, + }, + contentClass: { + type: { required: false }, + control: { type: "text" }, + table: { + type: { summary: "Classes for content"}, + }, + } + }, +}; + +export const Default = ({ children, heading, headingClass, content }) => { + return ( + + + { heading } + + + { content } + + + ) +}; + +export default AccordionStories; \ No newline at end of file