import {Fragment} from 'react'; import {ActionIcon, Alert, Badge, Collapse, Flex, Stack} from '@mantine/core'; import {type MRT_TableInstance} from '../types'; import {MRT_SelectCheckbox} from '../inputs'; interface Props = {}> { stackAlertBanner?: boolean; table: MRT_TableInstance; } export const MRT_ToolbarAlertBanner = = {}>({stackAlertBanner, table,}: Props) => { const { getPrePaginationRowModel, getSelectedRowModel, getState, options: { enableRowSelection, enableSelectAll, icons: {IconX}, localization, mantineToolbarAlertBannerBadgeProps, mantineToolbarAlertBannerProps, positionToolbarAlertBanner, renderToolbarAlertBannerContent, rowCount, }, } = table; const {grouping, showAlertBanner} = getState(); const alertProps = mantineToolbarAlertBannerProps instanceof Function ? mantineToolbarAlertBannerProps({table}) : mantineToolbarAlertBannerProps; const badgeProps = mantineToolbarAlertBannerBadgeProps instanceof Function ? mantineToolbarAlertBannerBadgeProps({table}) : mantineToolbarAlertBannerBadgeProps; const selectedAlert = getSelectedRowModel().rows.length > 0 ? localization.selectedCountOfRowCountRowsSelected ?.replace( '{selectedCount}', getSelectedRowModel().rows.length.toString(), ) ?.replace( '{rowCount}', (rowCount ?? getPrePaginationRowModel().rows.length).toString(), ) : null; const groupedAlert = grouping.length > 0 ? ( {localization.groupedBy}{' '} {grouping.map((columnId, index) => ( {index > 0 ? localization.thenBy : ''} table.getColumn(columnId).toggleGrouping()} size="xs" color="blue" radius="xl" variant="transparent" > } sx={{marginLeft: '1ch'}} variant="outline" {...badgeProps} > {table.getColumn(columnId).columnDef.header}{' '} ))} ) : null; return ( ({ borderRadius: 0, left: 0, position: 'relative', right: 0, top: 0, width: '100%', padding: "0 1rem", alignItems: "center", display: "flex", borderBottom: `1px solid ${theme.colors.gray[theme.colorScheme === 'dark' ? 8 : 3]}`, zIndex: 2, minHeight: "2.25rem", ...(alertProps?.sx instanceof Function ? alertProps.sx(theme) : (alertProps?.sx as any)), })} > {renderToolbarAlertBannerContent?.({ groupedAlert, selectedAlert, table, }) ?? ( {enableRowSelection && enableSelectAll && positionToolbarAlertBanner === 'head-overlay' && ( )} {alertProps?.children} {alertProps?.children && (selectedAlert || groupedAlert) && (
)} {selectedAlert} {selectedAlert && groupedAlert &&
} {groupedAlert}
)}
); };