diff --git a/packages/feedback/src/screenshot/components/CropIcon.tsx b/packages/feedback/src/screenshot/components/CropIcon.tsx new file mode 100644 index 000000000000..2f4dcc61ca6a --- /dev/null +++ b/packages/feedback/src/screenshot/components/CropIcon.tsx @@ -0,0 +1,23 @@ +import type { VNode, h as hType } from 'preact'; + +interface FactoryParams { + h: typeof hType; +} + +export default function CropIconFactory({ + h, // eslint-disable-line @typescript-eslint/no-unused-vars +}: FactoryParams) { + return function CropIcon(): VNode { + return ( + + + + ); + }; +} diff --git a/packages/feedback/src/screenshot/components/ScreenshotEditor.tsx b/packages/feedback/src/screenshot/components/ScreenshotEditor.tsx index e242415c0903..b38f69cb76a8 100644 --- a/packages/feedback/src/screenshot/components/ScreenshotEditor.tsx +++ b/packages/feedback/src/screenshot/components/ScreenshotEditor.tsx @@ -6,6 +6,7 @@ import { h } from 'preact'; // eslint-disable-line @typescript-eslint/no-unused- import type * as Hooks from 'preact/hooks'; import { DOCUMENT, WINDOW } from '../../constants'; import CropCornerFactory from './CropCorner'; +import CropIconFactory from './CropIcon'; import PenIconFactory from './PenIcon'; import { createScreenshotInputStyles } from './ScreenshotInput.css'; import { useTakeScreenshotFactory } from './useTakeScreenshot'; @@ -75,6 +76,7 @@ export function ScreenshotEditorFactory({ const useTakeScreenshot = useTakeScreenshotFactory({ hooks }); const CropCorner = CropCornerFactory({ h }); const PenIcon = PenIconFactory({ h }); + const CropIcon = CropIconFactory({ h }); return function ScreenshotEditor({ onError }: Props): VNode { const styles = hooks.useMemo(() => ({ __html: createScreenshotInputStyles(options.styleNonce).innerText }), []); @@ -86,6 +88,7 @@ export function ScreenshotEditorFactory({ const [croppingRect, setCroppingRect] = hooks.useState({ startX: 0, startY: 0, endX: 0, endY: 0 }); const [confirmCrop, setConfirmCrop] = hooks.useState(false); const [isResizing, setIsResizing] = hooks.useState(false); + const [isCropping, setIsCropping] = hooks.useState(false); const [isAnnotating, setIsAnnotating] = hooks.useState(false); hooks.useEffect(() => { @@ -142,6 +145,10 @@ export function ScreenshotEditorFactory({ const croppingBox = constructRect(croppingRect); ctx.clearRect(0, 0, imageDimensions.width, imageDimensions.height); + if (!isCropping) { + return; + } + // draw gray overlay around the selection ctx.fillStyle = 'rgba(0, 0, 0, 0.5)'; ctx.fillRect(0, 0, imageDimensions.width, imageDimensions.height); @@ -154,7 +161,7 @@ export function ScreenshotEditorFactory({ ctx.strokeStyle = '#000000'; ctx.lineWidth = 1; ctx.strokeRect(croppingBox.x + 3, croppingBox.y + 3, croppingBox.width - 6, croppingBox.height - 6); - }, [croppingRect]); + }, [croppingRect, isCropping]); function onGrabButton(e: Event, corner: string): void { setIsAnnotating(false); @@ -398,102 +405,132 @@ export function ScreenshotEditorFactory({ return (