import React from "react"; import { buttonVariants } from "@/components/ui/button"; import { Plus } from "lucide-react"; import { Translate, useCreatePath, useResourceContext } from "ra-core"; import { Link } from "react-router"; export type CreateButtonProps = { label?: string; resource?: string; variant?: | "default" | "destructive" | "outline" | "secondary" | "ghost" | "link"; }; /** * A button that navigates to the create page for a resource. * * Automatically uses the current resource unless overridden. * * @see {@link https://marmelab.com/shadcn-admin-kit/docs/createbutton/ CreateButton documentation} * * @example * import { CreateButton, List, ExportButton } from '@/components/admin'; * * const PostList = () => ( * * * * } * > * ... * * ); */ export const CreateButton = ({ label, resource: targetResource, variant = "outline", }: CreateButtonProps) => { const resource = useResourceContext(); const createPath = useCreatePath(); const link = createPath({ resource: targetResource ?? resource, type: "create", }); return ( {label ?? "Create"} ); }; // useful to prevent click bubbling in a datagrid with rowClick const stopPropagation = (e: React.MouseEvent) => e.stopPropagation();