Skip to content

<ImageWithZoom>: Add new prop to zoom only on click #484

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rosesyrett
Copy link

@rosesyrett rosesyrett commented May 13, 2025

Add a prop to <ImageWithZoom> component which allows images to only be zoomed in if they are clicked.

What:

I have started trying to use this library for my website, however have found it annoying that I cannot toggle the zoom behaviour on hover.

Specifically, I would like to enable zooming in the ImageWithZoom component only when the mouse has clicked the image, not necessarily on hover. Initially I tried to do this using the carouselContext as described in the docs however found that the props needed for this behaviour are exposed only internally within the react class.

Why:

This will allow the company I'm working with to use this library and customise exactly when we see the 'inner' image; that is, on click instead of on hover on desktop.

How:

I added a clicked state attribute to determine if the image is clicked, and a onlyZoomOnClick prop to the ImageWithZoom component, which (when true):

  1. conditionally renders the second 'overlay' Image (that is, if false, only the first Image is rendered),
  2. sets the cursor style to show a 'zoom-out' symbol if the image has been clicked (otherwise, zoom-in cursor is shown)

Todos

There are a couple of things I'm still working out:

  1. How to make the transition 'smooth' between being zoomed in and zoomed out. If you spin up a local server you can see when the mouse moves outside of the image boundary the transition between images is abrupt, unlike what currently exists if this new prop is not passed in.
  2. How this will affect mobile users or interplay with the other props, i.e. for pinch to zoom.

Checklist:

  • Documentation added/updated
  • Typescript definitions updated
  • Tests added and passing
  • Ready to be merged

@rosesyrett rosesyrett changed the title <ImageWithZoom>: Add new prop to oom only on click <ImageWithZoom>: Add new prop to zoom only on click May 13, 2025
@rosesyrett rosesyrett force-pushed the zoom-on-click branch 2 times, most recently from abd20c6 to cdab145 Compare May 13, 2025 10:56
Add a prop which allows images to only be zoomed in if they are
clicked.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant