Built with TypeScript, featuring multiple themes, touch support, and advanced customization options
๐ฌ Demo โข ๐ฆ Installation โข ๐ Quick Start โข ๐ก Examples โข ๐ API
๐ Core Features | โก Advanced Features |
---|---|
โข ๐ Smooth Magnification - High-performance zoom |
โข ๐๏ธ Zoom Controls - Interactive +/- buttons |
// โจ Just works out of the box!
import { ReactImageMagnifier } from '@hammadxcm/image-magnifier';
<ReactImageMagnifier
imageSrc="/your-amazing-image.jpg"
imageWidth={500}
imageHeight={400}
/>
๐ฏ Hover over images to see the magnification effect in action
๐ฆ npm | ๐งถ yarn | ๐ pnpm |
---|---|---|
npm install @hammadxcm/image-magnifier |
yarn add @hammadxcm/image-magnifier |
pnpm add @hammadxcm/image-magnifier |
import { ReactImageMagnifier } from '@hammadxcm/image-magnifier';
function ProductImage() {
return (
<ReactImageMagnifier
imageSrc="/product.jpg"
imageAlt="Product showcase"
imageWidth={600}
imageHeight={400}
magnifierSize={200}
zoomLevel={2.5}
/>
);
}
import {
MagnifierProvider,
ReactImageMagnifierAdvanced
} from '@hammadxcm/image-magnifier';
function App() {
return (
<MagnifierProvider theme="modern" performanceMode={false}>
<ReactImageMagnifierAdvanced
imageSrc="/hero-image.jpg"
theme="modern"
showZoomControls={true}
showMiniMap={true}
enableTouch={true}
watermark="ยฉ 2024 Your Brand"
/>
</MagnifierProvider>
);
}
๐จ Themed Gallery
import { ReactImageMagnifierAdvanced, MagnifierProvider } from '@hammadxcm/image-magnifier';
function ThemedGallery() {
return (
<MagnifierProvider>
<div className="grid grid-cols-2 gap-4">
{/* Modern Theme */}
<ReactImageMagnifierAdvanced
imageSrc="/image1.jpg"
theme="modern"
showZoomControls={true}
position="follow"
cursorStyle="zoom-in"
/>
{/* Dark Theme */}
<ReactImageMagnifierAdvanced
imageSrc="/image2.jpg"
theme="dark"
showMiniMap={true}
position="fixed-top-right"
enableTouch={true}
/>
</div>
</MagnifierProvider>
);
}
๐ฑ Mobile-Optimized
function MobileGallery() {
return (
<ReactImageMagnifierAdvanced
imageSrc="/mobile-image.jpg"
enableTouch={true}
showZoomControls={true}
theme="modern"
minZoom={1.5}
maxZoom={4}
onZoomChange={(zoom) => console.log(`Zoom: ${zoom}x`)}
watermark="ยฉ 2024 Brand"
/>
);
}
๐๏ธ E-commerce Product
function ProductShowcase() {
return (
<ReactImageMagnifierAdvanced
imageSrc="/product.jpg"
theme="classic"
showZoomControls={true}
showMiniMap={true}
watermark="Premium Quality โจ"
overlayContent={
<div className="absolute top-4 left-4 bg-red-500 text-white px-2 py-1 rounded">
๐ฅ Sale 50% OFF
</div>
}
onMagnifierShow={() => console.log('User examining product')}
/>
);
}
๐๏ธ Classic | ๐ฏ Modern | ๐ Dark | ๐ Neon |
---|---|---|---|
Traditional magnifying glass |
Clean, minimalist blue accents |
Perfect for dark mode |
Vibrant pink highlights |
<ReactImageMagnifierAdvanced
theme="classic"
// Warm, traditional styling
/> |
<ReactImageMagnifierAdvanced
theme="modern"
// Clean blue accents
/> |
<ReactImageMagnifierAdvanced
theme="dark"
// Subtle dark highlights
/> |
<ReactImageMagnifierAdvanced
theme="neon"
// Pink/purple vibrancy
/> |
Create your own unique styling:
const customTheme = {
borderColor: 'rgba(255, 0, 0, 0.8)',
borderWidth: 2,
shadowColor: 'rgba(255, 0, 0, 0.3)',
handleColor: 'rgba(255, 0, 0, 0.9)',
gripColor: 'rgba(200, 0, 0, 0.9)',
backdropBlur: true,
};
<ReactImageMagnifierAdvanced
customTheme={customTheme}
magnifierSize={250}
/>
Prop | Type | Default | Description |
---|---|---|---|
imageSrc |
string |
required | Image source URL |
imageAlt |
string |
- | Alt text for accessibility |
imageWidth |
number |
500 |
Image width in pixels |
imageHeight |
number |
500 |
Image height in pixels |
magnifierSize |
number |
300 |
Magnifier lens size |
zoomLevel |
number |
2.5 |
Zoom multiplier |
disabled |
boolean |
false |
Disable magnification |
๐ง View Advanced Props
Prop | Type | Default | Description |
---|---|---|---|
theme |
'classic' | 'modern' | 'dark' | 'neon' |
'classic' |
Built-in theme |
customTheme |
Partial<MagnifierTheme> |
- | Custom theme overrides |
position |
'follow' | 'fixed-*' |
'follow' |
Magnifier positioning |
cursorStyle |
'crosshair' | 'zoom-in' | 'grab' | 'pointer' |
'crosshair' |
Cursor style |
showZoomControls |
boolean |
false |
Show +/- buttons |
showMiniMap |
boolean |
false |
Show navigation map |
enableKeyboard |
boolean |
true |
Keyboard shortcuts |
enableTouch |
boolean |
true |
Touch/gesture support |
minZoom |
number |
1.5 |
Minimum zoom level |
maxZoom |
number |
5 |
Maximum zoom level |
watermark |
string | ReactNode |
- | Watermark content |
overlayContent |
ReactNode |
- | Custom overlay |
onMagnifierShow |
() => void |
- | Show callback |
onMagnifierHide |
() => void |
- | Hide callback |
onZoomChange |
(zoom: number) => void |
- | Zoom change callback |
๐ฑ๏ธ Mouse/Keyboard | ๐ฑ Touch Gestures |
---|---|
โข Hover - Show magnifier |
โข Tap & Hold - Show magnifier |
<MagnifierProvider performanceMode={true}>
{images.map(image => (
<ReactImageMagnifierAdvanced
key={image.id}
{...image}
performanceMode={true}
/>
))}
</MagnifierProvider>
- โก Single Active Magnifier - Only one renders at a time
- ๐ฏ 60fps Throttling - Smooth with rapid movements
- ๐ง Smart Re-rendering - Optimized React patterns
- ๐ฆ Tree Shaking - Import only what you need
Built with accessibility in mind:
- ๐ Screen Readers - Full ARIA label support
- โจ๏ธ Keyboard Navigation - Complete keyboard control
- ๐ฏ Focus Management - Proper tab order
- ๐ High Contrast - Works with system preferences
๐ฃ Custom Hooks
import { useMagnifier, useTouch } from '@hammadxcm/image-magnifier';
function CustomMagnifier() {
const magnifierProps = useMagnifier({
magnifierSize: 200,
zoomLevel: 3,
smoothAnimations: true,
});
const touchProps = useTouch({
enabled: true,
minZoom: 1,
maxZoom: 5,
onGesture: (gesture) => {
console.log('Touch gesture:', gesture);
},
});
// Your custom implementation
}
๐ Context Usage
import { useMagnifierContext } from '@hammadxcm/image-magnifier';
function ThemeSelector() {
const { globalSettings, updateGlobalSettings } = useMagnifierContext();
return (
<select
value={globalSettings.theme}
onChange={(e) => updateGlobalSettings({ theme: e.target.value })}
>
<option value="classic">๐๏ธ Classic</option>
<option value="modern">๐ฏ Modern</option>
<option value="dark">๐ Dark</option>
<option value="neon">๐ Neon</option>
</select>
);
}
โ Common Issues & Solutions
- โ
Ensure
imageSrc
is valid and loads successfully - โ
Check that
disabled
prop is not set totrue
- โ Verify image dimensions are set correctly
- โ
Check that
enableTouch
istrue
- โ
Ensure
touchEnabled
is enabled in MagnifierProvider - โ Test on actual device, not desktop browser
- โ
Enable
performanceMode
in MagnifierProvider - โ
Use
performanceMode={true}
on individual components - โ Consider lazy loading for large galleries
- โ Ensure React 18+ or 19+ is installed
- โ Check that all required props are provided
- โ
Import types:
import type { ReactImageMagnifierAdvancedProps } from '@hammadxcm/image-magnifier'
โ๏ธ Framework Integration
import dynamic from 'next/dynamic';
const ReactImageMagnifier = dynamic(
() => import('@hammadxcm/image-magnifier').then(mod => mod.ReactImageMagnifier),
{ ssr: false }
);
function ProductPage() {
return (
<ReactImageMagnifier
imageSrc="/product.jpg"
imageWidth={600}
imageHeight={400}
/>
);
}
- ๐ Report bugs
- ๐ก Request features
- ๐ Improve documentation
- ๐จ Create custom themes
# Clone the repository
git clone https://github.com/hammadxcm/react-image-magnifier.git
# Install dependencies
npm install
# Build the package
npm run build
# Run tests
npm test
- ๐ฅ Video Magnification - Support for video elements
- ๐ 3D Image Support - WebGL-based exploration
- ๐ค AI-Powered Features - Smart zoom region detection
- ๐จ More Themes - Community-requested designs
- โจ Animation Presets - Pre-built configurations
ISC License - see LICENSE file for details.
- ๐ Bug Reports: GitHub Issues
- ๐ก Feature Requests: GitHub Discussions
- ๐ Documentation: Complete Guide
- โญ Star the repository to show your support
- ๐ฆ Share on social media
- ๐ Write a blog post about your experience
Made with โค๏ธ by hammadxcm and the amazing open-source community
Crafted with passion โข Built for developers โข Enhanced by community