react-image-accordion 1.0.9 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.storybook/preview.js +8 -8
- package/LICENSE +21 -21
- package/README.md +124 -120
- package/dist/index.es.js +18 -6
- package/dist/index.js +18 -6
- package/package.json +2 -1
- package/rollup.config.js +38 -38
- package/src/components/Accordion/App.css +187 -187
- package/src/components/Accordion/React-image-accordion.js +16 -7
- package/src/components/Accordion/UseImageAccordion.js +69 -69
- package/src/components/Accordion/index.js +2 -2
- package/src/index.js +2 -2
- package/src/stories/MockAccordion.json +42 -42
- package/src/stories/UseImageAccordion.stories.js +17 -15
package/.storybook/preview.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export const parameters = {
|
|
2
|
-
actions: { argTypesRegex: "^on[A-Z].*" },
|
|
3
|
-
controls: {
|
|
4
|
-
matchers: {
|
|
5
|
-
color: /(background|color)$/i,
|
|
6
|
-
date: /Date$/,
|
|
7
|
-
},
|
|
8
|
-
},
|
|
1
|
+
export const parameters = {
|
|
2
|
+
actions: { argTypesRegex: "^on[A-Z].*" },
|
|
3
|
+
controls: {
|
|
4
|
+
matchers: {
|
|
5
|
+
color: /(background|color)$/i,
|
|
6
|
+
date: /Date$/,
|
|
7
|
+
},
|
|
8
|
+
},
|
|
9
9
|
}
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022 Masoud Naji
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Masoud Naji
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,120 +1,124 @@
|
|
|
1
|
-
# React Image Accordion
|
|
2
|
-
|
|
3
|
-
A simple and customizable React component that creates an image accordion with smooth animation, inspired by Kevin Powell's tutorial on [YouTube](https://www.youtube.com/watch?v=WJERnXiFFug&t=0s&ab_channel=KevinPowell).
|
|
4
|
-
|
|
5
|
-
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.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
## Installation
|
|
9
|
-
|
|
10
|
-
Use the package manager [npm](https://www.npmjs.com/) to install react-image-accordion.
|
|
11
|
-
|
|
12
|
-
```bash
|
|
13
|
-
npm i react-image-accordion
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
## Usage
|
|
20
|
-
|
|
21
|
-
To use the component in your React application, import it and pass the necessary props:
|
|
22
|
-
|
|
23
|
-
```jsx
|
|
24
|
-
import ReactImageAccordion from 'react-image-accordion';
|
|
25
|
-
|
|
26
|
-
function MyComponent() {
|
|
27
|
-
const accordionData = [
|
|
28
|
-
{
|
|
29
|
-
id: 1,
|
|
30
|
-
title: "Boating",
|
|
31
|
-
image: "https://picsum.photos/400/600",
|
|
32
|
-
alt: "first panel image",
|
|
33
|
-
content: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
|
|
34
|
-
svg: "aa (1).svg",
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
id: 2,
|
|
38
|
-
title: "Fishing",
|
|
39
|
-
image: "https://picsum.photos/400/600",
|
|
40
|
-
alt: "second panel image",
|
|
41
|
-
content: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
|
|
42
|
-
svg: "aa (2).svg",
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
id: 3,
|
|
46
|
-
title: "Swimming",
|
|
47
|
-
image: "https://picsum.photos/400/600",
|
|
48
|
-
alt: "third panel image",
|
|
49
|
-
content: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
|
|
50
|
-
svg: "aa (3).svg",
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
id: 4,
|
|
54
|
-
title: "Kayaking",
|
|
55
|
-
image: "https://picsum.photos/400/600",
|
|
56
|
-
alt: "fourth panel image",
|
|
57
|
-
content: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
|
|
58
|
-
svg: "aa (4).svg",
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
id: 5,
|
|
62
|
-
title: "Scuba diving",
|
|
63
|
-
image: "https://picsum.photos/400/600",
|
|
64
|
-
alt: "fifth panel image",
|
|
65
|
-
content: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
|
|
66
|
-
svg: "aa (5).svg",
|
|
67
|
-
},
|
|
68
|
-
];
|
|
69
|
-
|
|
70
|
-
return (
|
|
71
|
-
<ReactImageAccordion
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
##
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
1
|
+
# React Image Accordion
|
|
2
|
+
|
|
3
|
+
A simple and customizable React component that creates an image accordion with smooth animation, inspired by Kevin Powell's tutorial on [YouTube](https://www.youtube.com/watch?v=WJERnXiFFug&t=0s&ab_channel=KevinPowell).
|
|
4
|
+
|
|
5
|
+
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.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
Use the package manager [npm](https://www.npmjs.com/) to install react-image-accordion.
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm i react-image-accordion
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
To use the component in your React application, import it and pass the necessary props:
|
|
22
|
+
|
|
23
|
+
```jsx
|
|
24
|
+
import {ReactImageAccordion} from 'react-image-accordion';
|
|
25
|
+
|
|
26
|
+
function MyComponent() {
|
|
27
|
+
const accordionData = [
|
|
28
|
+
{
|
|
29
|
+
id: 1,
|
|
30
|
+
title: "Boating",
|
|
31
|
+
image: "https://picsum.photos/400/600",
|
|
32
|
+
alt: "first panel image",
|
|
33
|
+
content: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
|
|
34
|
+
svg: "aa (1).svg",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: 2,
|
|
38
|
+
title: "Fishing",
|
|
39
|
+
image: "https://picsum.photos/400/600",
|
|
40
|
+
alt: "second panel image",
|
|
41
|
+
content: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
|
|
42
|
+
svg: "aa (2).svg",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: 3,
|
|
46
|
+
title: "Swimming",
|
|
47
|
+
image: "https://picsum.photos/400/600",
|
|
48
|
+
alt: "third panel image",
|
|
49
|
+
content: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
|
|
50
|
+
svg: "aa (3).svg",
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: 4,
|
|
54
|
+
title: "Kayaking",
|
|
55
|
+
image: "https://picsum.photos/400/600",
|
|
56
|
+
alt: "fourth panel image",
|
|
57
|
+
content: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
|
|
58
|
+
svg: "aa (4).svg",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: 5,
|
|
62
|
+
title: "Scuba diving",
|
|
63
|
+
image: "https://picsum.photos/400/600",
|
|
64
|
+
alt: "fifth panel image",
|
|
65
|
+
content: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
|
|
66
|
+
svg: "aa (5).svg",
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<ReactImageAccordion
|
|
72
|
+
accordionData={accordionData}
|
|
73
|
+
AccordionWidth={AccordionWidth}
|
|
74
|
+
AccordionHeight={AccordionHeight}
|
|
75
|
+
/>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+

|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+

|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
| Property | type | Default | Description |
|
|
90
|
+
| ---------------- |:-------------:|:----------:|:-----------------------:|
|
|
91
|
+
| accordionData | json data | json file | Source File json |
|
|
92
|
+
| AccordionWidth | css | 50rem | Accordion Width |
|
|
93
|
+
| AccordionHeight | css | 30rem | Accordion Height |
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
## Sample Code
|
|
97
|
+
```React Code
|
|
98
|
+
import MockDocument from "./MOCK_DATA.json";
|
|
99
|
+
import { ReactImageAccordion } from "json-pretty-textarea";
|
|
100
|
+
export const test = () => {
|
|
101
|
+
return (
|
|
102
|
+
<ReactImageAccordion
|
|
103
|
+
accordionData= {MockAccordion}
|
|
104
|
+
AccordionWidth= "40rem",
|
|
105
|
+
AccordionHeight= "30rem",
|
|
106
|
+
/>
|
|
107
|
+
);
|
|
108
|
+
};
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
***
|
|
113
|
+
## StoryBook Sample
|
|
114
|
+
[StoryBook]https://react-image-accordion.netlify.app/
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
## Contributing
|
|
118
|
+
For major changes, please open an issue first to discuss what you would like to change.
|
|
119
|
+
|
|
120
|
+
Please make sure to update tests as appropriate.
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
## License
|
|
124
|
+
[MIT](https://choosealicense.com/licenses/mit/)
|
package/dist/index.es.js
CHANGED
|
@@ -27,11 +27,13 @@ function styleInject(css, ref) {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
var css_248z = "*,\
|
|
30
|
+
var css_248z = "*,\n*::before,\n*::after {\n box-sizing: border-box;\n}\n\nhtml {\n color-scheme: dark;\n}\n\nbody {\n display: grid;\n justify-content: center;\n align-content: center;\n min-height: 100vh;\n\n margin: 0;\n font-family: system-ui;\n font-size: 1.125rem;\n line-height: 1.6;\n}\n\nimg {\n max-width: 100%;\n display: block;\n}\n\n.wrapper {\n /* max-width: 50rem; */\n margin-inline: auto;\n padding-inline: 1rem;\n}\n\n.accordion {\n --_button-size: 3rem;\n --_panel-padding: 0.75rem;\n --_panel-gap: 1rem;\n\n display: flex;\n flex-direction: column;\n gap: 1rem;\n}\n\n@media (min-width: 45em) {\n .accordion {\n flex-direction: row;\n /* height: 30rem; */\n }\n}\n\n.accordion * {\n margin: 0;\n}\n\n.accordion-panel {\n position: relative;\n isolation: isolate;\n flex-basis: calc((var(--_panel-padding) * 2) + var(--_button-size));\n overflow: hidden;\n padding: var(--_panel-padding);\n padding-right: calc(var(--_panel-padding) * 4);\n border-radius: calc(((var(--_panel-padding) * 2) + var(--_button-size)) / 2);\n cursor: pointer;\n}\n\n@media (prefers-reduced-motion: no-preference) {\n .accordion-panel {\n transition: flex-basis 500ms, flex-grow 500ms;\n }\n}\n\n.accordion-panel:nth-child(1) {\n --_panel-color: red;\n}\n.accordion-panel:nth-child(2) {\n --_panel-color: blue;\n}\n.accordion-panel:nth-child(3) {\n --_panel-color: green;\n}\n.accordion-panel:nth-child(4) {\n --_panel-color: yellow;\n}\n.accordion-panel:nth-child(5) {\n --_panel-color: orange;\n}\n.accordion-panel:nth-child(6) {\n --_panel-color: purple;\n}\n.accordion-panel:nth-child(7) {\n --_panel-color: pink;\n}\n.accordion-panel:nth-child(8) {\n --_panel-color: brown;\n}\n.accordion-panel:nth-child(9) {\n --_panel-color: cyan;\n}\n.accordion-panel:nth-child(10) {\n --_panel-color: magenta;\n}\n\n.accordion-panel:has([aria-expanded=\"true\"]) {\n flex-basis: clamp(15rem, 40vh, 20rem);\n flex-grow: 1;\n}\n\n.accordion-trigger {\n outline: 0 !important;\n}\n\n.accordion-panel:focus-within {\n outline: 3px solid var(--_panel-color);\n outline-offset: 4px;\n}\n\n.accordion-content > p {\n transform: translateY(2rem);\n opacity: 0;\n margin-left: calc(var(--_button-size) + var(--_panel-gap));\n}\n\n@media (prefers-reduced-motion: no-preference) {\n .accordion-panel:has([aria-expanded=\"true\"]) .accordion-content > p {\n transition: transform 500ms 500ms, opacity 500ms 500ms;\n }\n}\n\n.accordion-panel:has([aria-expanded=\"true\"]) .accordion-content > p {\n transform: translateY(0);\n opacity: 1;\n}\n\n.accordion-title {\n font-size: 1.5rem;\n font-weight: 700;\n position: relative;\n isolation: isolate;\n display: grid;\n align-items: center;\n}\n\n@media (max-width: 44.999em) {\n .accordion-title::after {\n content: \"\";\n position: absolute;\n\n left: calc((var(--_panel-gap) + var(--_button-size)) * -1);\n width: calc(100% + (var(--_button-size) * 2));\n height: var(--_button-size);\n background: hsl(0 0% 0% /0.55);\n z-index: -1;\n border-radius: 100vw;\n }\n}\n\n.accordion-image {\n position: absolute;\n inset: 0;\n width: 100%;\n height: 100%;\n object-fit: cover;\n z-index: -1;\n transition: filer 500ms;\n}\n\n.accordion-panel:has([aria-expanded=\"true\"]) .accordion-image {\n filter: brightness(0.5);\n}\n.accordion-trigger {\n display: flex;\n align-items: center;\n flex-direction: row-reverse;\n gap: var(--_panel-gap);\n background: transparent;\n border: 0;\n padding: 0;\n}\n.accordion-icon {\n fill: var(--_panel-color);\n background: hsl(0 0% 0% /0.55);\n width: var(--_button-size);\n aspect-ratio: 1/1;\n padding: 0.75rem;\n border-radius: 50%;\n z-index: 10;\n}\n";
|
|
31
31
|
styleInject(css_248z);
|
|
32
32
|
|
|
33
33
|
function UseImageAccordion({
|
|
34
|
-
accordionData
|
|
34
|
+
accordionData,
|
|
35
|
+
AccordionWidth,
|
|
36
|
+
AccordionHeight
|
|
35
37
|
}) {
|
|
36
38
|
const [activePanel, setActivePanel] = useState(null);
|
|
37
39
|
function toggleAccordion(panelToActivate) {
|
|
@@ -48,9 +50,15 @@ function UseImageAccordion({
|
|
|
48
50
|
}, []);
|
|
49
51
|
if (!accordionData) return null;
|
|
50
52
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
51
|
-
className: "wrapper"
|
|
53
|
+
className: "wrapper",
|
|
54
|
+
style: {
|
|
55
|
+
width: AccordionWidth
|
|
56
|
+
}
|
|
52
57
|
}, /*#__PURE__*/React.createElement("div", {
|
|
53
|
-
className: "accordion"
|
|
58
|
+
className: "accordion",
|
|
59
|
+
style: {
|
|
60
|
+
height: AccordionHeight
|
|
61
|
+
}
|
|
54
62
|
}, accordionData.map(item => /*#__PURE__*/React.createElement("div", {
|
|
55
63
|
key: item.id,
|
|
56
64
|
className: "accordion-panel",
|
|
@@ -84,10 +92,14 @@ function UseImageAccordion({
|
|
|
84
92
|
}
|
|
85
93
|
|
|
86
94
|
const ReactImageAccordion = ({
|
|
87
|
-
accordionData
|
|
95
|
+
accordionData,
|
|
96
|
+
AccordionWidth,
|
|
97
|
+
AccordionHeight
|
|
88
98
|
}) => {
|
|
89
99
|
return /*#__PURE__*/React.createElement(UseImageAccordion, {
|
|
90
|
-
accordionData: accordionData
|
|
100
|
+
accordionData: accordionData,
|
|
101
|
+
AccordionWidth: AccordionWidth,
|
|
102
|
+
AccordionHeight: AccordionHeight
|
|
91
103
|
});
|
|
92
104
|
};
|
|
93
105
|
|
package/dist/index.js
CHANGED
|
@@ -35,11 +35,13 @@ function styleInject(css, ref) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
var css_248z = "*,\
|
|
38
|
+
var css_248z = "*,\n*::before,\n*::after {\n box-sizing: border-box;\n}\n\nhtml {\n color-scheme: dark;\n}\n\nbody {\n display: grid;\n justify-content: center;\n align-content: center;\n min-height: 100vh;\n\n margin: 0;\n font-family: system-ui;\n font-size: 1.125rem;\n line-height: 1.6;\n}\n\nimg {\n max-width: 100%;\n display: block;\n}\n\n.wrapper {\n /* max-width: 50rem; */\n margin-inline: auto;\n padding-inline: 1rem;\n}\n\n.accordion {\n --_button-size: 3rem;\n --_panel-padding: 0.75rem;\n --_panel-gap: 1rem;\n\n display: flex;\n flex-direction: column;\n gap: 1rem;\n}\n\n@media (min-width: 45em) {\n .accordion {\n flex-direction: row;\n /* height: 30rem; */\n }\n}\n\n.accordion * {\n margin: 0;\n}\n\n.accordion-panel {\n position: relative;\n isolation: isolate;\n flex-basis: calc((var(--_panel-padding) * 2) + var(--_button-size));\n overflow: hidden;\n padding: var(--_panel-padding);\n padding-right: calc(var(--_panel-padding) * 4);\n border-radius: calc(((var(--_panel-padding) * 2) + var(--_button-size)) / 2);\n cursor: pointer;\n}\n\n@media (prefers-reduced-motion: no-preference) {\n .accordion-panel {\n transition: flex-basis 500ms, flex-grow 500ms;\n }\n}\n\n.accordion-panel:nth-child(1) {\n --_panel-color: red;\n}\n.accordion-panel:nth-child(2) {\n --_panel-color: blue;\n}\n.accordion-panel:nth-child(3) {\n --_panel-color: green;\n}\n.accordion-panel:nth-child(4) {\n --_panel-color: yellow;\n}\n.accordion-panel:nth-child(5) {\n --_panel-color: orange;\n}\n.accordion-panel:nth-child(6) {\n --_panel-color: purple;\n}\n.accordion-panel:nth-child(7) {\n --_panel-color: pink;\n}\n.accordion-panel:nth-child(8) {\n --_panel-color: brown;\n}\n.accordion-panel:nth-child(9) {\n --_panel-color: cyan;\n}\n.accordion-panel:nth-child(10) {\n --_panel-color: magenta;\n}\n\n.accordion-panel:has([aria-expanded=\"true\"]) {\n flex-basis: clamp(15rem, 40vh, 20rem);\n flex-grow: 1;\n}\n\n.accordion-trigger {\n outline: 0 !important;\n}\n\n.accordion-panel:focus-within {\n outline: 3px solid var(--_panel-color);\n outline-offset: 4px;\n}\n\n.accordion-content > p {\n transform: translateY(2rem);\n opacity: 0;\n margin-left: calc(var(--_button-size) + var(--_panel-gap));\n}\n\n@media (prefers-reduced-motion: no-preference) {\n .accordion-panel:has([aria-expanded=\"true\"]) .accordion-content > p {\n transition: transform 500ms 500ms, opacity 500ms 500ms;\n }\n}\n\n.accordion-panel:has([aria-expanded=\"true\"]) .accordion-content > p {\n transform: translateY(0);\n opacity: 1;\n}\n\n.accordion-title {\n font-size: 1.5rem;\n font-weight: 700;\n position: relative;\n isolation: isolate;\n display: grid;\n align-items: center;\n}\n\n@media (max-width: 44.999em) {\n .accordion-title::after {\n content: \"\";\n position: absolute;\n\n left: calc((var(--_panel-gap) + var(--_button-size)) * -1);\n width: calc(100% + (var(--_button-size) * 2));\n height: var(--_button-size);\n background: hsl(0 0% 0% /0.55);\n z-index: -1;\n border-radius: 100vw;\n }\n}\n\n.accordion-image {\n position: absolute;\n inset: 0;\n width: 100%;\n height: 100%;\n object-fit: cover;\n z-index: -1;\n transition: filer 500ms;\n}\n\n.accordion-panel:has([aria-expanded=\"true\"]) .accordion-image {\n filter: brightness(0.5);\n}\n.accordion-trigger {\n display: flex;\n align-items: center;\n flex-direction: row-reverse;\n gap: var(--_panel-gap);\n background: transparent;\n border: 0;\n padding: 0;\n}\n.accordion-icon {\n fill: var(--_panel-color);\n background: hsl(0 0% 0% /0.55);\n width: var(--_button-size);\n aspect-ratio: 1/1;\n padding: 0.75rem;\n border-radius: 50%;\n z-index: 10;\n}\n";
|
|
39
39
|
styleInject(css_248z);
|
|
40
40
|
|
|
41
41
|
function UseImageAccordion({
|
|
42
|
-
accordionData
|
|
42
|
+
accordionData,
|
|
43
|
+
AccordionWidth,
|
|
44
|
+
AccordionHeight
|
|
43
45
|
}) {
|
|
44
46
|
const [activePanel, setActivePanel] = React.useState(null);
|
|
45
47
|
function toggleAccordion(panelToActivate) {
|
|
@@ -56,9 +58,15 @@ function UseImageAccordion({
|
|
|
56
58
|
}, []);
|
|
57
59
|
if (!accordionData) return null;
|
|
58
60
|
return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
59
|
-
className: "wrapper"
|
|
61
|
+
className: "wrapper",
|
|
62
|
+
style: {
|
|
63
|
+
width: AccordionWidth
|
|
64
|
+
}
|
|
60
65
|
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
61
|
-
className: "accordion"
|
|
66
|
+
className: "accordion",
|
|
67
|
+
style: {
|
|
68
|
+
height: AccordionHeight
|
|
69
|
+
}
|
|
62
70
|
}, accordionData.map(item => /*#__PURE__*/React__default["default"].createElement("div", {
|
|
63
71
|
key: item.id,
|
|
64
72
|
className: "accordion-panel",
|
|
@@ -92,10 +100,14 @@ function UseImageAccordion({
|
|
|
92
100
|
}
|
|
93
101
|
|
|
94
102
|
const ReactImageAccordion = ({
|
|
95
|
-
accordionData
|
|
103
|
+
accordionData,
|
|
104
|
+
AccordionWidth,
|
|
105
|
+
AccordionHeight
|
|
96
106
|
}) => {
|
|
97
107
|
return /*#__PURE__*/React__default["default"].createElement(UseImageAccordion, {
|
|
98
|
-
accordionData: accordionData
|
|
108
|
+
accordionData: accordionData,
|
|
109
|
+
AccordionWidth: AccordionWidth,
|
|
110
|
+
AccordionHeight: AccordionHeight
|
|
99
111
|
});
|
|
100
112
|
};
|
|
101
113
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-image-accordion",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Accordion component for React",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.es.js",
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"react-dom": "^18.1.0"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
+
"@rollup/plugin-terser": "^0.4.1",
|
|
60
61
|
"react-image-accordion": "^1.0.8",
|
|
61
62
|
"rollup-plugin-local-resolve": "^1.0.7",
|
|
62
63
|
"rollup-plugin-terser": "^7.0.2"
|
package/rollup.config.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import babel from 'rollup-plugin-babel';
|
|
2
|
-
import resolve from '@rollup/plugin-node-resolve';
|
|
3
|
-
import external from 'rollup-plugin-peer-deps-external';
|
|
4
|
-
import postcss from 'rollup-plugin-postcss';
|
|
5
|
-
import localResolve from 'rollup-plugin-local-resolve';
|
|
6
|
-
// import { terser } from "rollup-plugin-terser";
|
|
7
|
-
|
|
8
|
-
export default [
|
|
9
|
-
{
|
|
10
|
-
input: 'src/index.js',
|
|
11
|
-
output: [
|
|
12
|
-
{
|
|
13
|
-
file: 'dist/index.js',
|
|
14
|
-
format: 'cjs',
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
file: 'dist/index.es.js',
|
|
18
|
-
format: 'es',
|
|
19
|
-
exports: 'named',
|
|
20
|
-
},
|
|
21
|
-
],
|
|
22
|
-
plugins: [
|
|
23
|
-
postcss({
|
|
24
|
-
plugins: []
|
|
25
|
-
}),
|
|
26
|
-
babel({
|
|
27
|
-
exclude: 'node_modules/**',
|
|
28
|
-
presets: ['@babel/preset-react'],
|
|
29
|
-
}),
|
|
30
|
-
external(),
|
|
31
|
-
resolve(),
|
|
32
|
-
localResolve(),
|
|
33
|
-
// terser(),
|
|
34
|
-
],
|
|
35
|
-
watch: {
|
|
36
|
-
include: "src/**",
|
|
37
|
-
},
|
|
38
|
-
}
|
|
1
|
+
import babel from 'rollup-plugin-babel';
|
|
2
|
+
import resolve from '@rollup/plugin-node-resolve';
|
|
3
|
+
import external from 'rollup-plugin-peer-deps-external';
|
|
4
|
+
import postcss from 'rollup-plugin-postcss';
|
|
5
|
+
import localResolve from 'rollup-plugin-local-resolve';
|
|
6
|
+
// import { terser } from "rollup-plugin-terser";
|
|
7
|
+
|
|
8
|
+
export default [
|
|
9
|
+
{
|
|
10
|
+
input: 'src/index.js',
|
|
11
|
+
output: [
|
|
12
|
+
{
|
|
13
|
+
file: 'dist/index.js',
|
|
14
|
+
format: 'cjs',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
file: 'dist/index.es.js',
|
|
18
|
+
format: 'es',
|
|
19
|
+
exports: 'named',
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
plugins: [
|
|
23
|
+
postcss({
|
|
24
|
+
plugins: []
|
|
25
|
+
}),
|
|
26
|
+
babel({
|
|
27
|
+
exclude: 'node_modules/**',
|
|
28
|
+
presets: ['@babel/preset-react'],
|
|
29
|
+
}),
|
|
30
|
+
external(),
|
|
31
|
+
resolve(),
|
|
32
|
+
localResolve(),
|
|
33
|
+
// terser(),
|
|
34
|
+
],
|
|
35
|
+
watch: {
|
|
36
|
+
include: "src/**",
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
39
|
];
|
|
@@ -1,187 +1,187 @@
|
|
|
1
|
-
*,
|
|
2
|
-
*::before,
|
|
3
|
-
*::after {
|
|
4
|
-
box-sizing: border-box;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
html {
|
|
8
|
-
color-scheme: dark;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
body {
|
|
12
|
-
display: grid;
|
|
13
|
-
justify-content: center;
|
|
14
|
-
align-content: center;
|
|
15
|
-
min-height: 100vh;
|
|
16
|
-
|
|
17
|
-
margin: 0;
|
|
18
|
-
font-family: system-ui;
|
|
19
|
-
font-size: 1.125rem;
|
|
20
|
-
line-height: 1.6;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
img {
|
|
24
|
-
max-width: 100%;
|
|
25
|
-
display: block;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
.wrapper {
|
|
29
|
-
max-width: 50rem;
|
|
30
|
-
margin-inline: auto;
|
|
31
|
-
padding-inline: 1rem;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
.accordion {
|
|
35
|
-
--_button-size: 3rem;
|
|
36
|
-
--_panel-padding: 0.75rem;
|
|
37
|
-
--_panel-gap: 1rem;
|
|
38
|
-
|
|
39
|
-
display: flex;
|
|
40
|
-
flex-direction: column;
|
|
41
|
-
gap: 1rem;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
@media (min-width: 45em) {
|
|
45
|
-
.accordion {
|
|
46
|
-
flex-direction: row;
|
|
47
|
-
height: 30rem;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
.accordion * {
|
|
52
|
-
margin: 0;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
.accordion-panel {
|
|
56
|
-
position: relative;
|
|
57
|
-
isolation: isolate;
|
|
58
|
-
flex-basis: calc((var(--_panel-padding) * 2) + var(--_button-size));
|
|
59
|
-
overflow: hidden;
|
|
60
|
-
padding: var(--_panel-padding);
|
|
61
|
-
padding-right: calc(var(--_panel-padding) * 4);
|
|
62
|
-
border-radius: calc(((var(--_panel-padding) * 2) + var(--_button-size)) / 2);
|
|
63
|
-
cursor: pointer;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
@media (prefers-reduced-motion: no-preference) {
|
|
67
|
-
.accordion-panel {
|
|
68
|
-
transition: flex-basis 500ms, flex-grow 500ms;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
.accordion-panel:nth-child(1) {
|
|
73
|
-
--_panel-color: red;
|
|
74
|
-
}
|
|
75
|
-
.accordion-panel:nth-child(2) {
|
|
76
|
-
--_panel-color: blue;
|
|
77
|
-
}
|
|
78
|
-
.accordion-panel:nth-child(3) {
|
|
79
|
-
--_panel-color: green;
|
|
80
|
-
}
|
|
81
|
-
.accordion-panel:nth-child(4) {
|
|
82
|
-
--_panel-color: yellow;
|
|
83
|
-
}
|
|
84
|
-
.accordion-panel:nth-child(5) {
|
|
85
|
-
--_panel-color: orange;
|
|
86
|
-
}
|
|
87
|
-
.accordion-panel:nth-child(6) {
|
|
88
|
-
--_panel-color: purple;
|
|
89
|
-
}
|
|
90
|
-
.accordion-panel:nth-child(7) {
|
|
91
|
-
--_panel-color: pink;
|
|
92
|
-
}
|
|
93
|
-
.accordion-panel:nth-child(8) {
|
|
94
|
-
--_panel-color: brown;
|
|
95
|
-
}
|
|
96
|
-
.accordion-panel:nth-child(9) {
|
|
97
|
-
--_panel-color: cyan;
|
|
98
|
-
}
|
|
99
|
-
.accordion-panel:nth-child(10) {
|
|
100
|
-
--_panel-color: magenta;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
.accordion-panel:has([aria-expanded="true"]) {
|
|
104
|
-
flex-basis: clamp(15rem, 40vh, 20rem);
|
|
105
|
-
flex-grow: 1;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
.accordion-trigger {
|
|
109
|
-
outline: 0 !important;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
.accordion-panel:focus-within {
|
|
113
|
-
outline: 3px solid var(--_panel-color);
|
|
114
|
-
outline-offset: 4px;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
.accordion-content > p {
|
|
118
|
-
transform: translateY(2rem);
|
|
119
|
-
opacity: 0;
|
|
120
|
-
margin-left: calc(var(--_button-size) + var(--_panel-gap));
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
@media (prefers-reduced-motion: no-preference) {
|
|
124
|
-
.accordion-panel:has([aria-expanded="true"]) .accordion-content > p {
|
|
125
|
-
transition: transform 500ms 500ms, opacity 500ms 500ms;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
.accordion-panel:has([aria-expanded="true"]) .accordion-content > p {
|
|
130
|
-
transform: translateY(0);
|
|
131
|
-
opacity: 1;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
.accordion-title {
|
|
135
|
-
font-size: 1.5rem;
|
|
136
|
-
font-weight: 700;
|
|
137
|
-
position: relative;
|
|
138
|
-
isolation: isolate;
|
|
139
|
-
display: grid;
|
|
140
|
-
align-items: center;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
@media (max-width: 44.999em) {
|
|
144
|
-
.accordion-title::after {
|
|
145
|
-
content: "";
|
|
146
|
-
position: absolute;
|
|
147
|
-
|
|
148
|
-
left: calc((var(--_panel-gap) + var(--_button-size)) * -1);
|
|
149
|
-
width: calc(100% + (var(--_button-size) * 2));
|
|
150
|
-
height: var(--_button-size);
|
|
151
|
-
background: hsl(0 0% 0% /0.55);
|
|
152
|
-
z-index: -1;
|
|
153
|
-
border-radius: 100vw;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
.accordion-image {
|
|
158
|
-
position: absolute;
|
|
159
|
-
inset: 0;
|
|
160
|
-
width: 100%;
|
|
161
|
-
height: 100%;
|
|
162
|
-
object-fit: cover;
|
|
163
|
-
z-index: -1;
|
|
164
|
-
transition: filer 500ms;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
.accordion-panel:has([aria-expanded="true"]) .accordion-image {
|
|
168
|
-
filter: brightness(0.5);
|
|
169
|
-
}
|
|
170
|
-
.accordion-trigger {
|
|
171
|
-
display: flex;
|
|
172
|
-
align-items: center;
|
|
173
|
-
flex-direction: row-reverse;
|
|
174
|
-
gap: var(--_panel-gap);
|
|
175
|
-
background: transparent;
|
|
176
|
-
border: 0;
|
|
177
|
-
padding: 0;
|
|
178
|
-
}
|
|
179
|
-
.accordion-icon {
|
|
180
|
-
fill: var(--_panel-color);
|
|
181
|
-
background: hsl(0 0% 0% /0.55);
|
|
182
|
-
width: var(--_button-size);
|
|
183
|
-
aspect-ratio: 1/1;
|
|
184
|
-
padding: 0.75rem;
|
|
185
|
-
border-radius: 50%;
|
|
186
|
-
z-index: 10;
|
|
187
|
-
}
|
|
1
|
+
*,
|
|
2
|
+
*::before,
|
|
3
|
+
*::after {
|
|
4
|
+
box-sizing: border-box;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
html {
|
|
8
|
+
color-scheme: dark;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
body {
|
|
12
|
+
display: grid;
|
|
13
|
+
justify-content: center;
|
|
14
|
+
align-content: center;
|
|
15
|
+
min-height: 100vh;
|
|
16
|
+
|
|
17
|
+
margin: 0;
|
|
18
|
+
font-family: system-ui;
|
|
19
|
+
font-size: 1.125rem;
|
|
20
|
+
line-height: 1.6;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
img {
|
|
24
|
+
max-width: 100%;
|
|
25
|
+
display: block;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.wrapper {
|
|
29
|
+
/* max-width: 50rem; */
|
|
30
|
+
margin-inline: auto;
|
|
31
|
+
padding-inline: 1rem;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.accordion {
|
|
35
|
+
--_button-size: 3rem;
|
|
36
|
+
--_panel-padding: 0.75rem;
|
|
37
|
+
--_panel-gap: 1rem;
|
|
38
|
+
|
|
39
|
+
display: flex;
|
|
40
|
+
flex-direction: column;
|
|
41
|
+
gap: 1rem;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@media (min-width: 45em) {
|
|
45
|
+
.accordion {
|
|
46
|
+
flex-direction: row;
|
|
47
|
+
/* height: 30rem; */
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.accordion * {
|
|
52
|
+
margin: 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.accordion-panel {
|
|
56
|
+
position: relative;
|
|
57
|
+
isolation: isolate;
|
|
58
|
+
flex-basis: calc((var(--_panel-padding) * 2) + var(--_button-size));
|
|
59
|
+
overflow: hidden;
|
|
60
|
+
padding: var(--_panel-padding);
|
|
61
|
+
padding-right: calc(var(--_panel-padding) * 4);
|
|
62
|
+
border-radius: calc(((var(--_panel-padding) * 2) + var(--_button-size)) / 2);
|
|
63
|
+
cursor: pointer;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
67
|
+
.accordion-panel {
|
|
68
|
+
transition: flex-basis 500ms, flex-grow 500ms;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.accordion-panel:nth-child(1) {
|
|
73
|
+
--_panel-color: red;
|
|
74
|
+
}
|
|
75
|
+
.accordion-panel:nth-child(2) {
|
|
76
|
+
--_panel-color: blue;
|
|
77
|
+
}
|
|
78
|
+
.accordion-panel:nth-child(3) {
|
|
79
|
+
--_panel-color: green;
|
|
80
|
+
}
|
|
81
|
+
.accordion-panel:nth-child(4) {
|
|
82
|
+
--_panel-color: yellow;
|
|
83
|
+
}
|
|
84
|
+
.accordion-panel:nth-child(5) {
|
|
85
|
+
--_panel-color: orange;
|
|
86
|
+
}
|
|
87
|
+
.accordion-panel:nth-child(6) {
|
|
88
|
+
--_panel-color: purple;
|
|
89
|
+
}
|
|
90
|
+
.accordion-panel:nth-child(7) {
|
|
91
|
+
--_panel-color: pink;
|
|
92
|
+
}
|
|
93
|
+
.accordion-panel:nth-child(8) {
|
|
94
|
+
--_panel-color: brown;
|
|
95
|
+
}
|
|
96
|
+
.accordion-panel:nth-child(9) {
|
|
97
|
+
--_panel-color: cyan;
|
|
98
|
+
}
|
|
99
|
+
.accordion-panel:nth-child(10) {
|
|
100
|
+
--_panel-color: magenta;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.accordion-panel:has([aria-expanded="true"]) {
|
|
104
|
+
flex-basis: clamp(15rem, 40vh, 20rem);
|
|
105
|
+
flex-grow: 1;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.accordion-trigger {
|
|
109
|
+
outline: 0 !important;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.accordion-panel:focus-within {
|
|
113
|
+
outline: 3px solid var(--_panel-color);
|
|
114
|
+
outline-offset: 4px;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.accordion-content > p {
|
|
118
|
+
transform: translateY(2rem);
|
|
119
|
+
opacity: 0;
|
|
120
|
+
margin-left: calc(var(--_button-size) + var(--_panel-gap));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
124
|
+
.accordion-panel:has([aria-expanded="true"]) .accordion-content > p {
|
|
125
|
+
transition: transform 500ms 500ms, opacity 500ms 500ms;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.accordion-panel:has([aria-expanded="true"]) .accordion-content > p {
|
|
130
|
+
transform: translateY(0);
|
|
131
|
+
opacity: 1;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.accordion-title {
|
|
135
|
+
font-size: 1.5rem;
|
|
136
|
+
font-weight: 700;
|
|
137
|
+
position: relative;
|
|
138
|
+
isolation: isolate;
|
|
139
|
+
display: grid;
|
|
140
|
+
align-items: center;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@media (max-width: 44.999em) {
|
|
144
|
+
.accordion-title::after {
|
|
145
|
+
content: "";
|
|
146
|
+
position: absolute;
|
|
147
|
+
|
|
148
|
+
left: calc((var(--_panel-gap) + var(--_button-size)) * -1);
|
|
149
|
+
width: calc(100% + (var(--_button-size) * 2));
|
|
150
|
+
height: var(--_button-size);
|
|
151
|
+
background: hsl(0 0% 0% /0.55);
|
|
152
|
+
z-index: -1;
|
|
153
|
+
border-radius: 100vw;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.accordion-image {
|
|
158
|
+
position: absolute;
|
|
159
|
+
inset: 0;
|
|
160
|
+
width: 100%;
|
|
161
|
+
height: 100%;
|
|
162
|
+
object-fit: cover;
|
|
163
|
+
z-index: -1;
|
|
164
|
+
transition: filer 500ms;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.accordion-panel:has([aria-expanded="true"]) .accordion-image {
|
|
168
|
+
filter: brightness(0.5);
|
|
169
|
+
}
|
|
170
|
+
.accordion-trigger {
|
|
171
|
+
display: flex;
|
|
172
|
+
align-items: center;
|
|
173
|
+
flex-direction: row-reverse;
|
|
174
|
+
gap: var(--_panel-gap);
|
|
175
|
+
background: transparent;
|
|
176
|
+
border: 0;
|
|
177
|
+
padding: 0;
|
|
178
|
+
}
|
|
179
|
+
.accordion-icon {
|
|
180
|
+
fill: var(--_panel-color);
|
|
181
|
+
background: hsl(0 0% 0% /0.55);
|
|
182
|
+
width: var(--_button-size);
|
|
183
|
+
aspect-ratio: 1/1;
|
|
184
|
+
padding: 0.75rem;
|
|
185
|
+
border-radius: 50%;
|
|
186
|
+
z-index: 10;
|
|
187
|
+
}
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import UseImageAccordion from "./UseImageAccordion";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import React from "react";
|
|
2
|
+
import UseImageAccordion from "./UseImageAccordion";
|
|
3
|
+
|
|
4
|
+
export const ReactImageAccordion = ({
|
|
5
|
+
accordionData,
|
|
6
|
+
AccordionWidth,
|
|
7
|
+
AccordionHeight,
|
|
8
|
+
}) => {
|
|
9
|
+
return (
|
|
10
|
+
<UseImageAccordion
|
|
11
|
+
accordionData={accordionData}
|
|
12
|
+
AccordionWidth={AccordionWidth}
|
|
13
|
+
AccordionHeight={AccordionHeight}
|
|
14
|
+
/>
|
|
15
|
+
);
|
|
16
|
+
};
|
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
import React, { useEffect, useState } from "react";
|
|
2
|
-
import "./App.css";
|
|
3
|
-
|
|
4
|
-
function UseImageAccordion({ accordionData }) {
|
|
5
|
-
const [activePanel, setActivePanel] = useState(null);
|
|
6
|
-
|
|
7
|
-
function toggleAccordion(panelToActivate) {
|
|
8
|
-
setActivePanel((prevPanel) => {
|
|
9
|
-
if (prevPanel === panelToActivate) {
|
|
10
|
-
return prevPanel;
|
|
11
|
-
} else {
|
|
12
|
-
return panelToActivate;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
setActivePanel(accordionData[0].id);
|
|
19
|
-
}, []);
|
|
20
|
-
|
|
21
|
-
if (!accordionData) return null;
|
|
22
|
-
return (
|
|
23
|
-
<>
|
|
24
|
-
<div className="wrapper">
|
|
25
|
-
<div className="accordion">
|
|
26
|
-
{accordionData.map((item) => (
|
|
27
|
-
<div
|
|
28
|
-
key={item.id}
|
|
29
|
-
className="accordion-panel"
|
|
30
|
-
onClick={() => toggleAccordion(item.id)}
|
|
31
|
-
>
|
|
32
|
-
<h2 id={item.id}>
|
|
33
|
-
<button
|
|
34
|
-
type="button"
|
|
35
|
-
className="accordion-trigger"
|
|
36
|
-
aria-controls="panel1-content"
|
|
37
|
-
aria-expanded={activePanel === item.id}
|
|
38
|
-
>
|
|
39
|
-
<span className="accordion-title" id={item.id}>
|
|
40
|
-
{item.title}
|
|
41
|
-
</span>
|
|
42
|
-
<svg aria-hidden="true" className="accordion-icon">
|
|
43
|
-
<image href={item.svg}></image>
|
|
44
|
-
</svg>
|
|
45
|
-
</button>
|
|
46
|
-
</h2>
|
|
47
|
-
<div
|
|
48
|
-
className="accordion-content"
|
|
49
|
-
id={item.id}
|
|
50
|
-
aria-labelledby={item.id}
|
|
51
|
-
aria-hidden={activePanel !== item.id}
|
|
52
|
-
role="region"
|
|
53
|
-
>
|
|
54
|
-
<p>{item.content}</p>
|
|
55
|
-
<img
|
|
56
|
-
className="accordion-image"
|
|
57
|
-
src={item.image}
|
|
58
|
-
alt={item.alt}
|
|
59
|
-
/>
|
|
60
|
-
</div>
|
|
61
|
-
</div>
|
|
62
|
-
))}
|
|
63
|
-
</div>
|
|
64
|
-
</div>
|
|
65
|
-
</>
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export default UseImageAccordion;
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
|
+
import "./App.css";
|
|
3
|
+
|
|
4
|
+
function UseImageAccordion({ accordionData, AccordionWidth, AccordionHeight }) {
|
|
5
|
+
const [activePanel, setActivePanel] = useState(null);
|
|
6
|
+
|
|
7
|
+
function toggleAccordion(panelToActivate) {
|
|
8
|
+
setActivePanel((prevPanel) => {
|
|
9
|
+
if (prevPanel === panelToActivate) {
|
|
10
|
+
return prevPanel;
|
|
11
|
+
} else {
|
|
12
|
+
return panelToActivate;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
setActivePanel(accordionData[0].id);
|
|
19
|
+
}, []);
|
|
20
|
+
|
|
21
|
+
if (!accordionData) return null;
|
|
22
|
+
return (
|
|
23
|
+
<>
|
|
24
|
+
<div className="wrapper" style={{ width: AccordionWidth }}>
|
|
25
|
+
<div className="accordion" style={{ height: AccordionHeight }}>
|
|
26
|
+
{accordionData.map((item) => (
|
|
27
|
+
<div
|
|
28
|
+
key={item.id}
|
|
29
|
+
className="accordion-panel"
|
|
30
|
+
onClick={() => toggleAccordion(item.id)}
|
|
31
|
+
>
|
|
32
|
+
<h2 id={item.id}>
|
|
33
|
+
<button
|
|
34
|
+
type="button"
|
|
35
|
+
className="accordion-trigger"
|
|
36
|
+
aria-controls="panel1-content"
|
|
37
|
+
aria-expanded={activePanel === item.id}
|
|
38
|
+
>
|
|
39
|
+
<span className="accordion-title" id={item.id}>
|
|
40
|
+
{item.title}
|
|
41
|
+
</span>
|
|
42
|
+
<svg aria-hidden="true" className="accordion-icon">
|
|
43
|
+
<image href={item.svg}></image>
|
|
44
|
+
</svg>
|
|
45
|
+
</button>
|
|
46
|
+
</h2>
|
|
47
|
+
<div
|
|
48
|
+
className="accordion-content"
|
|
49
|
+
id={item.id}
|
|
50
|
+
aria-labelledby={item.id}
|
|
51
|
+
aria-hidden={activePanel !== item.id}
|
|
52
|
+
role="region"
|
|
53
|
+
>
|
|
54
|
+
<p>{item.content}</p>
|
|
55
|
+
<img
|
|
56
|
+
className="accordion-image"
|
|
57
|
+
src={item.image}
|
|
58
|
+
alt={item.alt}
|
|
59
|
+
/>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
))}
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
</>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default UseImageAccordion;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
export * from "./React-image-accordion";
|
|
1
|
+
import React from "react";
|
|
2
|
+
export * from "./React-image-accordion";
|
package/src/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
export * from "./components/Accordion";
|
|
1
|
+
import React from "react";
|
|
2
|
+
export * from "./components/Accordion";
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"title": "Boating",
|
|
4
|
-
"id": 1,
|
|
5
|
-
"image": "https://picsum.photos/400/
|
|
6
|
-
"alt": "first panel image",
|
|
7
|
-
"content": "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
|
|
8
|
-
"svg": "aa (1).svg"
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
"title": "Fishing",
|
|
12
|
-
"id": 2,
|
|
13
|
-
"image": "https://picsum.photos/400/
|
|
14
|
-
"alt": "second panel image",
|
|
15
|
-
"content": "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
|
|
16
|
-
"svg": "aa (2).svg"
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
"title": "Swimming",
|
|
20
|
-
"id": 3,
|
|
21
|
-
"image": "https://picsum.photos/
|
|
22
|
-
"alt": "third panel image",
|
|
23
|
-
"content": "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
|
|
24
|
-
"svg": "aa (3).svg"
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
"title": "Kayaking",
|
|
28
|
-
"id": 4,
|
|
29
|
-
"image": "https://picsum.photos/
|
|
30
|
-
"alt": "fourth panel image",
|
|
31
|
-
"content": "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
|
|
32
|
-
"svg": "aa (4).svg"
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
"title": "Scuba diving",
|
|
36
|
-
"id": 5,
|
|
37
|
-
"image": "https://picsum.photos/
|
|
38
|
-
"alt": "fifth panel image",
|
|
39
|
-
"content": "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
|
|
40
|
-
"svg": "aa (5).svg"
|
|
41
|
-
}
|
|
42
|
-
]
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"title": "Boating",
|
|
4
|
+
"id": 1,
|
|
5
|
+
"image": "https://picsum.photos/400/601",
|
|
6
|
+
"alt": "first panel image",
|
|
7
|
+
"content": "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
|
|
8
|
+
"svg": "aa (1).svg"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"title": "Fishing",
|
|
12
|
+
"id": 2,
|
|
13
|
+
"image": "https://picsum.photos/400/602",
|
|
14
|
+
"alt": "second panel image",
|
|
15
|
+
"content": "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
|
|
16
|
+
"svg": "aa (2).svg"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"title": "Swimming",
|
|
20
|
+
"id": 3,
|
|
21
|
+
"image": "https://picsum.photos/401/600",
|
|
22
|
+
"alt": "third panel image",
|
|
23
|
+
"content": "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
|
|
24
|
+
"svg": "aa (3).svg"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"title": "Kayaking",
|
|
28
|
+
"id": 4,
|
|
29
|
+
"image": "https://picsum.photos/402/600",
|
|
30
|
+
"alt": "fourth panel image",
|
|
31
|
+
"content": "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
|
|
32
|
+
"svg": "aa (4).svg"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"title": "Scuba diving",
|
|
36
|
+
"id": 5,
|
|
37
|
+
"image": "https://picsum.photos/401/601",
|
|
38
|
+
"alt": "fifth panel image",
|
|
39
|
+
"content": "Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe id numquam ab molestias sint beatae provident possimus doloribus autem repudiandae!",
|
|
40
|
+
"svg": "aa (5).svg"
|
|
41
|
+
}
|
|
42
|
+
]
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { ReactImageAccordion } from "../components/Accordion";
|
|
3
|
-
import MockAccordion from "./MockAccordion.json";
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
title: "React Image Accordion",
|
|
7
|
-
component: ReactImageAccordion,
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const Template = (args) => <ReactImageAccordion {...args} />;
|
|
11
|
-
|
|
12
|
-
export const App = Template.bind({});
|
|
13
|
-
App.args = {
|
|
14
|
-
accordionData: MockAccordion,
|
|
15
|
-
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ReactImageAccordion } from "../components/Accordion";
|
|
3
|
+
import MockAccordion from "./MockAccordion.json";
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: "React Image Accordion",
|
|
7
|
+
component: ReactImageAccordion,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const Template = (args) => <ReactImageAccordion {...args} />;
|
|
11
|
+
|
|
12
|
+
export const App = Template.bind({});
|
|
13
|
+
App.args = {
|
|
14
|
+
accordionData: MockAccordion,
|
|
15
|
+
AccordionWidth: "40rem",
|
|
16
|
+
AccordionHeight: "30rem",
|
|
17
|
+
};
|