import { type MouseEvent } from 'react'; import IconButton, { type IconButtonProps } from '@mui/material/IconButton'; import Tooltip from '@mui/material/Tooltip'; import { useTheme } from '@mui/material/styles'; import { type MRT_Row, type MRT_RowData, type MRT_TableInstance, } from '../../types'; import { getCommonTooltipProps } from '../../utils/style.utils'; import { parseFromValuesOrFunc } from '../../utils/utils'; export interface MRT_ExpandButtonProps extends IconButtonProps { row: MRT_Row; staticRowIndex?: number; table: MRT_TableInstance; } export const MRT_ExpandButton = ({ row, staticRowIndex, table, }: MRT_ExpandButtonProps) => { const theme = useTheme(); const { getState, options: { icons: { ExpandMoreIcon }, localization, muiExpandButtonProps, positionExpandColumn, renderDetailPanel, }, } = table; const { density } = getState(); const iconButtonProps = parseFromValuesOrFunc(muiExpandButtonProps, { row, staticRowIndex, table, }); const canExpand = row.getCanExpand(); const isExpanded = row.getIsExpanded(); const handleToggleExpand = (event: MouseEvent) => { event.stopPropagation(); row.toggleExpanded(); iconButtonProps?.onClick?.(event); }; const detailPanel = !!renderDetailPanel?.({ row, table }); return ( ({ height: density === 'compact' ? '1.75rem' : '2.25rem', opacity: !canExpand && !detailPanel ? 0.3 : 1, [theme.direction === 'rtl' || positionExpandColumn === 'last' ? 'mr' : 'ml']: `${row.depth * 16}px`, width: density === 'compact' ? '1.75rem' : '2.25rem', ...(parseFromValuesOrFunc(iconButtonProps?.sx, theme) as any), })} title={undefined} > {iconButtonProps?.children ?? ( )} ); };