import { flexRender, Row as TanstackRow, Table as TanstackTable } from '@tanstack/react-table' import classNames from 'classnames' interface Props { row: TanstackRow table: TanstackTable renderExpanded?: (row: TanstackRow, table: TanstackTable) => JSX.Element rowClassName?: string spacingClassName?: string className?: string isSelectable?: boolean type?: TableType } function getBorderColor( type: TableType, row: AccountBalanceRow | AccountStrategyRow | AccountPerpRow, ) { if (type === 'strategies') return '' if (type === 'balances') { const balancesRow = row as AccountBalanceRow return balancesRow.type === 'borrow' ? 'border-loss' : 'border-profit' } const perpRow = row as AccountPerpRow return perpRow.tradeDirection === 'short' ? 'border-loss' : 'border-profit' } export default function Row(props: Props) { const { renderExpanded, table, row, type, spacingClassName, isSelectable } = props const canExpand = !!renderExpanded return ( <> { e.preventDefault() if (isSelectable) { row.toggleSelected() } if (canExpand) { const isExpanded = row.getIsExpanded() table.resetExpanded() !isExpanded && row.toggleExpanded() } }} > {row.getVisibleCells().map((cell) => { const isSymbolOrName = cell.column.id === 'symbol' || cell.column.id === 'name' return ( {flexRender(cell.column.columnDef.cell, cell.getContext())} ) })} {row.getIsExpanded() && renderExpanded && renderExpanded(row, table)} ) }