import clsx from 'clsx'; import classes from './MRT_TableContainer.module.css'; import { useEffect, useLayoutEffect, useState } from 'react'; import { Box, type BoxProps, LoadingOverlay } from '@mantine/core'; import { MRT_Table } from './MRT_Table'; import { type MRT_RowData, type MRT_TableInstance } from '../../types'; import { parseFromValuesOrFunc } from '../../utils/utils'; import { MRT_EditRowModal } from '../modals/MRT_EditRowModal'; const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect; interface Props extends BoxProps { table: MRT_TableInstance; } export const MRT_TableContainer = ({ table, ...rest }: Props) => { 'use no memo'; const { getState, options: { createDisplayMode, editDisplayMode, enableStickyHeader, mantineLoadingOverlayProps, mantineTableContainerProps, }, refs: { bottomToolbarRef, tableContainerRef, topToolbarRef }, } = table; const { creatingRow, editingRow, isFullScreen, isLoading, showLoadingOverlay, } = getState(); const [totalToolbarHeight, setTotalToolbarHeight] = useState(0); const tableContainerProps = { ...parseFromValuesOrFunc(mantineTableContainerProps, { table }), ...rest, }; const loadingOverlayProps = parseFromValuesOrFunc( mantineLoadingOverlayProps, { table }, ); useIsomorphicLayoutEffect(() => { const topToolbarHeight = typeof document !== 'undefined' ? (topToolbarRef.current?.offsetHeight ?? 0) : 0; const bottomToolbarHeight = typeof document !== 'undefined' ? (bottomToolbarRef?.current?.offsetHeight ?? 0) : 0; setTotalToolbarHeight(topToolbarHeight + bottomToolbarHeight); }); const createModalOpen = createDisplayMode === 'modal' && creatingRow; const editModalOpen = editDisplayMode === 'modal' && editingRow; return ( { if (node) { tableContainerRef.current = node; if (tableContainerProps?.ref) { //@ts-ignore tableContainerProps.ref.current = node; } } }} > {(createModalOpen || editModalOpen) && ( )} ); };