import { HTMLAttributes, ReactNode } from "react"; import { useRecordContext } from "ra-core"; import { FieldProps } from "@/lib/field.type"; /** * Field using a render function to display the value. * * @example * `${record.first_name} ${record.last_name}`} /> */ export const FunctionField = < RecordType extends Record = Record, >({ className, record: recordProps, render, source, ...rest }: FunctionFieldProps) => { const record = useRecordContext(recordProps); if (!record) return null; return ( {render(record, source)} ); }; export interface FunctionFieldProps< RecordType extends Record = Record, > extends Omit, "source">, HTMLAttributes { render: (record: RecordType, source?: string) => ReactNode; source?: string; }