infoalloggi-monorepo/apps/infoalloggi/src/components/accordionComp.tsx
Marco Pedone 1fc855393f Refactor Annuncio Card Component and Remove Legacy Code
- Updated `CardAnnuncio` component to enhance functionality and styling.
- Removed `CardAnnuncio2` component as it was redundant.
- Added new icons and badges for better visual representation of availability and status.
- Improved layout and responsiveness of the card.
- Updated translations in English and Italian for consistency.
- Enhanced pagination controls in the `Annunci` page with new button styles.
- Adjusted footer components to accept additional class names for customization.
- Cleaned up unused CSS animations and styles in `globals.css`.
- Modified server-side controller to include homepage field in the Annuncio data structure.
2025-11-03 18:49:27 +01:00

67 lines
1.7 KiB
TypeScript

import { forwardRef, type InputHTMLAttributes } from "react";
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "~/components/ui/accordion";
import type { Faq } from "~/i18n/locales";
import { cn } from "~/lib/utils";
interface AccordionCompProps extends InputHTMLAttributes<HTMLDivElement> {
texts: Faq[];
defaultOpen?: number;
}
/**
* Renders an accordion component with collapsible items.
*
* @component
* @example
* ```tsx
* <AccordionComp
* texts={[
* { title: "Item 1", description: "Description for Item 1" },
* { title: "Item 2", description: "Description for Item 2" },
* { title: "Item 3", description: "Description for Item 3" },
* ]}
* className="my-4"
* />
* ```
*/
export const AccordionComp = forwardRef<HTMLDivElement, AccordionCompProps>(
({ texts, defaultOpen, className }, ref) => {
if (!texts || texts.length === 0) {
return null; // Return null if no texts are provided
}
return (
<div
className={cn("mx-auto flex max-w-xl justify-center", className)}
ref={ref}
>
<Accordion
className="w-full"
collapsible
defaultValue={
defaultOpen !== undefined ? `item-${defaultOpen}` : undefined
}
type="single"
>
{texts.map((text, index) => (
// biome-ignore lint/suspicious/noArrayIndexKey: <index is safe here>
<AccordionItem key={`ac-item-${index}`} value={`item-${index}`}>
<AccordionTrigger className="cursor-pointer gap-4 text-left text-lg">
{text.title}
</AccordionTrigger>
<AccordionContent className="text-base">
{text.description}
</AccordionContent>
</AccordionItem>
))}
</Accordion>
</div>
);
},
);
AccordionComp.displayName = "AccordionComp";