From 98b46a94d3af714eee0a0ca73dac84bc3177184a Mon Sep 17 00:00:00 2001 From: Alejandro Bailo <59607668+alejandrobailo@users.noreply.github.com> Date: Mon, 12 May 2025 10:32:40 +0200 Subject: [PATCH] feat: accordion component (#7700) --- ui/CHANGELOG.md | 3 - ui/components/ui/accordion/Accordion.tsx | 109 +++++++++++++++++++++++ ui/components/ui/index.ts | 1 + 3 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 ui/components/ui/accordion/Accordion.tsx diff --git a/ui/CHANGELOG.md b/ui/CHANGELOG.md index f89c82ef37..8c9c12db4e 100644 --- a/ui/CHANGELOG.md +++ b/ui/CHANGELOG.md @@ -2,8 +2,6 @@ All notable changes to the **Prowler UI** are documented in this file. -<<<<<<< HEAD -======= ## [v1.7.0] (Prowler v5.7.0) – Not released ### 🚀 Added @@ -16,7 +14,6 @@ All notable changes to the **Prowler UI** are documented in this file. - Fix form validation in launch scan workflow. [(#7693)](https://github.com/prowler-cloud/prowler/pull/7693) - Moved ProviderType to a shared types file and replaced all occurrences across the codebase. [(#7710)](https://github.com/prowler-cloud/prowler/pull/7710) ->>>>>>> 60e004057 (fix: move ProviderType to shared types and update usages (#7710)) --- ## [v1.6.0] (Prowler v5.6.0) diff --git a/ui/components/ui/accordion/Accordion.tsx b/ui/components/ui/accordion/Accordion.tsx new file mode 100644 index 0000000000..aa029a121c --- /dev/null +++ b/ui/components/ui/accordion/Accordion.tsx @@ -0,0 +1,109 @@ +"use client"; + +import { + Accordion as NextUIAccordion, + AccordionItem, + Selection, +} from "@nextui-org/react"; +import { ChevronDown } from "lucide-react"; +import React, { ReactNode, useCallback, useState } from "react"; + +import { cn } from "@/lib/utils"; + +export interface AccordionItemProps { + key: string; + title: ReactNode; + subtitle?: ReactNode; + content: ReactNode; + items?: AccordionItemProps[]; + isDisabled?: boolean; +} + +export interface AccordionProps { + items: AccordionItemProps[]; + variant?: "light" | "shadow" | "bordered" | "splitted"; + className?: string; + defaultExpandedKeys?: string[]; + selectionMode?: "single" | "multiple"; + isCompact?: boolean; + showDivider?: boolean; +} + +const AccordionContent = ({ + content, + items, +}: { + content: ReactNode; + items?: AccordionItemProps[]; +}) => { + return ( +
+ {content} + {items && items.length > 0 && ( +
+ +
+ )} +
+ ); +}; + +export const Accordion = ({ + items, + variant = "light", + className, + defaultExpandedKeys = [], + selectionMode = "single", + isCompact = false, + showDivider = true, +}: AccordionProps) => { + const [expandedKeys, setExpandedKeys] = useState( + new Set(defaultExpandedKeys), + ); + + const handleSelectionChange = useCallback((keys: Selection) => { + setExpandedKeys(keys); + }, []); + + return ( + + {items.map((item, index) => ( + } + classNames={{ + base: index === 0 || index === 1 ? "my-2" : "my-1", + title: "text-sm font-medium", + subtitle: "text-xs text-gray-500", + trigger: + "p-2 rounded-lg data-[hover=true]:bg-gray-50 dark:data-[hover=true]:bg-gray-800/50", + content: "p-2", + }} + > + + + ))} + + ); +}; + +Accordion.displayName = "Accordion"; diff --git a/ui/components/ui/index.ts b/ui/components/ui/index.ts index 181ad5e4c1..6fb4555d80 100644 --- a/ui/components/ui/index.ts +++ b/ui/components/ui/index.ts @@ -1,3 +1,4 @@ +export * from "./accordion/Accordion"; export * from "./action-card/ActionCard"; export * from "./alert/Alert"; export * from "./alert-dialog/AlertDialog";