import React from "react"; import { buttonVariants } from "@/components/ui/button"; import { Pencil } from "lucide-react"; import type { RaRecord } from "ra-core"; import { useCreatePath, useRecordContext, useResourceContext, Translate, } from "ra-core"; import { Link } from "react-router"; export type EditButtonProps = { record?: RaRecord; resource?: string; label?: string; }; /** * A button that navigates to the edit page for a record. * * Works within RecordContext to automatically get the record ID. * * @see {@link https://marmelab.com/shadcn-admin-kit/docs/editbutton/ EditButton documentation} * * @example * import { DataTable, EditButton } from '@/components/admin'; * * const PostList = () => ( * * * * * * * * * ); */ export const EditButton = (props: EditButtonProps) => { const resource = useResourceContext(props); const record = useRecordContext(props); const createPath = useCreatePath(); const link = createPath({ resource, type: "edit", id: record?.id, }); return ( {props.label ?? "Edit"} ); }; // useful to prevent click bubbling in a datagrid with rowClick const stopPropagation = (e: React.MouseEvent) => e.stopPropagation();