-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/f 39 implement generic accordion component #12
Changes from 3 commits
d293865
f07ad1f
c3edb35
e410034
a233351
fb4f385
8a6cd28
df7d75a
3a3f1d2
12ef2d8
6a58e64
e3b6ab5
64edb1a
b633af8
91b2bff
6743a38
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,64 @@ | ||
import Accordions from '@/components/Accordions/Accordion'; | ||
import Cards from '@/components/Cards/Card'; | ||
import { Chart } from '@/components/Charts/Chart'; | ||
import { cardsWrapperClass } from '@/utils/primitives'; | ||
|
||
/** | ||
* You can use this page to try and show off your components. | ||
* It's not accessible from the UI, but you can reach it by manually navigating to /elements | ||
*/ | ||
|
||
const accordionData = [ | ||
ArmanpreetGhotra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
title: 'Food Security', | ||
iconSrc: '/Images/InfoIcon.svg', | ||
content: ( | ||
<div className={cardsWrapperClass}> | ||
<Cards | ||
title="Population" | ||
content={[{ imageSrc: '/Images/Population.svg', text: '4.4 Mio', altText: 'Population Icon' }]} | ||
/> | ||
<Cards | ||
title="Population with Food Consumption" | ||
content={[ | ||
{ imageSrc: '/Images/FoodConsumption.svg', text: '11.2 Mio', altText: 'Population Icon' }, | ||
{ imageSrc: '/Images/ArrowRed.svg', text: '+ 0.19 Mio', timeText: '3 Months ago', altText: 'Icon' }, | ||
{ imageSrc: '/Images/ArrowGreen.svg', text: '- 2.5 Mio ', timeText: 'A Month ago', altText: 'Other Icon' }, | ||
]} | ||
/> | ||
</div> | ||
), | ||
}, | ||
{ | ||
title: 'Nutrition', | ||
iconSrc: '/Images/InfoIcon.svg', | ||
content: ( | ||
<div className={cardsWrapperClass}> | ||
<Cards | ||
title="Acute Nutrition" | ||
content={[{ imageSrc: '/Images/Acute.svg', text: '28.0% of Cereals', altText: ' Icon' }]} | ||
/> | ||
<Cards | ||
title="Chronic Nutrition" | ||
content={[{ imageSrc: '/Images/Chronic.svg', text: '28.0% of Cereals', altText: ' Icon' }]} | ||
/> | ||
</div> | ||
), | ||
}, | ||
{ | ||
title: 'Macroeconomic', | ||
iconSrc: '/Images/InfoIcon.svg', | ||
content: ( | ||
<div className={cardsWrapperClass}> | ||
<Cards | ||
title="Import Dependency" | ||
content={[{ imageSrc: '/Images/Import.svg', text: '28.0% of Cereals', altText: ' Icon' }]} | ||
/> | ||
</div> | ||
), | ||
}, | ||
]; | ||
export default function Elements() { | ||
return <Chart />; | ||
// return <Chart />; | ||
return <Accordions items={accordionData} />; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use client'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need of client component here, you do not use any client side APIs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as soon as remove the 'use client' the accordions as well as card doesn't get rendered. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually an open bug in NextUI, I had the same problem for the table. Seems like keeping 'use client' is neccesary for now: nextui-org/nextui#1403 (comment) |
||
|
||
import { Accordion, AccordionItem } from '@nextui-org/accordion'; | ||
|
||
interface AccordionItemProps { | ||
title: string; | ||
iconSrc?: string; | ||
content: React.ReactNode | string; | ||
} | ||
|
||
interface AccordionsProps { | ||
items: AccordionItemProps[]; | ||
} | ||
|
||
ArmanpreetGhotra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
export default function Accordions({ items }: AccordionsProps) { | ||
ArmanpreetGhotra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return ( | ||
<div className="accordion-wrapper"> | ||
<Accordion variant="splitted" className="accordion-container"> | ||
bohdangarchu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{items.map((item) => ( | ||
<AccordionItem | ||
key={item.title} | ||
aria-label={item.title} | ||
title={ | ||
<div className="flex items-center justify-between w-full"> | ||
<span>{item.title}</span> | ||
ArmanpreetGhotra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{item.iconSrc && <img src={item.iconSrc} alt="info icon" className="info-icon" />} | ||
</div> | ||
} | ||
> | ||
{typeof item.content === 'string' ? <p>{item.content}</p> : item.content} | ||
</AccordionItem> | ||
))} | ||
</Accordion> | ||
</div> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generally do not remove other components when adding yours here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed that import because I was getting an "unused vars" error. Since the comments mentioned that page.tsx is intended for testing purposes, I decided to remove it.