movie-web/src/components/buttons/EditButton.tsx
mrjvs bc22c323a0 fix savebar still persisting + fix stopEditing translation key
Co-authored-by: Jip Frijlink <JipFr@users.noreply.github.com>
2023-11-29 17:42:51 +01:00

38 lines
1.0 KiB
TypeScript

import { useAutoAnimate } from "@formkit/auto-animate/react";
import { useCallback } from "react";
import { useTranslation } from "react-i18next";
import { Icon, Icons } from "@/components/Icon";
export interface EditButtonProps {
editing: boolean;
onEdit?: (editing: boolean) => void;
}
export function EditButton(props: EditButtonProps) {
const { t } = useTranslation();
const [parent] = useAutoAnimate<HTMLSpanElement>();
const onClick = useCallback(() => {
props.onEdit?.(!props.editing);
}, [props]);
return (
<button
type="button"
onClick={onClick}
className="flex h-12 items-center overflow-hidden rounded-full bg-background-secondary px-4 py-2 text-white transition-[background-color,transform] hover:bg-background-secondaryHover active:scale-105"
>
<span ref={parent}>
{props.editing ? (
<span className="mx-4 whitespace-nowrap">
{t("home.mediaList.stopEditing")}
</span>
) : (
<Icon icon={Icons.EDIT} />
)}
</span>
</button>
);
}