Skip to content
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

Merged
merged 16 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
"prepare": "husky"
},
"dependencies": {
"@nextui-org/accordion": "^2.0.40",
"@nextui-org/button": "2.0.38",
"@nextui-org/card": "^2.0.34",
"@nextui-org/code": "2.0.33",
"@nextui-org/input": "2.2.5",
"@nextui-org/kbd": "2.0.34",
"@nextui-org/link": "2.0.35",
"@nextui-org/listbox": "2.1.27",
"@nextui-org/navbar": "2.0.37",
"@nextui-org/react": "^2.4.8",
"@nextui-org/skeleton": "^2.0.32",
"@nextui-org/snippet": "2.0.43",
"@nextui-org/switch": "2.0.34",
Expand Down
5 changes: 5 additions & 0 deletions public/Images/Acute.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/Images/ArrowGreen.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/Images/ArrowRed.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions public/Images/Chronic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions public/Images/FoodConsumption.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/Images/Import.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions public/Images/InfoIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/Images/Population.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 56 additions & 1 deletion src/app/elements/page.tsx
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';
Copy link
Collaborator

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

Copy link
Collaborator Author

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.

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} />;
}
36 changes: 36 additions & 0 deletions src/components/Accordions/Accordion.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use client';
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Collaborator Author

@ArmanpreetGhotra ArmanpreetGhotra Nov 6, 2024

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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>
);
}
Loading