import { Flex, Modal, Stack, Text } from '@mantine/core'; import { MRT_EditActionButtons } from '../buttons/MRT_EditActionButtons'; import { MRT_EditCellTextInput } from '../inputs/MRT_EditCellTextInput'; import { type MRT_Row, type MRT_TableInstance } from '../types'; interface Props = {}> { open: boolean; table: MRT_TableInstance; } export const MRT_EditRowModal = = {}>({ open, table, }: Props) => { const { getState, options: { localization, onEditingRowCancel, onCreatingRowCancel, renderEditRowModalContent, renderCreateRowModalContent, mantineCreateRowModalProps, mantineEditRowModalProps, }, setEditingRow, setCreatingRow, } = table; const { creatingRow, editingRow } = getState(); const row = (creatingRow ?? editingRow) as MRT_Row; const createModalProps = mantineCreateRowModalProps instanceof Function ? mantineCreateRowModalProps({ row, table }) : mantineCreateRowModalProps; const editModalProps = mantineEditRowModalProps instanceof Function ? mantineEditRowModalProps({ row, table }) : mantineEditRowModalProps; const modalProps = { ...editModalProps, ...(creatingRow && createModalProps), }; const internalEditComponents = row .getAllCells() .filter((cell) => cell.column.columnDef.columnDefType === 'data') .map((cell) => ( )); return ( { if (creatingRow) { onCreatingRowCancel?.({ row, table }); setCreatingRow(null); } else { onEditingRowCancel?.({ row, table }); setEditingRow(null); } }} opened={open} withCloseButton={false} {...modalProps} key={row.id} > {((creatingRow && renderCreateRowModalContent?.({ row, table, internalEditComponents, })) || renderEditRowModalContent?.({ row, table, internalEditComponents, })) ?? ( <> {(creatingRow && localization.create) || localization.edit}
e.preventDefault()}> {internalEditComponents}
)}
); };