Skip to content

Build your personal knowledge base with Trilium Notes

client/image viewer: tweak the mouse cursor

Adorian Doran621ae24e54bb
diff --git a/apps/client/src/widgets/react/ImageViewer.css b/apps/client/src/widgets/react/ImageViewer.css
index 4b2dece372..5095bc3adc 100644
--- a/apps/client/src/widgets/react/ImageViewer.css
+++ b/apps/client/src/widgets/react/ImageViewer.css
@@ -15,3 +15,12 @@
max-width: 100%;
max-height: 100%;
}
+
+/* The the grab cursor only while the image is large enough to pan (zoomed past fit). */
+.image-viewer-viewport.pannable {
+ cursor: grab;
+}
+
+.image-viewer-viewport.pannable.panning {
+ cursor: grabbing;
+}
diff --git a/apps/client/src/widgets/react/ImageViewer.tsx b/apps/client/src/widgets/react/ImageViewer.tsx
index 698e4f003c..e967bd8eff 100644
--- a/apps/client/src/widgets/react/ImageViewer.tsx
+++ b/apps/client/src/widgets/react/ImageViewer.tsx
@@ -1,6 +1,7 @@
import "./ImageViewer.css";
import { Ref } from "preact";
+import { useState } from "preact/hooks";
import { type ReactZoomPanPinchRef, TransformComponent, TransformWrapper } from "react-zoom-pan-pinch";
interface ImageViewerProps {
@@ -19,6 +20,9 @@ interface ImageViewerProps {
* (wheel/pinch/buttons) and pan (drag). Double-clicking resets back to the fitted view.
*/
export default function ImageViewer({ src, imgClassName, alt = "", minScale = 0.5, maxScale = 50, apiRef }: ImageViewerProps) {
+ const [ pannable, setPannable ] = useState(false);
+ const [ panning, setPanning ] = useState(false);
+
return (
<TransformWrapper
ref={apiRef}
@@ -29,8 +33,11 @@ export default function ImageViewer({ src, imgClassName, alt = "", minScale = 0.
wheel={{ step: 0.0085 }}
autoAlignment={{ disabled: true }}
doubleClick={{ mode: "reset" }}
+ onTransform={(_ref, { scale }) => setPannable(scale > 1)}
+ onPanningStart={() => setPanning(true)}
+ onPanningStop={() => setPanning(false)}
>
- <TransformComponent wrapperClass="image-viewer-viewport" contentClass="image-viewer-content">
+ <TransformComponent wrapperClass={`image-viewer-viewport${pannable ? " pannable" : ""}${panning ? " panning" : ""}`} contentClass="image-viewer-content">
<img className={imgClassName} src={src} alt={alt} />
</TransformComponent>
</TransformWrapper>