import * as React from 'react'; import { getCellLinks } from '../../utils'; import { DataLinksContextMenu } from '../DataLinks/DataLinksContextMenu'; import { TableCellDisplayMode, TableCellProps } from './types'; import { getCellOptions } from './utils'; const DATALINKS_HEIGHT_OFFSET = 10; export const ImageCell = (props: TableCellProps) => { const { field, cell, tableStyles, row, cellProps } = props; const cellOptions = getCellOptions(field); const { title, alt } = cellOptions.type === TableCellDisplayMode.Image ? cellOptions : { title: undefined, alt: undefined }; const displayValue = field.display!(cell.value); const hasLinks = Boolean(getCellLinks(field, row)?.length); // The image element const img = ( {alt} ); return (
{/* If there are no links we simply render the image */} {!hasLinks && img} {/* Otherwise render data links with image */} {hasLinks && ( getCellLinks(field, row) || []} > {(api) => { if (api.openMenu) { return (
{ if (e.key === 'Enter' && api.openMenu) { // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions api.openMenu(e as any); } }} > {img}
); } else { return img; } }}
)}
); };