import React, { useContext } from "react" import { Getter, Row } from "@tanstack/react-table" import { GenericObject } from "../../types" import { GlobalProps } from "../../utilities/globalProps" import Flex from "../../pb_flex/_flex" import FlexItem from "../../pb_flex/_flex_item" import Icon from "../../pb_icon/_icon" import AdvancedTableContext from "../Context/AdvancedTableContext" interface CustomCellProps { getValue?: Getter onRowToggleClick?: (arg: Row) => void row: Row value?: string customRenderer?: (row: Row, value: string | undefined) => React.ReactNode } export const CustomCell = ({ getValue, onRowToggleClick, row, value, customRenderer, }: CustomCellProps & GlobalProps) => { const { setExpanded, expanded, expandedControl, inlineRowLoading } = useContext(AdvancedTableContext); const handleOnExpand = (row: Row) => { onRowToggleClick && onRowToggleClick(row); if (!expandedControl) { setExpanded({ ...expanded, [row.id]: !row.getIsExpanded() }); } }; const RowHasChildren = row.original.children ? true : false const renderButton = inlineRowLoading ? RowHasChildren : row.getCanExpand() return (
{renderButton ? ( ) : null} {row.depth === 0 ? ( customRenderer ? customRenderer(row, getValue()) : getValue() ) :( customRenderer ? customRenderer(row, value) : value ) }
) }