import { useFieldValue, useTranslate } from "ra-core"; import type { AnchorHTMLAttributes } from "react"; import React from "react"; import { cn } from "@/lib/utils"; import { genericMemo } from "@/lib/genericMemo"; import type { FieldProps } from "@/lib/field.type"; const EmailFieldImpl = < // eslint-disable-next-line @typescript-eslint/no-explicit-any RecordType extends Record = Record, >( inProps: EmailFieldProps, ) => { const { className, empty, defaultValue, source, record, ...rest } = inProps; const value = useFieldValue({ defaultValue, source, record }); const translate = useTranslate(); if (value == null) { if (!empty) { return null; } return ( {typeof empty === "string" ? translate(empty, { _: empty }) : empty} ); } return ( {value} ); }; EmailFieldImpl.displayName = "EmailFieldImpl"; /** * Displays an email address as a clickable mailto link. * * Click events are prevented from bubbling up, making it safe to use in DataTable rows with rowClick. * To be used with RecordField or DataTable.Col components, or anywhere a RecordContext is available. * * @see {@link https://marmelab.com/shadcn-admin-kit/docs/emailfield/ EmailField documentation} * * @example * import { List, DataTable, EmailField } from '@/components/admin'; * * const UserList = () => ( * * * * * * * ); */ export const EmailField = genericMemo(EmailFieldImpl); export interface EmailFieldProps< // eslint-disable-next-line @typescript-eslint/no-explicit-any RecordType extends Record = Record, > extends FieldProps, AnchorHTMLAttributes {} // useful to prevent click bubbling in a DataTable with rowClick const stopPropagation = (e: React.MouseEvent) => e.stopPropagation();