mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-04-23 03:00:31 -04:00
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import { IconButton } from '@invoke-ai/ui-library';
|
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
|
import { toolChanged } from 'features/controlLayers/store/canvasV2Slice';
|
|
import { isDrawableEntityType } from 'features/controlLayers/store/types';
|
|
import { memo, useCallback } from 'react';
|
|
import { useHotkeys } from 'react-hotkeys-hook';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { PiEraserBold } from 'react-icons/pi';
|
|
|
|
export const EraserToolButton = memo(() => {
|
|
const { t } = useTranslation();
|
|
const dispatch = useAppDispatch();
|
|
const isSelected = useAppSelector((s) => s.canvasV2.tool.selected === 'eraser');
|
|
const isDisabled = useAppSelector((s) => {
|
|
const entityType = s.canvasV2.selectedEntityIdentifier?.type;
|
|
const isDrawingToolAllowed = entityType ? isDrawableEntityType(entityType) : false;
|
|
const isStaging = s.canvasV2.session.isStaging;
|
|
return !isDrawingToolAllowed || isStaging;
|
|
});
|
|
|
|
const onClick = useCallback(() => {
|
|
dispatch(toolChanged('eraser'));
|
|
}, [dispatch]);
|
|
|
|
useHotkeys('e', onClick, { enabled: !isDisabled }, [isDisabled, onClick]);
|
|
|
|
return (
|
|
<IconButton
|
|
aria-label={`${t('unifiedCanvas.eraser')} (E)`}
|
|
tooltip={`${t('unifiedCanvas.eraser')} (E)`}
|
|
icon={<PiEraserBold />}
|
|
variant={isSelected ? 'solid' : 'outline'}
|
|
onClick={onClick}
|
|
isDisabled={isDisabled}
|
|
/>
|
|
);
|
|
});
|
|
|
|
EraserToolButton.displayName = 'EraserToolButton';
|