All files / src/entities/brush/ui BrushTool.tsx

85.71% Statements 6/7
100% Branches 2/2
50% Functions 1/2
85.71% Lines 6/7

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 33                  2x 3x 3x 3x 3x   3x                                  
import React from 'react';
import { Brush } from 'lucide-react';
import { TOOLS, UI_LABELS } from '@/shared/constants';
import { ToolButton } from '@/widgets/toolbar/ui';
import { BrushFloatingPalette } from '@/entities/brush/model';
import { setActiveTool } from '@/entities/editor/model/slice';
import { useAppDispatch, useAppSelector } from '@/store/hooks';
import { selectActiveTool, selectPaletteOpen } from '@/entities/editor/model/selectors';
 
export const BrushTool = React.memo(function BrushTool() {
	const dispatch = useAppDispatch();
	const activeTool = useAppSelector(selectActiveTool);
	const paletteOpen = useAppSelector(selectPaletteOpen);
	const isActive = activeTool === TOOLS.BRUSH;
 
	const handleClick = () => {
		dispatch(setActiveTool(TOOLS.BRUSH));
	};
 
	return (
		<>
			<ToolButton
				data-testid="brush-tool-button"
				icon={<Brush className="w-5 h-5" />}
				label={UI_LABELS.BRUSH_TOOL}
				active={isActive}
				onClick={handleClick}
			/>
			{isActive && paletteOpen && <BrushFloatingPalette />}
		</>
	);
});