-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/
DatagridCell.tsx
44 lines (39 loc) · 1.3 KB
/
DatagridCell.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import * as React from 'react';
import PropTypes from 'prop-types';
import TableCell, { TableCellProps } from '@material-ui/core/TableCell';
import classnames from 'classnames';
import { Record } from 'ra-core';
const DatagridCell = React.forwardRef<HTMLTableCellElement, DatagridCellProps>(
({ className, field, record, basePath, resource, ...rest }, ref) => (
<TableCell
className={classnames(className, field.props.cellClassName)}
align={field.props.textAlign}
ref={ref}
{...rest}
>
{React.cloneElement(field, {
record,
basePath: field.props.basePath || basePath,
resource,
})}
</TableCell>
)
);
DatagridCell.propTypes = {
className: PropTypes.string,
field: PropTypes.element,
// @ts-ignore
record: PropTypes.object, // eslint-disable-line react/forbid-prop-types
basePath: PropTypes.string,
resource: PropTypes.string,
};
export interface DatagridCellProps extends TableCellProps {
basePath?: string;
className?: string;
field?: JSX.Element;
record?: Record;
resource?: string;
}
// What? TypeScript loses the displayName if we don't set it explicitly
DatagridCell.displayName = 'DatagridCell';
export default DatagridCell;