2023-01-19 22:29:56 +01:00
|
|
|
import { useAutoAnimate } from "@formkit/auto-animate/react";
|
|
|
|
import { useCallback } from "react";
|
2023-02-18 20:01:19 +01:00
|
|
|
import { useTranslation } from "react-i18next";
|
2023-04-24 18:41:54 +03:00
|
|
|
|
|
|
|
import { Icon, Icons } from "@/components/Icon";
|
|
|
|
|
2023-01-19 22:29:56 +01:00
|
|
|
export interface EditButtonProps {
|
|
|
|
editing: boolean;
|
|
|
|
onEdit?: (editing: boolean) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function EditButton(props: EditButtonProps) {
|
2023-02-19 18:03:54 +01:00
|
|
|
const { t } = useTranslation();
|
2023-01-19 22:29:56 +01:00
|
|
|
const [parent] = useAutoAnimate<HTMLSpanElement>();
|
|
|
|
|
|
|
|
const onClick = useCallback(() => {
|
|
|
|
props.onEdit?.(!props.editing);
|
|
|
|
}, [props]);
|
|
|
|
|
|
|
|
return (
|
2023-11-26 16:04:23 +01:00
|
|
|
<button
|
|
|
|
type="button"
|
2023-01-19 22:29:56 +01:00
|
|
|
onClick={onClick}
|
2023-11-24 17:11:00 +01:00
|
|
|
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"
|
2023-01-19 22:29:56 +01:00
|
|
|
>
|
|
|
|
<span ref={parent}>
|
|
|
|
{props.editing ? (
|
2023-02-19 18:03:54 +01:00
|
|
|
<span className="mx-4 whitespace-nowrap">
|
2023-11-29 17:42:51 +01:00
|
|
|
{t("home.mediaList.stopEditing")}
|
2023-02-19 18:03:54 +01:00
|
|
|
</span>
|
2023-01-19 22:29:56 +01:00
|
|
|
) : (
|
|
|
|
<Icon icon={Icons.EDIT} />
|
|
|
|
)}
|
|
|
|
</span>
|
2023-11-26 16:04:23 +01:00
|
|
|
</button>
|
2023-01-19 22:29:56 +01:00
|
|
|
);
|
|
|
|
}
|