import React, { Fragment } from 'react'; import Alert from '@mui/material/Alert'; import AlertTitle from '@mui/material/AlertTitle'; import Box from '@mui/material/Box'; import Chip from '@mui/material/Chip'; import Collapse from '@mui/material/Collapse'; import type { MRT_TableInstance } from '..'; interface Props = {}> { stackAlertBanner: boolean; table: MRT_TableInstance; } export const MRT_ToolbarAlertBanner = = {}>({ stackAlertBanner, table, }: Props) => { const { getPrePaginationRowModel, getSelectedRowModel, getState, options: { localization, muiToolbarAlertBannerProps, muiToolbarAlertBannerChipProps, positionToolbarAlertBanner, rowCount, }, } = table; const { grouping, showAlertBanner, hideSelectBanner } = getState(); const alertProps = muiToolbarAlertBannerProps instanceof Function ? muiToolbarAlertBannerProps({ table }) : muiToolbarAlertBannerProps; const chipProps = muiToolbarAlertBannerChipProps instanceof Function ? muiToolbarAlertBannerChipProps({ table }) : muiToolbarAlertBannerChipProps; const selectMessage = getSelectedRowModel().rows.length > 0 ? localization.selectedCountOfRowCountRowsSelected ?.replace( '{selectedCount}', getSelectedRowModel().rows.length.toString(), ) ?.replace( '{rowCount}', (rowCount ?? getPrePaginationRowModel().rows.length).toString(), ) : null; const groupedByMessage = grouping.length > 0 ? ( {localization.groupedBy}{' '} {grouping.map((columnId, index) => ( {index > 0 ? localization.thenBy : ''} table.getColumn(columnId).toggleGrouping()} {...chipProps} /> ))} ) : null; return ( ({ borderRadius: 0, fontSize: '1rem', left: 0, p: 0, position: 'relative', mb: stackAlertBanner ? 0 : positionToolbarAlertBanner === 'bottom' ? '-1rem' : undefined, right: 0, top: 0, width: '100%', zIndex: 2, ...(alertProps?.sx instanceof Function ? alertProps.sx(theme) : (alertProps?.sx as any)), })} > {alertProps?.title && {alertProps.title}} {alertProps?.children} {alertProps?.children && (selectMessage || groupedByMessage) && (
)} {selectMessage} {selectMessage && groupedByMessage &&
} {groupedByMessage}
); };