2021-10-21 17:35:28 +05:30
|
|
|
import { useState } from "react";
|
|
|
|
import { t } from "../i18n";
|
2022-03-16 15:59:30 +01:00
|
|
|
import { useDeviceType } from "./App";
|
2021-10-21 17:35:28 +05:30
|
|
|
import { trash } from "./icons";
|
|
|
|
import { ToolButton } from "./ToolButton";
|
|
|
|
|
2021-11-16 18:55:56 +05:30
|
|
|
import ConfirmDialog from "./ConfirmDialog";
|
2021-10-21 17:35:28 +05:30
|
|
|
|
|
|
|
const ClearCanvas = ({ onConfirm }: { onConfirm: () => void }) => {
|
|
|
|
const [showDialog, setShowDialog] = useState(false);
|
|
|
|
const toggleDialog = () => {
|
|
|
|
setShowDialog(!showDialog);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<ToolButton
|
|
|
|
type="button"
|
|
|
|
icon={trash}
|
|
|
|
title={t("buttons.clearReset")}
|
|
|
|
aria-label={t("buttons.clearReset")}
|
2022-03-16 15:59:30 +01:00
|
|
|
showAriaLabel={useDeviceType().isMobile}
|
2021-10-21 17:35:28 +05:30
|
|
|
onClick={toggleDialog}
|
|
|
|
data-testid="clear-canvas-button"
|
|
|
|
/>
|
|
|
|
|
|
|
|
{showDialog && (
|
2021-11-16 18:55:56 +05:30
|
|
|
<ConfirmDialog
|
|
|
|
onConfirm={() => {
|
|
|
|
onConfirm();
|
|
|
|
toggleDialog();
|
|
|
|
}}
|
|
|
|
onCancel={toggleDialog}
|
2021-10-21 17:35:28 +05:30
|
|
|
title={t("clearCanvasDialog.title")}
|
|
|
|
>
|
2021-11-16 18:55:56 +05:30
|
|
|
<p className="clear-canvas__content"> {t("alerts.clearReset")}</p>
|
|
|
|
</ConfirmDialog>
|
2021-10-21 17:35:28 +05:30
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ClearCanvas;
|