A simple React component for magnifying images with a zoom effect. This component is built using TypeScript and Next.js.
You can install the @hammadxcm/image-magnifier
package via npm, pnpm, or yarn. Don't forget to add the --save
flag if you want to save it to your package.json
.
npm install @hammadxcm/image-magnifier --save
pnpm add @hammadxcm/image-magnifier
yard add @hammadxcm/image-magnifier
import React from 'react';
import ReactImageMagnifier from '@hammadxcm/image-magnifier';
const App = () => {
return (
<div>
<h1>Image Magnifier Example</h1>
<ReactImageMagnifier imageSrc='https://picsum.photos/200/300.jpg' />
</div>
);
};
export default App;
import React from 'react';
import ReactImageMagnifier from '@hammadxcm/image-magnifier';
const App = () => {
return (
<div>
<h1>Advanced Image Magnifier Example</h1>
<ReactImageMagnifier
imageSrc='https://picsum.photos/200/300.jpg'
magnifierSize={250}
zoomLevel={3}
imageClassName='custom-image-class'
imageAlt='Custom Alt Text'
imageSizes='(max-width: 500px) 100vw, 500px'
imageWidth={400}
imageHeight={400}
className='custom-root-class'
/>
</div>
);
};
export default App;
The ImageMagnifier
component accepts the following props:
imageSrc
(string): The URL of the image to be magnified. (required)magnifierSize
(number): The size of the magnifier. Default is300
.zoomLevel
(number): The zoom level for magnification. Default is2.5
.imageClassName
(string): CSS class for the image element. Default is'object-cover z-10'
.imageAlt
(string): Alt text for the image. Default isundefined
.imageSizes
(string): Sizes attribute for the image. Default is'(max-width: 700px) 100vw, (max-width: 300px) 100vw, 700px'
.imageWidth
(number): Width of the image in pixels. Default is500
.imageHeight
(number): Height of the image in pixels. Default is500
.className
(string): CSS class for the rootdiv
element. Default is'flex justify-center items-center'
.
MIT © hammadxcm