1.0.1 • Published 11 months ago

react-responsive-image-zoom v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

React Responsive Image Zoom šŸ”

A lightweight and customizable React component that provides a smooth zoom effect on images when hovered over. It supports responsive zoom factors based on screen width breakpoints,adapting to different screen, and includes an optional debug mode.

✨ Features

  • šŸ‹ļøā€ā™€ļø Lightweight: Small bundle size, perfect for performance-conscious applications.
  • šŸ”Œ No external dependencies: Works out of the box with React.
  • šŸ“± Responsive: Automatically adapts to different screen sizes, including mobile devices.
  • šŸŽØ Customizable: Easily adjust zoom factors, transitions, and breakpoints.
  • šŸž Debug mode: Optional feature for development and testing.

šŸ“¦ Installation

npm install react-responsive-image-zoom

šŸŽ„ Example

example

šŸš€ Usage

import React from 'react';
import { ImageZoom } from 'react-responsive-image-zoom';

const App = () => {
  return (
    <ImageZoom
      src="/path/to/image.jpg"
      defaultZoomFactor={1.5}
      transition={0.5}
      breakpoints={[
        { maxWidth: 768, zoomFactor: 1.2 },
        { maxWidth: 1024, zoomFactor: 1.4 }
      ]}
      imgClassName="my-image-class"
      debug={false}
    />
  );
};

export default App;

šŸŽ›ļø Props

PropTypeDefaultDescription
srcstring-The source URL of the image (required)
defaultZoomFactornumber1.3The default zoom factor to use when no breakpoints match
transitionnumber0.3The duration of the zoom transition in seconds
breakpointsArray<Breakpoint>[]An array of breakpoints for responsive zoom factors
imgClassNamestring-Additional CSS class name for the image element
debugbooleanfalseEnable debug mode to show current width and zoom factor

šŸ“Š Breakpoint Object

PropertyTypeDescription
maxWidthnumberThe maximum screen width for this breakpoint
zoomFactornumberThe zoom factor to use for this breakpoint

šŸš€ Performance and Optimization

  • šŸ‹ļøā€ā™€ļø Lightweight: This package has a very small footprint, ensuring minimal impact on your application's load time and performance.
  • šŸ”Œ No Dependencies: react-responsive-image-zoom doesn't include any additional dependencies, keeping your project lean.
  • šŸ“± Responsive Design: The component automatically adapts to different screen sizes, making it suitable for both desktop and mobile devices.
  • šŸ–¼ļø Automatic Image Scaling: The underlying <img> element automatically scales to fit its container, ensuring proper display across different device sizes.
  • ⚔ Optimized Rendering: Uses React.memo, useCallback, and useMemo for optimized performance.

āš ļø Note: When the debug prop is set to true, the component will update its state and re-render on every window resize event. This can impact performance, especially on devices with frequently changing viewport sizes. It's recommended to use the debug prop only during development or testing, and to disable it in production environments.# react-responsive-image-zoom

react-responsive-image-zoom