Skip to content

Commit

Permalink
feat: remove private Modal dependency on ButtonIcon
Browse files Browse the repository at this point in the history
  • Loading branch information
aversini committed Feb 26, 2024
1 parent c0117fb commit e3ccd6d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
12 changes: 8 additions & 4 deletions packages/ui-components/src/components/Panel/Panel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useRef } from "react";

import { IconClose } from "../";
import { ButtonIcon, IconClose } from "../";
import {
Modal,
ModalClose,
Expand Down Expand Up @@ -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>

Expand Down
23 changes: 10 additions & 13 deletions packages/ui-components/src/components/private/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
})}
</>
);
});

0 comments on commit e3ccd6d

Please sign in to comment.