import React, { useEffect, useImperativeHandle } from "react"; import { MantineReactTable, MRT_ColumnDef, MRT_RowData, MRT_TableInstance, MRT_TableOptions, useMantineReactTable, } from "mantine-react-table"; import { MRT_Localization_RU } from "mantine-react-table/locales/ru"; type Props = { data: T[]; onSelectionChange?: (selectedRows: T[]) => void; columns: MRT_ColumnDef[]; restProps?: MRT_TableOptions; striped?: boolean | "odd" | "even"; }; export type BaseTableRef = { getTable: () => MRT_TableInstance; }; function BaseTableInner( { data, columns, restProps, onSelectionChange, striped = false }: Props, ref: React.Ref> ) { const table = useMantineReactTable({ localization: MRT_Localization_RU, enablePagination: false, data, columns, mantineTableProps: { striped, highlightOnHover: false, }, enableTopToolbar: false, enableBottomToolbar: false, enableRowSelection: onSelectionChange !== undefined, ...restProps, }); useEffect(() => { if (!onSelectionChange) return; onSelectionChange( table.getSelectedRowModel().rows.map(r => r.original) ); }, [onSelectionChange, table.getState().rowSelection]); useImperativeHandle(ref, () => ({ getTable: () => table })); return ; } const BaseTable = React.forwardRef(BaseTableInner) as ( props: Props & { ref?: React.Ref> } ) => React.ReactElement | null; export default BaseTable;