Add explicit zoom button

This commit is contained in:
Sam Becker 2025-01-26 14:17:40 -06:00
parent c089d9a6ca
commit cb13496a34
2 changed files with 28 additions and 3 deletions

View File

@ -33,6 +33,14 @@ export default function useImageZoomControls(
} }
}, [imageRef, isEnabled]); }, [imageRef, isEnabled]);
const open = useCallback(() => {
viewerRef.current?.show();
}, [viewerRef]);
const close = useCallback(() => {
viewerRef.current?.hide();
}, [viewerRef]);
// On shown, disable keyboard commands // On shown, disable keyboard commands
const onShown = useCallback(() => const onShown = useCallback(() =>
setShouldRespondToKeyboardCommands?.(false), setShouldRespondToKeyboardCommands?.(false),
@ -69,4 +77,9 @@ export default function useImageZoomControls(
document.removeEventListener(EVENT_KEYDOWN, handleKeyDown); document.removeEventListener(EVENT_KEYDOWN, handleKeyDown);
}; };
}, [handleKeyDown]); }, [handleKeyDown]);
return {
open,
close,
};
} }

View File

@ -37,6 +37,8 @@ import useOnVisible from '@/utility/useOnVisible';
import PhotoDate from './PhotoDate'; import PhotoDate from './PhotoDate';
import { useAppState } from '@/state/AppState'; import { useAppState } from '@/state/AppState';
import useImageZoomControls from '@/components/image/useImageZoomControls'; import useImageZoomControls from '@/components/image/useImageZoomControls';
import { LuZoomIn } from 'react-icons/lu';
import LoaderButton from '@/components/primitives/LoaderButton';
export default function PhotoLarge({ export default function PhotoLarge({
photo, photo,
@ -79,7 +81,7 @@ export default function PhotoLarge({
onVisible?: () => void onVisible?: () => void
}) { }) {
const ref = useRef<HTMLDivElement>(null); const ref = useRef<HTMLDivElement>(null);
const refZoomControls = useRef<HTMLDivElement>(null); const refZoomControlsContainer = useRef<HTMLDivElement>(null);
const { const {
areZoomControlsEnabled, areZoomControlsEnabled,
@ -97,7 +99,10 @@ export default function PhotoLarge({
useOnVisible(ref, onVisible); useOnVisible(ref, onVisible);
useImageZoomControls(refZoomControls, areZoomControlsEnabled); const { open } = useImageZoomControls(
refZoomControlsContainer,
areZoomControlsEnabled,
);
const hasTitle = const hasTitle =
showTitle && showTitle &&
@ -152,7 +157,7 @@ export default function PhotoLarge({
arePhotosMatted && matteContentWidthForAspectRatio(), arePhotosMatted && matteContentWidthForAspectRatio(),
)}> )}>
<div <div
ref={refZoomControls} ref={refZoomControlsContainer}
className={clsx(areZoomControlsEnabled && 'cursor-zoom-in')} className={clsx(areZoomControlsEnabled && 'cursor-zoom-in')}
> >
<ImageLarge <ImageLarge
@ -293,6 +298,13 @@ export default function PhotoLarge({
focal={shouldShareFocalLength ? photo.focalLength : undefined} focal={shouldShareFocalLength ? photo.focalLength : undefined}
prefetch={prefetchRelatedLinks} prefetch={prefetchRelatedLinks}
/>} />}
{areZoomControlsEnabled &&
<LoaderButton
icon={<LuZoomIn size={17} />}
onClick={open}
styleAs="link"
className="text-medium"
/>}
{ALLOW_PUBLIC_DOWNLOADS && {ALLOW_PUBLIC_DOWNLOADS &&
<DownloadButton <DownloadButton
className={clsx( className={clsx(