1
Fork 0
mirror of https://github.com/Steffo99/festa.git synced 2024-12-23 15:14:23 +00:00
festa/components/events/toolbar/toolToggleEditing.tsx

53 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-06-11 03:08:49 +00:00
import { faBinoculars, faPencil } from "@fortawesome/free-solid-svg-icons"
import { useTranslation } from "next-i18next"
import { useDefinedContext } from "../../../utils/definedContext"
import { EditingContext, EditingMode } from "../../generic/editable/base"
import { FestaIcon } from "../../generic/renderers/fontawesome"
import { Tool } from "../../generic/toolbar/tool"
2022-07-16 17:21:42 +00:00
export type ToolToggleEditingProps = {
onViewStart?: () => void,
onViewEnd?: () => void,
onEditStart?: () => void,
onEditEnd?: () => void,
}
2022-06-11 03:08:49 +00:00
/**
* ToolBar {@link Tool} which switches between {@link EditingMode}s of the surrounding context.
2022-06-11 03:08:49 +00:00
*/
2022-07-16 17:21:42 +00:00
export function ToolToggleEditing({ onViewStart, onViewEnd, onEditStart, onEditEnd }: ToolToggleEditingProps) {
2022-06-11 03:08:49 +00:00
const { t } = useTranslation()
const [editing, setEditing] = useDefinedContext(EditingContext)
if (editing === EditingMode.EDIT) {
return (
<Tool
aria-label={t("toggleEditingView")}
2022-07-16 17:21:42 +00:00
onClick={() => {
onEditEnd?.()
setEditing(EditingMode.VIEW)
onViewStart?.()
}}
2022-06-11 03:08:49 +00:00
>
<FestaIcon icon={faBinoculars} />
</Tool>
)
}
else {
return (
<Tool
aria-label={t("toggleEditingEdit")}
2022-07-16 17:21:42 +00:00
onClick={() => {
onViewEnd?.()
setEditing(EditingMode.EDIT)
onEditStart?.()
}}
2022-06-11 03:08:49 +00:00
>
<FestaIcon icon={faPencil} />
</Tool>
)
}
}