This is a low-level component for magnify in React.
-
Image Display: Use an image component to display the image you want to magnify.
-
Magnified View: Create a separate container to display the magnified portion of the image. You can use CSS to position and style this container, making it circular or any desired shape. The magnified view should update dynamically based on the mouse cursor position.
-
Zoom Level Control: Add controls (such as buttons or sliders) to allow users to adjust the zoom level of the magnifier. These controls should modify the size of the magnified area accordingly.
Client: React
Install the package in your project with your preferred package manager:
# npm
npm install solguruz-react-image-magnifier
# yarn
yarn add solguruz-react-image-magnifierreact (>= 18) is a peer dependency, so make sure it is installed in your project.
Clone the project
git clone https://github.com/solguruz/magnifier-react.gitGo to the project directory
cd magnifier-reactInstall dependencies (this project uses yarn — a yarn.lock is committed; do not use npm install):
yarn installThe library ships dual ESM + CJS output, produced by two tsc passes (no bundler).
yarn build # full build — runs build:esm then build:cjs
yarn build:esm # ESM build (tsc → dist/esm)
yarn build:cjs # CommonJS build (tsc --module commonjs → dist/cjs)Other useful scripts:
yarn lint # ESLint over all .{js,ts,jsx,tsx} files
yarn prettier # format the source in placeThe
preparehook runs a full build automatically onyarn installand before publish, so a fresh install also compilesdist/.
| Parameters | Type | Default | Description |
|---|---|---|---|
image (required) |
String | – | URL of the image |
zoom |
Number | 2 | it's define the zoom level of component |
width |
Number/String | '100%' |
Image width |
magnifierWidth |
Number | 150 |
Width of the Magnifier |
magnifierHeight |
Number | 150 |
Height of the magnifier |
borderWidth |
Number | 2 |
Border Width of the magnifier |
borderColor |
String | white |
Color of magnifier border |
Import the Magnifier component and pass it the image URL. Only image is required — every other prop has a sensible default (see Configuration).
Basic usage:
import { Magnifier } from 'solguruz-react-image-magnifier'
const App = () => {
return <Magnifier image={IMAGE_PATH} />
}With custom configuration:
import { Magnifier } from 'solguruz-react-image-magnifier'
const App = () => {
return (
<Magnifier
image='https://example.com/photo.jpg'
zoom={3}
width={400}
magnifierWidth={180}
magnifierHeight={180}
borderWidth={3}
borderColor='black'
/>
)
}Engineering Quality Solutions by employing technologies with Passion and Love | Web and Mobile App Development Company in India and Canada
Contributions are always welcome!
See CONTRIBUTING.md for the it workflow & contribution guidelines
MIT License
Copyright (c) 2023 SolGuruz Pvt Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

