npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

image-lazy-component

v1.3.4

Published

A React component for lazy loading images with advanced image processing features.

Readme

ImageLazy - Advanced React Image Component

A powerful React component for lazy loading images with advanced image processing features, progressive loading, and optimization capabilities.

🚀 Features

  • Lazy Loading: Efficient lazy loading with Intersection Observer
  • Progressive Loading: Blur-to-sharp loading effect for better UX
  • Image Optimization: Automatic image optimization and format conversion
  • Responsive Images: Support for responsive images with srcset
  • Error Handling: Smart retry mechanism for failed image loads
  • TypeScript Support: Full TypeScript support with comprehensive types
  • Accessibility: Built-in accessibility features
  • Memory Efficient: Optimized memory usage and cleanup
  • Customizable: Highly customizable with extensive props

📦 Installation

npm install image-lazy-component

🔧 Basic Usage

import React from "react";
import { ImageLazy } from "image-lazy-component";

const BasicExample = () => {
  return (
    <ImageLazy
      imgUrl="https://example.com/image.jpg"
      alt="Example image"
      width={400}
      height={300}
    />
  );
};

🎨 Advanced Usage

Progressive Loading with Blur Effect

import { ImageLazy } from "image-lazy-component";

const ProgressiveExample = () => {
  return (
    <ImageLazy
      imgUrl="https://example.com/high-quality.jpg"
      alt="Progressive loading example"
      progressive={true}
      progressiveOptions={{
        blurAmount: 15,
        transitionDuration: 500
      }}
      width={600}
      height={400}
    />
  );
};

Responsive Images

import { ImageLazy } from "image-lazy-component";

const ResponsiveExample = () => {
  return (
    <ImageLazy
      imgUrl="https://example.com/image.jpg"
      alt="Responsive image"
      responsive={true}
      sizes="(max-width: 768px) 100vw, (max-width: 1024px) 50vw, 33vw"
      optimizationOptions={{
        quality: 85,
        format: 'webp'
      }}
      width="100%"
      height="auto"
    />
  );
};

With Error Handling and Retry

import { ImageLazy } from "image-lazy-component";

const RetryExample = () => {
  return (
    <ImageLazy
      imgUrl="https://example.com/might-fail.jpg"
      imgUrlDefault="https://placehold.co/400x300"
      alt="Image with retry"
      retryOptions={{
        retryCount: 3,
        retryDelay: 2000,
        timeout: 10000
      }}
      errorComponent={
        <div>😞 Failed to load after retries</div>
      }
      loadingComponent={
        <div>🔄 Loading...</div>
      }
    />
  );
};

Custom Skeleton Loading

import { ImageLazy } from "image-lazy-component";

const SkeletonExample = () => {
  return (
    <ImageLazy
      imgUrl="https://example.com/image.jpg"
      alt="Custom skeleton"
      showSkeleton={true}
      skeletonColor="#e0e0e0"
      loadingComponent={
        <div style={{ 
          display: 'flex', 
          alignItems: 'center', 
          justifyContent: 'center',
          height: '100%' 
        }}>
          Loading...
        </div>
      }
    />
  );
};

📚 Props Reference

Basic Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | imgUrl | string | - | Required. Main image URL | | imgUrlDefault | string | "https://placehold.co/280x200" | Fallback image URL | | alt | string | "" | Alternative text for accessibility | | width | string \| number | - | Image width | | height | string \| number | - | Image height | | className | string | "" | CSS class name | | style | CSSProperties | {} | Inline styles | | loading | "lazy" \| "eager" | "lazy" | Loading behavior |

Advanced Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | progressive | boolean | false | Enable progressive loading | | progressiveOptions | UseProgressiveImageOptions | {} | Progressive loading options | | responsive | boolean | false | Enable responsive images | | sizes | string | "(max-width: 768px) 100vw, (max-width: 1024px) 50vw, 33vw" | Sizes attribute for responsive images | | optimizationOptions | ImageOptimizationOptions | {} | Image optimization settings | | retryOptions | UseImageBrokenOptions | {} | Retry configuration | | showSkeleton | boolean | true | Show loading skeleton | | skeletonColor | string | "#f0f0f0" | Skeleton background color |

Event Handlers

| Prop | Type | Description | |------|------|-------------| | onClick | MouseEventHandler<HTMLImageElement> | Click event handler | | onLoad | MouseEventHandler<HTMLImageElement> | Load event handler | | onError | MouseEventHandler<HTMLImageElement> | Error event handler | | onMouseEnter | MouseEventHandler<HTMLImageElement> | Mouse enter handler | | onMouseLeave | MouseEventHandler<HTMLImageElement> | Mouse leave handler |

Custom Components

| Prop | Type | Description | |------|------|-------------| | loadingComponent | React.ReactNode | Custom loading indicator | | errorComponent | React.ReactNode | Custom error display |

🔧 Utility Functions

The package also exports utility functions for advanced image processing:

import { 
  optimizeImageUrl, 
  generateSrcSet, 
  isValidImageUrl,
  ensureHttps 
} from "image-lazy-component";

// Optimize image URL
const optimized = optimizeImageUrl("https://example.com/image.jpg", {
  width: 800,
  height: 600,
  quality: 85,
  format: 'webp'
});

// Generate responsive srcset
const srcSet = generateSrcSet("https://example.com/image.jpg", {
  quality: 80
});

// Validate image URL
const isValid = isValidImageUrl("https://example.com/image.jpg");

🎯 TypeScript Support

Full TypeScript support with comprehensive type definitions:

import { ImageLazy, ImageLazyProps } from "image-lazy-component";

const TypedComponent: React.FC<ImageLazyProps> = (props) => {
  return <ImageLazy {...props} />;
};

🔍 Browser Support

  • Modern browsers with Intersection Observer support
  • Fallback handling for older browsers
  • Supports WebP, AVIF format detection
  • Progressive enhancement approach

📄 License

MIT License - see LICENSE file for details.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📞 Support

If you have any questions or issues, please open an issue on GitHub.


Made with ❤️ by thind9xdev