import { Flex, Modal, type ModalProps, Stack } from '@mantine/core'; import { type MRT_Row, type MRT_RowData, type MRT_TableInstance, } from '../../types'; import { parseFromValuesOrFunc } from '../../utils/utils'; import { MRT_EditActionButtons } from '../buttons/MRT_EditActionButtons'; import { MRT_EditCellTextInput } from '../inputs/MRT_EditCellTextInput'; interface Props extends Partial { open: boolean; table: MRT_TableInstance; } export const MRT_EditRowModal = ({ open, table, ...rest }: Props) => { 'use no memo'; const { getState, options: { mantineCreateRowModalProps, mantineEditRowModalProps, onCreatingRowCancel, onEditingRowCancel, renderCreateRowModalContent, renderEditRowModalContent, }, setCreatingRow, setEditingRow, } = table; const { creatingRow, editingRow } = getState(); const row = (creatingRow ?? editingRow) as MRT_Row; const arg = { row, table }; const modalProps = { ...parseFromValuesOrFunc(mantineEditRowModalProps, arg), ...(creatingRow && parseFromValuesOrFunc(mantineCreateRowModalProps, arg)), ...rest, }; const internalEditComponents = row .getAllCells() .filter((cell) => cell.column.columnDef.columnDefType === 'data') .map((cell) => ( )); const handleCancel = () => { if (creatingRow) { onCreatingRowCancel?.({ row, table }); setCreatingRow(null); } else { onEditingRowCancel?.({ row, table }); setEditingRow(null); } row._valuesCache = {} as any; //reset values cache modalProps.onClose?.(); }; return ( {((creatingRow && renderCreateRowModalContent?.({ internalEditComponents, row, table, })) || renderEditRowModalContent?.({ internalEditComponents, row, table, })) ?? ( <>
e.preventDefault()}> {internalEditComponents}
)}
); };