Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(feedback): Let CropCorner inherit the existing h prop #12814

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions packages/feedback/src/screenshot/components/CropCorner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { VNode, h as hType } from 'preact';

interface FactoryParams {
h: typeof hType;
}

export default function CropCornerFactory({
h, // eslint-disable-line @typescript-eslint/no-unused-vars
}: FactoryParams) {
return function CropCorner({
top,
left,
corner,
onGrabButton,
}: {
top: number;
left: number;
corner: string;
onGrabButton: (e: Event, corner: string) => void;
}): VNode {
return (
<button
class={`editor__crop-corner editor__crop-corner--${corner} `}
style={{
top: top,
left: left,
}}
onMouseDown={e => {
e.preventDefault();
onGrabButton(e, corner);
}}
onClick={e => {
e.preventDefault();
}}
></button>
);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { FeedbackInternalOptions, FeedbackModalIntegration } from '@sentry/
import type { ComponentType, VNode, h as hType } from 'preact';
import type * as Hooks from 'preact/hooks';
import { DOCUMENT, WINDOW } from '../../constants';
import CropCornerFactory from './CropCorner';
import { createScreenshotInputStyles } from './ScreenshotInput.css';
import { useTakeScreenshotFactory } from './useTakeScreenshot';

Expand Down Expand Up @@ -62,7 +63,7 @@ const getContainedSize = (img: HTMLCanvasElement): Box => {
};

export function ScreenshotEditorFactory({
h, // eslint-disable-line @typescript-eslint/no-unused-vars
h,
hooks,
imageBuffer,
dialog,
Expand All @@ -72,6 +73,7 @@ export function ScreenshotEditorFactory({

return function ScreenshotEditor({ onError }: Props): VNode {
const styles = hooks.useMemo(() => ({ __html: createScreenshotInputStyles().innerText }), []);
const CropCorner = CropCornerFactory({ h });

const canvasContainerRef = hooks.useRef<HTMLDivElement>(null);
const cropContainerRef = hooks.useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -326,32 +328,3 @@ export function ScreenshotEditorFactory({
);
};
}

function CropCorner({
top,
left,
corner,
onGrabButton,
}: {
top: number;
left: number;
corner: string;
onGrabButton: (e: Event, corner: string) => void;
}): VNode {
return (
<button
class={`editor__crop-corner editor__crop-corner--${corner} `}
style={{
top: top,
left: left,
}}
onMouseDown={e => {
e.preventDefault();
onGrabButton(e, corner);
}}
onClick={e => {
e.preventDefault();
}}
></button>
);
}
Loading