import Box from '@mui/material/Box'; import useMediaQuery from '@mui/material/useMediaQuery'; import { MRT_LinearProgressBar } from './MRT_LinearProgressBar'; import { MRT_TablePagination } from './MRT_TablePagination'; import { MRT_ToolbarAlertBanner } from './MRT_ToolbarAlertBanner'; import { MRT_ToolbarDropZone } from './MRT_ToolbarDropZone'; import { MRT_ToolbarInternalButtons } from './MRT_ToolbarInternalButtons'; import { type MRT_RowData, type MRT_TableInstance } from '../../types'; import { getCommonToolbarStyles } from '../../utils/style.utils'; import { parseFromValuesOrFunc } from '../../utils/utils'; import { MRT_GlobalFilterTextField } from '../inputs/MRT_GlobalFilterTextField'; export interface MRT_TopToolbarProps { table: MRT_TableInstance; } export const MRT_TopToolbar = ({ table, }: MRT_TopToolbarProps) => { const { getState, options: { enableGlobalFilter, enablePagination, enableToolbarInternalActions, muiTopToolbarProps, positionGlobalFilter, positionPagination, positionToolbarAlertBanner, positionToolbarDropZone, renderTopToolbarCustomActions, }, refs: { topToolbarRef }, } = table; const { isFullScreen, showGlobalFilter } = getState(); const isMobile = useMediaQuery('(max-width:720px)'); const isTablet = useMediaQuery('(max-width:1024px)'); const toolbarProps = parseFromValuesOrFunc(muiTopToolbarProps, { table }); const stackAlertBanner = isMobile || !!renderTopToolbarCustomActions || (showGlobalFilter && isTablet); const globalFilterProps = { sx: !isTablet ? { zIndex: 2, } : undefined, table, }; return ( { topToolbarRef.current = ref; if (toolbarProps?.ref) { // @ts-expect-error toolbarProps.ref.current = ref; } }} sx={(theme) => ({ ...getCommonToolbarStyles({ table, theme }), position: isFullScreen ? 'sticky' : 'relative', top: isFullScreen ? '0' : undefined, ...(parseFromValuesOrFunc(toolbarProps?.sx, theme) as any), })} > {positionToolbarAlertBanner === 'top' && ( )} {['both', 'top'].includes(positionToolbarDropZone ?? '') && ( )} {enableGlobalFilter && positionGlobalFilter === 'left' && ( )} {renderTopToolbarCustomActions?.({ table }) ?? } {enableToolbarInternalActions ? ( {enableGlobalFilter && positionGlobalFilter === 'right' && ( )} ) : ( enableGlobalFilter && positionGlobalFilter === 'right' && ( ) )} {enablePagination && ['both', 'top'].includes(positionPagination ?? '') && ( )} ); };