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 16:03:37 +00:00
|
|
|
* ToolBar {@link Tool} which switches between {@link EditingMode}s of the surrounding context.
|
2022-06-11 03:08:49 +00:00
|
|
|
*/
|
|
|
|
export function ToolToggleEditing() {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const [editing, setEditing] = useDefinedContext(EditingContext)
|
|
|
|
|
|
|
|
if (editing === EditingMode.EDIT) {
|
|
|
|
return (
|
|
|
|
<Tool
|
|
|
|
aria-label={t("toggleEditingView")}
|
|
|
|
onClick={() => setEditing(EditingMode.VIEW)}
|
|
|
|
>
|
|
|
|
<FestaIcon icon={faBinoculars} />
|
|
|
|
</Tool>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return (
|
|
|
|
<Tool
|
|
|
|
aria-label={t("toggleEditingEdit")}
|
|
|
|
onClick={() => setEditing(EditingMode.EDIT)}
|
|
|
|
>
|
|
|
|
<FestaIcon icon={faPencil} />
|
|
|
|
</Tool>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|