import { useEffect } from 'react'; import styled from '@emotion/styled'; import { Row } from '@tanstack/table-core'; import { useRecoilState } from 'recoil'; import { RecoilScope } from '@/recoil-scope/components/RecoilScope'; import { useRecoilScopedState } from '@/recoil-scope/hooks/useRecoilScopedState'; import { CellContext } from '@/ui/tables/states/CellContext'; import { currentRowNumberScopedState } from '@/ui/tables/states/currentRowNumberScopedState'; import { RowContext } from '@/ui/tables/states/RowContext'; import { currentRowSelectionState } from '@/ui/tables/states/rowSelectionState'; import { EntityTableCell } from './EntityTableCell'; const StyledRow = styled.tr<{ selected: boolean }>` background: ${(props) => props.selected ? props.theme.background.secondary : 'none'}; `; export function EntityTableRow({ row, index, }: { row: Row; index: number; }) { const [currentRowSelection] = useRecoilState(currentRowSelectionState); const [, setCurrentRowNumber] = useRecoilScopedState( currentRowNumberScopedState, RowContext, ); useEffect(() => { setCurrentRowNumber(index); }, [index, setCurrentRowNumber]); return ( {row.getVisibleCells().map((cell, cellIndex) => { return ( row={row} cell={cell} cellIndex={cellIndex} /> ); })} ); }