Skip to content
This repository was archived by the owner on May 3, 2025. It is now read-only.

Commit 42c4e35

Browse files
authored
feat(component): Add ConfirmIconButton and update file card delete button (#287)
1 parent 51b4740 commit 42c4e35

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { ConfirmationDialog } from "components/confirmation-dialog";
2+
import { IconButton } from "components/icon-button";
3+
import { IconButtonProps as EvergreenIconButtonProps } from "evergreen-ui";
4+
import React, { ForwardedRef, forwardRef, useCallback, useState } from "react";
5+
6+
interface ConfirmIconButtonProps extends EvergreenIconButtonProps {
7+
confirmationDescription?: string;
8+
confirmationTitle?: string;
9+
onClick?: () => void;
10+
}
11+
12+
const ConfirmIconButton: React.FC<ConfirmIconButtonProps> = forwardRef(
13+
(props: ConfirmIconButtonProps, ref: ForwardedRef<HTMLButtonElement>) => {
14+
const { confirmationDescription, confirmationTitle, onClick, ...rest } =
15+
props;
16+
17+
const [isConfirming, setIsConfirming] = useState<boolean>(false);
18+
19+
const handleConfirmation = useCallback(
20+
(close: () => void) => {
21+
onClick?.();
22+
close();
23+
},
24+
[onClick]
25+
);
26+
27+
return (
28+
<React.Fragment>
29+
<IconButton
30+
onClick={() => setIsConfirming(true)}
31+
ref={ref}
32+
{...rest}
33+
/>
34+
{isConfirming &&
35+
confirmationDescription != null &&
36+
confirmationTitle != null && (
37+
<ConfirmationDialog
38+
alertDescription={confirmationDescription}
39+
alertTitle={confirmationTitle}
40+
onCloseComplete={() => setIsConfirming(false)}
41+
onConfirm={handleConfirmation}
42+
/>
43+
)}
44+
</React.Fragment>
45+
);
46+
}
47+
);
48+
49+
export { ConfirmIconButton };

src/components/files/file-card.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { useBoolean } from "utils/hooks/use-boolean";
1818
import { FileSettingsDialog } from "components/files/file-settings-dialog";
1919
import { Flex } from "components/flex";
2020
import { IconButton } from "components/icon-button";
21+
import { ConfirmIconButton } from "components/confirm-icon-button";
2122

2223
interface FileCardProps
2324
extends Omit<EvergreenFileCardProps, "name" | "sizeInBytes" | "type"> {
@@ -92,9 +93,11 @@ const FileCard: React.FC<FileCardProps> = (props: FileCardProps) => {
9293
onClick={handleOpenDialog}
9394
type="button"
9495
/>
95-
<IconButton
96+
<ConfirmIconButton
9697
appearance="minimal"
9798
color={colors.gray600}
99+
confirmationDescription="After deleting this file, it will not be available for future and current projects."
100+
confirmationTitle="Are you sure?"
98101
icon={TrashIcon}
99102
isLoading={isLoading}
100103
marginLeft="auto"

0 commit comments

Comments
 (0)