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

48 lines
1.4 KiB
TypeScript
Raw Normal View History

import { faPencil, faSave } from "@fortawesome/free-solid-svg-icons"
2022-06-11 03:08:49 +00:00
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 = {
save: () => void,
2022-07-16 17:21:42 +00:00
}
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
*/
export function ToolToggleEditing({ save }: 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("toolToggleEditingSave")}
2022-07-16 17:21:42 +00:00
onClick={() => {
save()
2022-07-16 17:21:42 +00:00
setEditing(EditingMode.VIEW)
}}
2022-07-18 03:08:08 +00:00
className={"positive"}
2022-06-11 03:08:49 +00:00
>
<FestaIcon icon={faSave} />
2022-06-11 03:08:49 +00:00
</Tool>
)
}
else {
return (
<Tool
aria-label={t("toolToggleEditingEdit")}
2022-07-16 17:21:42 +00:00
onClick={() => {
setEditing(EditingMode.EDIT)
}}
2022-06-11 03:08:49 +00:00
>
<FestaIcon icon={faPencil} />
</Tool>
)
}
}