Skip to content

hammadxcm/image-magnifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ” React Image Magnifier

React TypeScript Tailwind CSS

npm version Bundle Size License GitHub Stars

๐ŸŽฏ A modern, powerful React component for image magnification

Built with TypeScript, featuring multiple themes, touch support, and advanced customization options


๐ŸŽฌ Demo โ€ข ๐Ÿ“ฆ Installation โ€ข ๐Ÿš€ Quick Start โ€ข ๐Ÿ’ก Examples โ€ข ๐Ÿ“– API


โœจ Features

๐Ÿš€ Core Features โšก Advanced Features

โ€ข ๐Ÿ” Smooth Magnification - High-performance zoom
โ€ข ๐ŸŽจ 4 Built-in Themes - Classic, Modern, Dark, Neon
โ€ข ๐Ÿ“ฑ Touch Support - Pinch-to-zoom gestures
โ€ข โŒจ๏ธ Keyboard Navigation - +/- zoom, ESC hide
โ€ข ๐ŸŽฏ Smart Positioning - Follow cursor or fixed
โ€ข ๐Ÿ–ฑ๏ธ Multiple Cursors - Crosshair, zoom-in, etc

โ€ข ๐ŸŽ›๏ธ Zoom Controls - Interactive +/- buttons
โ€ข ๐Ÿ—บ๏ธ Mini Map - Navigation overview
โ€ข ๐Ÿท๏ธ Watermarks - Text or component overlays
โ€ข ๐ŸŽญ Custom Themes - Full color customization
โ€ข โ™ฟ Accessibility - ARIA support, screen readers
โ€ข ๐Ÿ”ง TypeScript - Complete type definitions


๐ŸŽฌ Demo

Demo
// โœจ 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


๐Ÿ“ฆ Installation

๐Ÿ“ฆ npm ๐Ÿงถ yarn ๐Ÿ“Œ pnpm
npm install @hammadxcm/image-magnifier
yarn add @hammadxcm/image-magnifier
pnpm add @hammadxcm/image-magnifier

๐Ÿš€ Quick Start

Basic Usage

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}
    />
  );
}

Advanced Usage with Provider

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>
  );
}

๐Ÿ’ก Examples

๐ŸŽจ 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')}
    />
  );
}

๐ŸŽจ Themes

Built-in Theme Showcase

๐Ÿ›๏ธ 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
/>

๐ŸŽจ Custom Themes

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}
/>

๐Ÿ“– API

ReactImageMagnifier (Basic)

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

ReactImageMagnifierAdvanced

๐Ÿ”ง 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

โŒจ๏ธ Controls

๐Ÿ–ฑ๏ธ Mouse/Keyboard ๐Ÿ“ฑ Touch Gestures

โ€ข Hover - Show magnifier
โ€ข + or = - Zoom in
โ€ข - - Zoom out
โ€ข Escape - Hide magnifier

โ€ข Tap & Hold - Show magnifier
โ€ข Drag - Move view area
โ€ข Pinch - Zoom in/out
โ€ข Double Tap - Quick zoom


๐Ÿš€ Performance

Multiple Images Optimization

<MagnifierProvider performanceMode={true}>
  {images.map(image => (
    <ReactImageMagnifierAdvanced
      key={image.id}
      {...image}
      performanceMode={true}
    />
  ))}
</MagnifierProvider>

Performance Features

  • โšก 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

โ™ฟ Accessibility

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

๐Ÿ”ง Advanced Usage

๐ŸŽฃ 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>
  );
}

๐Ÿ› Troubleshooting

โ“ Common Issues & Solutions

๐Ÿ” Magnifier not showing

  • โœ… Ensure imageSrc is valid and loads successfully
  • โœ… Check that disabled prop is not set to true
  • โœ… Verify image dimensions are set correctly

๐Ÿ“ฑ Touch not working on mobile

  • โœ… Check that enableTouch is true
  • โœ… Ensure touchEnabled is enabled in MagnifierProvider
  • โœ… Test on actual device, not desktop browser

โšก Performance issues with multiple images

  • โœ… Enable performanceMode in MagnifierProvider
  • โœ… Use performanceMode={true} on individual components
  • โœ… Consider lazy loading for large galleries

๐Ÿ”ท TypeScript errors

  • โœ… 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

Next.js

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}
    />
  );
}

๐Ÿค Contributing

Contributions Welcome

Quick Contributions

Development Setup

# 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

๐Ÿ”ฎ Roadmap

๐ŸŽฏ Coming Soon

  • ๐ŸŽฅ 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

๐Ÿ“Š Stats

GitHub Stars NPM Downloads GitHub Issues

๐Ÿ“„ License

ISC License - see LICENSE file for details.


๐Ÿ’ฌ Support & Community

Get Help

Show Your Support

  • โญ Star the repository to show your support
  • ๐Ÿฆ Share on social media
  • ๐Ÿ“ Write a blog post about your experience

๐ŸŽ‰ Thank you for using React Image Magnifier! ๐ŸŽ‰

Made with โค๏ธ by hammadxcm and the amazing open-source community

Crafted with passion โ€ข Built for developers โ€ข Enhanced by community

GitHub Twitter LinkedIn


Star this repo

About

A React component for magnifying images with a zoom effect.

Resources

Security policy

Stars

Watchers

Forks

Packages

No packages published