import React, { MouseEvent } from 'react'; import Checkbox from '@mui/material/Checkbox'; import Tooltip from '@mui/material/Tooltip'; import Radio from '@mui/material/Radio'; import type { Theme } from '@mui/material/styles'; import type { MRT_Row, MRT_TableInstance } from '..'; interface Props { row?: MRT_Row; selectAll?: boolean; table: MRT_TableInstance; } export const MRT_SelectCheckbox = ({ row, selectAll, table }: Props) => { const { getState, options: { localization, enableMultiRowSelection, muiSelectCheckboxProps, muiSelectAllCheckboxProps, selectAllMode, }, } = table; const { density, isLoading } = getState(); const checkboxProps = !row ? muiSelectAllCheckboxProps instanceof Function ? muiSelectAllCheckboxProps({ table }) : muiSelectAllCheckboxProps : muiSelectCheckboxProps instanceof Function ? muiSelectCheckboxProps({ row, table }) : muiSelectCheckboxProps; const allRowsSelected = selectAll ? selectAllMode === 'page' ? table.getIsAllPageRowsSelected() : table.getIsAllRowsSelected() : undefined; const commonProps = { checked: selectAll ? allRowsSelected : row?.getIsSelected(), disabled: isLoading || (row && !row.getCanSelect()), inputProps: { 'aria-label': selectAll ? localization.toggleSelectAll : localization.toggleSelectRow, }, onChange: row ? row.getToggleSelectedHandler() : selectAllMode === 'all' ? table.getToggleAllRowsSelectedHandler() : table.getToggleAllPageRowsSelectedHandler(), size: (density === 'compact' ? 'small' : 'medium') as 'small' | 'medium', ...checkboxProps, onClick: (e: MouseEvent) => { e.stopPropagation(); checkboxProps?.onClick?.(e); }, sx: (theme: Theme) => ({ height: density === 'compact' ? '1.75rem' : '2.5rem', width: density === 'compact' ? '1.75rem' : '2.5rem', m: density !== 'compact' ? '-0.4rem' : undefined, ...(checkboxProps?.sx instanceof Function ? checkboxProps.sx(theme) : (checkboxProps?.sx as any)), }), title: undefined, }; return ( {enableMultiRowSelection === false ? ( ) : ( )} ); };