From cb9d48073b0b0ea94ebd022c824c7c7be8347e32 Mon Sep 17 00:00:00 2001 From: Lansana DIOMANDE Date: Mon, 8 Jan 2024 09:28:41 +0000 Subject: [PATCH] feat: can use a wrapper on panel when using items props of collapse --- src/hooks/useItems.tsx | 9 ++++++++- src/interface.ts | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/hooks/useItems.tsx b/src/hooks/useItems.tsx index 2bc5db7..27f7e7b 100644 --- a/src/hooks/useItems.tsx +++ b/src/hooks/useItems.tsx @@ -24,6 +24,7 @@ const convertItemsToNodes = (items: ItemType[], props: Props) => { const { children, label, + wrapper, key: rawKey, collapsible: rawCollapsible, onItemClick: rawOnItemClick, @@ -50,7 +51,7 @@ const convertItemsToNodes = (items: ItemType[], props: Props) => { isActive = activeKey.indexOf(key) > -1; } - return ( + const collapsePanel = ( { {children} ); + + if (wrapper) { + return wrapper(collapsePanel); + } + + return collapsePanel; }); }; diff --git a/src/interface.ts b/src/interface.ts index 7a36bed..5288153 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -1,5 +1,6 @@ import type { CSSMotionProps } from 'rc-motion'; import type * as React from 'react'; +import type { ReactNode } from 'react'; export type CollapsibleType = 'header' | 'icon' | 'disabled'; @@ -16,6 +17,7 @@ export interface ItemType > { key?: CollapsePanelProps['panelKey']; label?: CollapsePanelProps['header']; + wrapper?: ReactNode; ref?: React.RefObject; }