From e3ccd6d2651a3017c2541e3f377c30ea83895c63 Mon Sep 17 00:00:00 2001
From: Arno V <versini@gmail.com>
Date: Mon, 26 Feb 2024 09:41:50 -0500
Subject: [PATCH] feat: remove private Modal dependency on ButtonIcon

---
 .../src/components/Panel/Panel.tsx            | 12 ++++++----
 .../src/components/private/Modal/Modal.tsx    | 23 ++++++++-----------
 2 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/packages/ui-components/src/components/Panel/Panel.tsx b/packages/ui-components/src/components/Panel/Panel.tsx
index a99c7459..83ee3915 100644
--- a/packages/ui-components/src/components/Panel/Panel.tsx
+++ b/packages/ui-components/src/components/Panel/Panel.tsx
@@ -1,6 +1,6 @@
 import { useEffect, useRef } from "react";
 
-import { IconClose } from "../";
+import { ButtonIcon, IconClose } from "../";
 import {
 	Modal,
 	ModalClose,
@@ -44,9 +44,13 @@ export const Panel = ({
 		<Modal open={open} onOpenChange={onOpenChange}>
 			<ModalContent className={panelClassName.main}>
 				<ModalHeading className={panelClassName.header}>
-					<ModalClose>
-						<IconClose />
-					</ModalClose>
+					<ModalClose
+						trigger={
+							<ButtonIcon noBorder label="Close">
+								<IconClose />
+							</ButtonIcon>
+						}
+					></ModalClose>
 					<div>{title}</div>
 				</ModalHeading>
 
diff --git a/packages/ui-components/src/components/private/Modal/Modal.tsx b/packages/ui-components/src/components/private/Modal/Modal.tsx
index f27a6e94..87427bed 100644
--- a/packages/ui-components/src/components/private/Modal/Modal.tsx
+++ b/packages/ui-components/src/components/private/Modal/Modal.tsx
@@ -7,7 +7,7 @@ import {
 import clsx from "clsx";
 import * as React from "react";
 
-import { ButtonIcon, useUniqueId } from "../..";
+import { useUniqueId } from "../..";
 import { ModalContext } from "./ModalContext";
 import { useModal, useModalContext } from "./ModalHooks";
 import type { ModalOptions } from "./ModalTypes";
@@ -106,22 +106,19 @@ export const ModalDescription = React.forwardRef<
 export const ModalClose = React.forwardRef<
 	HTMLButtonElement,
 	{
-		children?: React.ReactNode;
+		trigger: React.ReactElement;
 	}
 >(function ModalClose(props, ref) {
 	const { setOpen } = useModalContext();
-	const { children, ...rest } = props;
+	const { trigger, ...rest } = props;
 	const handleClose = React.useCallback(() => setOpen(false), [setOpen]);
 	return (
-		<ButtonIcon
-			noBorder
-			label="Close"
-			type="button"
-			{...rest}
-			ref={ref}
-			onClick={handleClose}
-		>
-			{children}
-		</ButtonIcon>
+		<>
+			{React.cloneElement(trigger, {
+				ref,
+				onClick: handleClose,
+				...rest,
+			})}
+		</>
 	);
 });