Use our AstroLaunch UI Accordion
component to allow the user to show and hide sections of related content on a page. There are many ways to use this component, like displaying a list of FAQs, showing various menus and submenus, displaying the locations of a particular company, and so on.
See below our simple and versatile Accordion
example that you can use in your React and AstroLaunch UI projects. We also included some Accordion
props that are available.
Preview
Code
You can make an Accordion
component to be always open and doesn't close when it's next or previous Accordion
component opened using a separate state.
Preview
Code
You can make the Accordion
component to be all open and doesn't close when it's next or previous Accordion
component opened using a separate state.
Preview
Code
You can modify the open/close state icon for Accordion
component using the icon
prop.
Preview
Code
You can modify the open/close state animation for Accordion
component using the animate
prop.
Preview
Code
You can use tailwind css classes to add custom styles to the Accordion
component.
Preview
Code
An Accordion
could be disabled as well, it will help you to prevent user interactions like click over the Accordion
component.
Preview
Code
The following props are available for accordion component. These are the custom props that we've added for the accordion component and you can use all the other native props as well.
Attribute | Type | Description | Default |
---|---|---|---|
open | boolean | Open accordion collapse | No default value it's a required prop. |
icon | node | Change accordion collapse end icon | undefined |
animate | Animate | Change accordion body animation | undefined |
disabled | boolean | Disable the accordion | false |
className | string | Add custom className for accordion | '' |
children | node | Add content for accordion | No default value it's a required prop. |
import type { AccordionProps } from "@material-tailwind/react";
The following props are available for accordion header component. These are the custom props that we've added for the accordion header component and you can use all the other native props as well.
Attribute | Type | Description | Default |
---|---|---|---|
className | string | Add custom className for accordion header | '' |
children | node | Add content for accordion header | No default value it's a required prop. |
import type { AccordionHeaderProps } from "@material-tailwind/react";
The following props are available for accordion body component. These are the custom props that we've added for the accordion body component and you can use all the other native props as well.
Attribute | Type | Description | Default |
---|---|---|---|
className | string | Add custom className for accordion body | '' |
children | node | Add content for accordion body | No default value it's a required prop. |
import type { AccordionBodyProps } from "@material-tailwind/react";
type animate = {
mount?: object;
unmount?: object;
};
Learn how to customize the theme and styles for accordion components, the theme object for accordion components has two main objects:
A. The defaultProps
object for setting up the default value for props of accordion components.
B. The styles
object for customizing the theme and styles of accordion components.
You can customize the theme and styles of accordion components by adding Tailwind CSS classes as key paired values for objects.
interface AccordionStylesType {
defaultProps: {
icon: node;
className: string;
animate: {
mount: object;
unmount: object;
};
disabled: boolean;
};
styles: {
base: {
container: object;
header: {
initial: object;
active: object;
icon: object;
};
body: object;
disabled: object;
};
};
}
import type { AccordionStylesType } from "@material-tailwind/react";
const theme = {
accordion: {
defaultProps: {
icon: undefined,
className: "",
animate: {
unmount: {},
mount: {},
},
disabled: false,
},
styles: {
base: {
container: {
display: "block",
position: "relative",
width: "w-full",
},
header: {
initial: {
display: "flex",
justifyContent: "justify-between",
alignItems: "items-center",
width: "w-full",
py: "py-4",
borderWidth: "border-b border-b-blue-gray-100",
color: "text-blue-gray-700",
fontSmoothing: "antialiased",
fontFamily: "font-sans",
fontSize: "text-xl",
textAlign: "text-left",
fontWeight: "font-semibold",
lineHeight: "leading-snug",
userSelect: "select-none",
hover: "hover:text-blue-gray-900",
transition: "transition-colors",
},
active: { color: "text-blue-gray-900" },
icon: {
ml: "ml-4",
},
},
body: {
display: "block",
width: "w-full",
py: "py-4",
color: "text-gray-700",
fontSmoothing: "antialiased",
fontFamily: "font-sans",
fontSize: "text-sm",
fontWeight: "font-light",
lineHeight: "leading-normal",
},
disabled: {
pointerEvents: "pointer-events-none",
opacity: "opacity-50",
},
},
},
},
};
If you want to see more examples and properties please check the official Material Tailwind Documentation.