import React, { DragEvent, useEffect } from 'react'; import { alpha } from '@mui/material/styles'; import Box from '@mui/material/Box'; import Fade from '@mui/material/Fade'; import Typography from '@mui/material/Typography'; import type { MRT_TableInstance } from '..'; interface Props = {}> { table: MRT_TableInstance; } export const MRT_ToolbarDropZone = = {}>({ table, }: Props) => { const { getState, options: { enableGrouping, localization }, setHoveredColumn, setShowToolbarDropZone, } = table; const { draggingColumn, hoveredColumn, grouping, showToolbarDropZone } = getState(); const handleDragEnter = (_event: DragEvent) => { setHoveredColumn({ id: 'drop-zone' }); }; useEffect(() => { if (table.options.state?.showToolbarDropZone !== undefined) { setShowToolbarDropZone( !!enableGrouping && !!draggingColumn && !grouping.includes(draggingColumn.id), ); } }, [enableGrouping, draggingColumn, grouping]); return ( ({ alignItems: 'center', backgroundColor: alpha( theme.palette.info.main, hoveredColumn?.id === 'drop-zone' ? 0.2 : 0.1, ), backdropFilter: 'blur(4px)', boxSizing: 'border-box', border: `dashed ${theme.palette.info.main} 2px`, display: 'flex', justifyContent: 'center', height: '100%', position: 'absolute', width: '100%', zIndex: 4, })} onDragEnter={handleDragEnter} > {localization.dropToGroupBy.replace( '{column}', draggingColumn?.columnDef?.header ?? '', )} ); };