12 changed files with 178 additions and 62 deletions
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
import { atom, useAtom } from "jotai"; |
||||
import { actionClearCanvas } from "../actions"; |
||||
import { t } from "../i18n"; |
||||
import { useExcalidrawActionManager } from "./App"; |
||||
import ConfirmDialog from "./ConfirmDialog"; |
||||
|
||||
export const activeConfirmDialogAtom = atom<"clearCanvas" | null>(null); |
||||
|
||||
export const ActiveConfirmDialog = () => { |
||||
const [activeConfirmDialog, setActiveConfirmDialog] = useAtom( |
||||
activeConfirmDialogAtom, |
||||
); |
||||
const actionManager = useExcalidrawActionManager(); |
||||
|
||||
if (!activeConfirmDialog) { |
||||
return null; |
||||
} |
||||
|
||||
if (activeConfirmDialog === "clearCanvas") { |
||||
return ( |
||||
<ConfirmDialog |
||||
onConfirm={() => { |
||||
actionManager.executeAction(actionClearCanvas); |
||||
setActiveConfirmDialog(null); |
||||
}} |
||||
onCancel={() => setActiveConfirmDialog(null)} |
||||
title={t("clearCanvasDialog.title")} |
||||
> |
||||
<p className="clear-canvas__content"> {t("alerts.clearReset")}</p> |
||||
</ConfirmDialog> |
||||
); |
||||
} |
||||
|
||||
return null; |
||||
}; |
||||
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
import React, { useContext } from "react"; |
||||
import { EVENT } from "../../constants"; |
||||
import { composeEventHandlers } from "../../utils"; |
||||
|
||||
export const DropdownMenuContentPropsContext = React.createContext<{ |
||||
onSelect?: (event: Event) => void; |
||||
}>({}); |
||||
|
||||
export const getDrodownMenuItemClassName = (className = "") => { |
||||
return `dropdown-menu-item dropdown-menu-item-base ${className}`.trim(); |
||||
}; |
||||
|
||||
export const useHandleDropdownMenuItemClick = ( |
||||
origOnClick: |
||||
| React.MouseEventHandler<HTMLAnchorElement | HTMLButtonElement> |
||||
| undefined, |
||||
onSelect: ((event: Event) => void) | undefined, |
||||
) => { |
||||
const DropdownMenuContentProps = useContext(DropdownMenuContentPropsContext); |
||||
|
||||
return composeEventHandlers(origOnClick, (event) => { |
||||
const itemSelectEvent = new CustomEvent(EVENT.MENU_ITEM_SELECT, { |
||||
bubbles: true, |
||||
cancelable: true, |
||||
}); |
||||
onSelect?.(itemSelectEvent); |
||||
if (!itemSelectEvent.defaultPrevented) { |
||||
DropdownMenuContentProps.onSelect?.(itemSelectEvent); |
||||
} |
||||
}); |
||||
}; |
||||
Loading…
Reference in new issue