import React, { useContext } from 'react'; import classNames from 'classnames'; import { If } from 'components'; import { Skeleton } from 'components'; import { useAppIntlContext } from 'components/AppIntlProvider'; import TableContext from './TableContext'; import { saveInvoke, ignoreEventFromSelectors } from 'utils'; import { isCellLoading } from './utils'; const ROW_CLICK_SELECTORS_INGORED = ['.expand-toggle', '.selection-checkbox']; /** * Table cell. */ export default function TableCell({ cell, row, index }) { const { index: rowIndex, depth, getToggleRowExpandedProps, isExpanded } = row; const { props: { expandToggleColumn, expandColumnSpace, expandable, cellsLoading, cellsLoadingCoords, onCellClick, }, } = useContext(TableContext); const isExpandColumn = expandToggleColumn === index; const { skeletonWidthMax = 100, skeletonWidthMin = 40 } = {}; // Application intl context. const { isRTL } = useAppIntlContext(); // Detarmines whether the current cell is loading. const cellLoading = isCellLoading( cellsLoading, cellsLoadingCoords, rowIndex, cell.column.id, ); if (cellLoading) { return (
); } // Handle cell click action. const handleCellClick = (event) => { if (ignoreEventFromSelectors(event, ROW_CLICK_SELECTORS_INGORED)) { return; } saveInvoke(onCellClick, cell, event); }; return (
{ // Use the row.canExpand and row.getToggleRowExpandedProps prop getter // to build the toggle for expanding a row } {cell.render('Cell')}
); }