All files / src/widgets/toolbar/ui UndoButton.tsx

66.66% Statements 2/3
100% Branches 2/2
50% Functions 1/2
66.66% Lines 2/3

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            3x 3x                                    
import { Undo2 } from 'lucide-react';
import { useAppDispatch, useAppSelector } from '@/store/hooks';
import { selectCanUndo } from '@/entities/history/model/selectors';
import { undo } from '@/entities/history/model/slice';
 
export function UndoButton() {
	const dispatch = useAppDispatch();
	const canUndo = useAppSelector(selectCanUndo);
 
	return (
		<button
			onClick={() => dispatch(undo())}
			disabled={!canUndo}
			className={`p-2 rounded transition-colors ${
				canUndo
					? 'bg-gray-100 hover:bg-gray-200'
					: 'bg-gray-50 text-gray-400 cursor-not-allowed'
			}`}
			aria-label="Undo"
			title="Undo (Ctrl+Z)"
		>
			<Undo2 className="w-4 h-4" />
		</button>
	);
}