import React from 'react'; import Box from '@mui/material/Box'; import Toolbar from '@mui/material/Toolbar'; import useMediaQuery from '@mui/material/useMediaQuery'; import { lighten } from '@mui/material/styles'; import { MRT_GlobalFilterTextField } from '../inputs/MRT_GlobalFilterTextField'; import { MRT_LinearProgressBar } from './MRT_LinearProgressBar'; import { MRT_TablePagination } from './MRT_TablePagination'; import { MRT_ToolbarAlertBanner } from './MRT_ToolbarAlertBanner'; import { MRT_ToolbarInternalButtons } from './MRT_ToolbarInternalButtons'; import { MRT_ToolbarDropZone } from './MRT_ToolbarDropZone'; import type { MRT_TableInstance } from '..'; import type { Theme } from '@mui/material/styles'; export const commonToolbarStyles = ({ theme }: { theme: Theme }) => ({ alignItems: 'flex-start', backgroundColor: lighten(theme.palette.background.default, 0.04), backgroundImage: 'none', display: 'grid', flexWrap: 'wrap-reverse', minHeight: '3.5rem', overflow: 'hidden', p: '0 !important', transition: 'all 150ms ease-in-out', zIndex: 1, }); interface Props = {}> { table: MRT_TableInstance; } export const MRT_TopToolbar = = {}>({ table, }: Props) => { 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 toolbarProps = muiTopToolbarProps instanceof Function ? muiTopToolbarProps({ table }) : muiTopToolbarProps; const stackAlertBanner = isMobile || !!renderTopToolbarCustomActions || showGlobalFilter; return ( { topToolbarRef.current = ref; if (toolbarProps?.ref) { // @ts-ignore toolbarProps.ref.current = ref; } }} sx={(theme) => ({ position: isFullScreen ? 'sticky' : undefined, top: isFullScreen ? '0' : undefined, ...commonToolbarStyles({ theme }), ...(toolbarProps?.sx instanceof Function ? toolbarProps.sx(theme) : (toolbarProps?.sx as any)), } as any) } > {positionToolbarAlertBanner === 'top' && ( )} {['both', 'top'].includes(positionToolbarDropZone ?? '') && ( )} {enableGlobalFilter && positionGlobalFilter === 'left' && ( )} {renderTopToolbarCustomActions?.({ table }) ?? } {enableToolbarInternalActions ? ( {enableGlobalFilter && positionGlobalFilter === 'right' && ( )} ) : ( enableGlobalFilter && positionGlobalFilter === 'right' && ( ) )} {enablePagination && ['top', 'both'].includes(positionPagination ?? '') && ( )} ); };