import { Fragment } from 'react'; import { ActionIcon, Alert, Badge, Box, Collapse, Flex } from '@mantine/core'; import { type MRT_TableInstance } from '../types'; interface Props = {}> { stackAlertBanner: boolean; table: MRT_TableInstance; } export const MRT_ToolbarAlertBanner = = {}>({ stackAlertBanner, table, }: Props) => { const { getPrePaginationRowModel, getSelectedRowModel, getState, options: { icons: { IconX }, localization, mantineToolbarAlertBannerProps, mantineToolbarAlertBannerBadgeProps, positionToolbarAlertBanner, rowCount, }, } = table; const { grouping, showAlertBanner } = getState(); const alertProps = mantineToolbarAlertBannerProps instanceof Function ? mantineToolbarAlertBannerProps({ table }) : mantineToolbarAlertBannerProps; const badgeProps = mantineToolbarAlertBannerBadgeProps instanceof Function ? mantineToolbarAlertBannerBadgeProps({ table }) : mantineToolbarAlertBannerBadgeProps; 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()} size="xs" > } sx={{ marginLeft: '1ch' }} variant="filled" {...badgeProps} > {table.getColumn(columnId).columnDef.header}{' '} ))} ) : null; return ( ({ borderRadius: 0, fontSize: '16px', left: 0, position: 'relative', marginBottom: stackAlertBanner ? 0 : positionToolbarAlertBanner === 'bottom' ? '-16px' : undefined, padding: '8px', 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}
); };