🎥 Make videos programmatically with React
force specific cursor
JonnyBurger635b19cdae9e
diff --git a/packages/convert/app/components/crop-ui/ResizeHandle.tsx b/packages/convert/app/components/crop-ui/ResizeHandle.tsxindex 7d02f152a4..ce83b73ce6 100644--- a/packages/convert/app/components/crop-ui/ResizeHandle.tsx+++ b/packages/convert/app/components/crop-ui/ResizeHandle.tsx@@ -1,6 +1,10 @@import type {CropRectangle} from 'mediabunny';import React, {useCallback, useMemo} from 'react';import type {Dimensions} from '~/lib/calculate-new-dimensions-from-dimensions';+import {+ forceSpecificCursor,+ stopForcingSpecificCursor,+} from './force-specific-cursor';const baseStyle: React.CSSProperties = {width: 12,@@ -15,6 +19,28 @@ const clamp = (val: number, min: number, max: number) => {const MIN_SIZE = 120;+const getCursor = (position: Position) => {+ if (position === 'top-left') {+ return 'nwse-resize';+ }++ if (position === 'top-right') {+ return 'nesw-resize';+ }++ if (position === 'bottom-left') {+ return 'nesw-resize';+ }++ if (position === 'bottom-right') {+ return 'nwse-resize';+ }++ throw new Error(+ 'Unknown position: ' + JSON.stringify(position satisfies never),+ );+};+export const ResizeHandle: React.FC<{readonly position: Position;readonly divRef: React.RefObject<HTMLDivElement | null>;@@ -90,6 +116,8 @@ export const ResizeHandle: React.FC<{return;}+ forceSpecificCursor(getCursor(position));+const move = (evt: PointerEvent) => {evt.preventDefault();evt.stopPropagation();@@ -178,6 +206,8 @@ export const ResizeHandle: React.FC<{evt.preventDefault();evt.stopPropagation();+ stopForcingSpecificCursor();+window.removeEventListener('pointermove', onPointerMove);window.removeEventListener('pointerup', onPointerUp);};diff --git a/packages/convert/app/components/crop-ui/force-specific-cursor.tsx b/packages/convert/app/components/crop-ui/force-specific-cursor.tsxnew file mode 100644index 0000000000..034243952c--- /dev/null+++ b/packages/convert/app/components/crop-ui/force-specific-cursor.tsx@@ -0,0 +1,39 @@+import React, {useMemo} from 'react';++const ref = React.createRef<HTMLDivElement>();++export const forceSpecificCursor = (+ cursor: Exclude<React.CSSProperties['cursor'], undefined>,+) => {+ if (!ref.current) {+ throw new Error('ForceSpecificCursor is not mounted');+ }++ ref.current.style.cursor = cursor;+ ref.current.style.pointerEvents = 'auto';+};++export const stopForcingSpecificCursor = () => {+ if (!ref.current) {+ throw new Error('ForceSpecificCursor is not mounted');+ }++ ref.current.style.cursor = '';+ ref.current.style.pointerEvents = 'none';+};++export const ForceSpecificCursor = () => {+ const style: React.CSSProperties = useMemo(() => {+ return {+ zIndex: 10,+ };+ }, []);++ return (+ <div+ ref={ref}+ className="pointer-events-none absolute inset-0"+ style={style}+ />+ );+};diff --git a/packages/convert/app/root.tsx b/packages/convert/app/root.tsxindex f4efe9bbfe..8c7f8d733b 100644--- a/packages/convert/app/root.tsx+++ b/packages/convert/app/root.tsx@@ -1,3 +1,4 @@+import {ForceSpecificCursor} from './components/crop-ui/force-specific-cursor';import {DEFAULT_FAVICON} from './lib/default-favicon';import './tailwind.css';@@ -20,6 +21,7 @@ export const Layout = ({children}: {readonly children: React.ReactNode}) => {</head><body>{children}+ <ForceSpecificCursor /><ScrollRestoration /><Scripts /></body>