Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove private Modal dependency on ButtonIcon #357

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
})}
</>
);
});
Loading