All files / src/entities/eraser/ui EraserTool.tsx

83.33% Statements 5/6
100% Branches 2/2
50% Functions 1/2
83.33% Lines 5/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32                  3x 3x 3x 3x   3x                                  
import { Eraser } from 'lucide-react';
import { ToolButton } from '@/widgets/toolbar/ui';
import { EraserFloatingPalette } from './EraserFloatingPalette';
import { useAppDispatch, useAppSelector } from '@/store/hooks';
import { setActiveTool } from '@/entities/editor/model/slice';
import { selectActiveTool, selectPaletteOpen } from '@/entities/editor/model/selectors';
import { TOOLS, UI_LABELS } from '@/shared/constants';
 
export function EraserTool() {
	const dispatch = useAppDispatch();
	const activeTool = useAppSelector(selectActiveTool);
	const paletteOpen = useAppSelector(selectPaletteOpen);
	const isActive = activeTool === TOOLS.ERASER;
 
	const handleClick = () => {
		dispatch(setActiveTool(TOOLS.ERASER));
	};
 
	return (
		<>
			<ToolButton
				data-testid="eraser-tool-button"
				icon={<Eraser className="w-5 h-5" />}
				label={UI_LABELS.ERASER_TOOL}
				active={isActive}
				onClick={handleClick}
			/>
			{isActive && paletteOpen && <EraserFloatingPalette />}
		</>
	);
}