react-image-accordion
v1.2.2
Published
Accordion component for React
Downloads
53
Maintainers
Readme
React Image Accordion
A simple and customizable React component that creates an image accordion with smooth animation, inspired by Kevin Powell's tutorial on YouTube.
The image accordion is a modern design pattern that can be used to display images and accompanying information in an interactive and engaging way. This component makes it easy to incorporate this pattern into your React projects.
Installation
Use the package manager npm to install react-image-accordion.
npm i react-image-accordion
Usage
To use the component in your React application, import it and pass the necessary props:
import {ReactImageAccordion} from 'react-image-accordion';
function MyComponent() {
const accordionData = [
{
id: 1,
title: "Boating",
image: "https://picsum.photos/400/600",
alt: "first panel image",
content: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
svg: "aa (1).svg",
},
{
id: 2,
title: "Fishing",
image: "https://picsum.photos/400/600",
alt: "second panel image",
content: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
svg: "aa (2).svg",
},
{
id: 3,
title: "Swimming",
image: "https://picsum.photos/400/600",
alt: "third panel image",
content: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
svg: "aa (3).svg",
},
{
id: 4,
title: "Kayaking",
image: "https://picsum.photos/400/600",
alt: "fourth panel image",
content: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
svg: "aa (4).svg",
},
{
id: 5,
title: "Scuba diving",
image: "https://picsum.photos/400/600",
alt: "fifth panel image",
content: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
svg: "aa (5).svg",
},
];
return (
<ReactImageAccordion
accordionData={accordionData}
AccordionWidth={AccordionWidth}
AccordionHeight={AccordionHeight}
ContentSize=[ContentSize]
onClick={}
ShowButton={true/false}
/>
);
}
| Property | type | Default | Description | | ---------------- |:-------------:|:----------:|:-----------------------:| | accordionData | json data | json file | Source File json | | AccordionWidth | css /optional| 50rem | Accordion Width | | AccordionHeight | css /optional| 30rem | Accordion Height | | ContentSize |Array /optional|[0,1,2,3,4]*| Content font size | | onClick | onCLick | | onClick ATC event | | ShowButton | boolean | false | show or hid button |
*[0,1,2,3,4]
"@media (max-width: 480px)": {
fontSize: ContentSize[0] || "0.65rem",
},
"@media (min-width: 481px) and (max-width: 768px)": {
fontSize: ContentSize[1] || "0.8rem",
},
"@media (min-width: 769px) and (max-width: 1024px)": {
fontSize: ContentSize[2] || "1rem",
},
"@media (min-width: 1025px) and (max-width: 1200px)": {
fontSize: ContentSize[3] || "1.2rem",
},
"@media (min-width: 1201px)": {
fontSize: ContentSize[4] || "1.5rem",
},
Sample Code
import MockDocument from "./MOCK_DATA.json";
import { ReactImageAccordion } from "json-pretty-textarea";
export const test = () => {
return (
<ReactImageAccordion
accordionData= {MockAccordion}
AccordionWidth= "40rem"
AccordionHeight= "30rem"
ContentSize={[".5rem", ".5rem", ".6rem", ".7rem", "1.1rem"]}
ShowButton= {false},
onClick= {(e) => console.log(e.id, e.title)},
/>
);
};
StoryBook Sample
[StoryBook]https://react-image-accordion.netlify.app/
Contributing
For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.