2021-04-12 13:32:25 +00:00
|
|
|
import React from "react";
|
2023-02-17 18:25:28 +00:00
|
|
|
import { DEFAULT_EMPTY_CELL_VALUE } from "utilities/constants";
|
2021-02-11 16:22:22 +00:00
|
|
|
|
2021-03-03 16:51:39 +00:00
|
|
|
interface ITextCellProps {
|
2023-03-23 16:32:32 +00:00
|
|
|
value?: string | number | boolean | { timeString: string };
|
2023-01-05 15:08:27 +00:00
|
|
|
formatter?: (val: any) => JSX.Element | string; // string, number, or null
|
2022-08-15 22:47:07 +00:00
|
|
|
greyed?: boolean;
|
2022-04-07 19:12:38 +00:00
|
|
|
classes?: string;
|
2021-03-03 16:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-22 15:34:45 +00:00
|
|
|
const TextCell = ({
|
|
|
|
|
value,
|
|
|
|
|
formatter = (val) => val, // identity function if no formatter is provided
|
|
|
|
|
greyed,
|
2022-04-11 20:21:34 +00:00
|
|
|
classes = "w250",
|
2021-10-22 15:34:45 +00:00
|
|
|
}: ITextCellProps): JSX.Element => {
|
2021-07-26 17:07:27 +00:00
|
|
|
let val = value;
|
|
|
|
|
|
|
|
|
|
if (typeof value === "boolean") {
|
|
|
|
|
val = value.toString();
|
|
|
|
|
}
|
2023-03-23 16:32:46 +00:00
|
|
|
if (!val) {
|
|
|
|
|
greyed = true;
|
|
|
|
|
}
|
2022-04-07 19:12:38 +00:00
|
|
|
return (
|
2022-08-15 22:47:07 +00:00
|
|
|
<span className={`text-cell ${classes} ${greyed && "grey-cell"}`}>
|
2023-02-17 18:25:28 +00:00
|
|
|
{formatter(val) || DEFAULT_EMPTY_CELL_VALUE}
|
2022-04-07 19:12:38 +00:00
|
|
|
</span>
|
|
|
|
|
);
|
2021-02-11 16:22:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default TextCell;
|