From 7e696995235ae83f1eb70f8f0e2fc840db1c8ac6 Mon Sep 17 00:00:00 2001 From: praptippradhan Date: Wed, 3 Apr 2024 00:54:54 +0530 Subject: [PATCH] fix: made faq section collapsible --- pnpm-lock.yaml | 2 +- src/components/FaqSection/faq.jsx | 45 ++++++++++------ src/components/Gallery/gallery.jsx | 46 ++++++++++++++++ src/config/content/galleryData.js | 87 ++++++++++++++++++++++++++++++ src/pages/playground.jsx | 6 --- 5 files changed, 163 insertions(+), 23 deletions(-) create mode 100644 src/components/Gallery/gallery.jsx create mode 100644 src/config/content/galleryData.js diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2f66774..c715b3d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -51,7 +51,7 @@ devDependencies: version: 8.56.0 eslint-plugin-jsdoc: specifier: ^48.0.6 - version: 48.0.6(eslint@8.56.0) + version: 48.0.6(eslint@8.56.0)1 eslint-plugin-react: specifier: ^7.33.2 version: 7.33.2(eslint@8.56.0) diff --git a/src/components/FaqSection/faq.jsx b/src/components/FaqSection/faq.jsx index c49476a..0335699 100644 --- a/src/components/FaqSection/faq.jsx +++ b/src/components/FaqSection/faq.jsx @@ -1,9 +1,19 @@ +import { useState } from 'react'; import faqData from '../../config/content/faqData.js'; import { PersonalizedText, Heading, Paragraph } from '../shared/index.js'; function FAQ() { const Header1 = faqData.Header1; const Header2 = faqData.Header2; + const [openQuestion, setOpenQuestion] = useState(null); + + const toggleQuestion = id => { + if (openQuestion === id) { + setOpenQuestion(null); + } else { + setOpenQuestion(id); + } + }; return (
@@ -22,24 +32,27 @@ function FAQ() {
{faqData.questions.map(({ id, question, answer }) => ( -
-
- {faqData.img.alt} +
+
toggleQuestion(id)}> + {openQuestion === id ? - : +} {question}
- {answer instanceof Array ? ( -
    - {answer.map(({ key, content, bulleted }) => ( -
  • - {content} -
  • - ))} -
- ) : ( - - {answer} - - )} + {openQuestion === id && + (answer instanceof Array ? ( +
    + {answer.map(({ key, content, bulleted }) => ( +
  • + {content} +
  • + ))} +
+ ) : ( + + {answer} + + ))}
))}
diff --git a/src/components/Gallery/gallery.jsx b/src/components/Gallery/gallery.jsx new file mode 100644 index 0000000..bdb21f3 --- /dev/null +++ b/src/components/Gallery/gallery.jsx @@ -0,0 +1,46 @@ +import galleryData from '../../config/content/galleryData.js'; +import { Heading, Text } from '../shared/index.js'; + +function Gallery() { + return ( +
+ + {galleryData.headerText} + +
+ {galleryData.images.map(({ id, src, alt }) => ( +
+ {alt} +
+ ))} +
+
+ +
+
+ ); +} + +export default Gallery; diff --git a/src/config/content/galleryData.js b/src/config/content/galleryData.js new file mode 100644 index 0000000..6d9b7a9 --- /dev/null +++ b/src/config/content/galleryData.js @@ -0,0 +1,87 @@ +export default { + id: 'Gallery', + headerText: 'GALLERY', + buttonText: 'Back', + images: [ + { + id: 1, + src: 'https://res.cloudinary.com/dv1src8un/image/upload/v1711788300/gallery_z7ofs5.png', + alt: '', + }, + { + id: 1, + src: 'https://res.cloudinary.com/dv1src8un/image/upload/v1711788300/gallery_z7ofs5.png', + alt: '', + }, + { + id: 1, + src: 'https://res.cloudinary.com/dv1src8un/image/upload/v1711788300/gallery_z7ofs5.png', + alt: '', + }, + { + id: 1, + src: 'https://res.cloudinary.com/dv1src8un/image/upload/v1711788300/gallery_z7ofs5.png', + alt: '', + }, + { + id: 1, + src: 'https://res.cloudinary.com/dv1src8un/image/upload/v1711788300/gallery_z7ofs5.png', + alt: '', + }, + { + id: 1, + src: 'https://res.cloudinary.com/dv1src8un/image/upload/v1711788300/gallery_z7ofs5.png', + alt: '', + }, + { + id: 1, + src: 'https://res.cloudinary.com/dv1src8un/image/upload/v1711788300/gallery_z7ofs5.png', + alt: '', + }, + { + id: 1, + src: 'https://res.cloudinary.com/dv1src8un/image/upload/v1711788300/gallery_z7ofs5.png', + alt: '', + }, + { + id: 1, + src: 'https://res.cloudinary.com/dv1src8un/image/upload/v1711788300/gallery_z7ofs5.png', + alt: '', + }, + { + id: 1, + src: 'https://res.cloudinary.com/dv1src8un/image/upload/v1711788300/gallery_z7ofs5.png', + alt: '', + }, + { + id: 1, + src: 'https://res.cloudinary.com/dv1src8un/image/upload/v1711788300/gallery_z7ofs5.png', + alt: '', + }, + { + id: 1, + src: 'https://res.cloudinary.com/dv1src8un/image/upload/v1711788300/gallery_z7ofs5.png', + alt: '', + }, + { + id: 1, + src: 'https://res.cloudinary.com/dv1src8un/image/upload/v1711788300/gallery_z7ofs5.png', + alt: '', + }, + { + id: 1, + src: 'https://res.cloudinary.com/dv1src8un/image/upload/v1711788300/gallery_z7ofs5.png', + alt: '', + }, + { + id: 1, + src: 'https://res.cloudinary.com/dv1src8un/image/upload/v1711788300/gallery_z7ofs5.png', + alt: '', + }, + { + id: 1, + src: 'https://res.cloudinary.com/dv1src8un/image/upload/v1711788300/gallery_z7ofs5.png', + alt: '', + }, + ], +}; diff --git a/src/pages/playground.jsx b/src/pages/playground.jsx index a6d0c87..c48211f 100644 --- a/src/pages/playground.jsx +++ b/src/pages/playground.jsx @@ -1,15 +1,9 @@ import FAQ from '../components/FaqSection/faq.jsx'; -import Footer from '../components/shared/marginals/footer.jsx'; -import AboutUs from '../components/AboutUs.jsx'; -import NavBar from '../components/shared/NavBar'; export default function Playground() { return ( <> - - -