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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nehaakram12/image-lazy-loader

v1.2.9

Published

React component for lazy loading Graph CMS Images. Optimizes initial page load time and provides optimal resolutions for different screen sizes. Loads blurry low resolution image initially which is later on replaced with HD images

Downloads

16

Readme

DEPRECATED SCOPE

This package has been published under a new scope name. Please use the latest version from now onwards.

@nehaakram12/image-lazy-loader

Description

React component for lazy loading Graph CMS Images in an optimal way that is performance efficient. On initial page load, images are downloaded with low resolution and blur filter from graph cms. Once the image element is in active viewport, the blurred image is replaced with original HD image and blur effect is removed.

Note

This is a work in progress, not ready for production yet. Your feedback would be appreciated, custom features can also be requested.

Requirements

Currently, works only for image urls from graph media cms. Support for other image sources will be added as enhanced feature later on.

Installation

npm i @nehaakram12/image-lazy-loader

Features

  • Performance efficient, reduces initial load time by loading low resolution blur images on page load
  • Optimal sized images generated automatically for different devices and screen sizes.
  • Preview images whilst loading in form of blurred thumbnails
  • Lazy loading enabling original HD images to download only when they are in the current viewport

Demo Screenshot

Demo

Code Sandbox Demo

Props

| Name | Type | Description | | ------------------ | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | | handle | string | Graph cms uses handle an identifier for images which is required to fetch images. | | alt | string | Passed to theimg element for alternate prop | | className | string\|object | Passed to the wrapper div of image.Object must follow react css rules | | width | number | Resolution need to be passed in order to display image. Defaults to 1400. | | height | number | Optional value in pixels if fixed height needs to be added to image elements. Defaults to null. See styling instructions below for better understanding. | | objectFitMode | bool | Fit image to be contained inside parent container. Defaults to false. | | isLazy | bool | Load images lazily, low to high resolution when active in viewport. Defaults to true | | breakpointWidths | array | Array of screen breakpoints for fluid image rendering and optimal sizes. Defaults to [320, 640, 1024] |

Example Usage

The package can be integrated inside a react component as follows:

import React from 'react';
import Picture from '@nehaakram12/image-lazy-loader';
import '@nehaakram12/image-lazy-loader/lib/main.css';

const Gallery = ({ data }) => {
  return (
    <div className={galleryWrapper}>
      {data.map(item => (
        <Picture
          handle={item.Picturehandle}
          className={'galleryImage'}
          objectFitMode
          width={1300}
          alt={item.postTitle}
        />
      ))}
    </div>
  );
};

export default Gallery;

Css and Styling

A classname can be passed to the Picture component that is attached to the wrapper element.

  • No height passed in className prop object: By default padding-bottom: 56.25% set on wrapper div.

  • Set custom height using className prop object: Pass padding-bottom: 0% !important in addition to the height in order to overwrite the default styles.

Note:

  • The default styles need to be imported in addition to the component import as can be seen in above example.
  • Feel free to style the image elements by overwriting the default css.

Issues

You can open issues in the Bugs and Issues section on the connected repository.

Inspired by: