1
Fork 0
mirror of https://github.com/Steffo99/festa.git synced 2024-12-22 22:54:22 +00:00

Add some events to ToolToggleEditing

This commit is contained in:
Steffo 2022-07-16 19:21:42 +02:00
parent 5105ea9045
commit 3ce0b5698f
Signed by: steffo
GPG key ID: 6965406171929D01

View file

@ -6,10 +6,18 @@ import { FestaIcon } from "../../generic/renderers/fontawesome"
import { Tool } from "../../generic/toolbar/tool"
export type ToolToggleEditingProps = {
onViewStart?: () => void,
onViewEnd?: () => void,
onEditStart?: () => void,
onEditEnd?: () => void,
}
/**
* ToolBar {@link Tool} which switches between {@link EditingMode}s of the surrounding context.
*/
export function ToolToggleEditing() {
export function ToolToggleEditing({ onViewStart, onViewEnd, onEditStart, onEditEnd }: ToolToggleEditingProps) {
const { t } = useTranslation()
const [editing, setEditing] = useDefinedContext(EditingContext)
@ -17,7 +25,11 @@ export function ToolToggleEditing() {
return (
<Tool
aria-label={t("toggleEditingView")}
onClick={() => setEditing(EditingMode.VIEW)}
onClick={() => {
onEditEnd?.()
setEditing(EditingMode.VIEW)
onViewStart?.()
}}
>
<FestaIcon icon={faBinoculars} />
</Tool>
@ -27,7 +39,11 @@ export function ToolToggleEditing() {
return (
<Tool
aria-label={t("toggleEditingEdit")}
onClick={() => setEditing(EditingMode.EDIT)}
onClick={() => {
onViewEnd?.()
setEditing(EditingMode.EDIT)
onEditStart?.()
}}
>
<FestaIcon icon={faPencil} />
</Tool>