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

@pimred/lazyload

v0.1.0

Published

Pimred Lazyload

Downloads

1

Readme

@pimred/lazyload

Installation

npm install @pimred/lazyload

Usage

Basic example

import { Lazyload } from '@pimred/lazyload'

const MyComponent = () => {
  return (
    <Lazyload
      height={...}
      width={...}
      placeholder={(
        <div>Loading...</div>
      )}
    >
      <img
        src={...}
        height={...}
        width={...}
      />
    </Lazyload>
  )
}

Example

Lazyload demo

File App.js

import React from 'react'
import { Lazyload } from '@pimred/lazyload'
import '@pimred/lazyload/dist/index.css'

import './App.css'

function App () {
  const height = 500
  const width = 500
  const items = [
    {
      src    : `https://picsum.photos/${width}/${height}`,
      height : height,
      width  : width
    },
    {
      src    : `https://picsum.photos/${width}/${height}`,
      height : height,
      width  : width
    },
    {
      src    : `https://picsum.photos/${width}/${height}`,
      height : height,
      width  : width
    },
    {
      src    : `https://picsum.photos/${width}/${height}`,
      height : height,
      width  : width
    }
  ]
  return (
    <div className='App'>
      <h1 className='h1'>Example threshold = 0.15</h1>
      {items.map((item, index) => {
        return (
          <div className='lazyload' key={`lazyload-${index}`}>
            <Lazyload
              height={item.height}
              width={item.width}
              placeholder={(
                <div className='animated-background' />
              )}
            >
              <img
                src={item.src}
                height={height}
                width={width}
              />
            </Lazyload>
          </div>
        )
      })}
    </div>
  )
}

export default App

File App.css

@keyframes placeHolderShimmer{
  0%{
      background-position: -468px 0
  }
  100%{
      background-position: 468px 0
  }
}

.animated-background {
  animation-duration: 1.25s;
  animation-fill-mode: forwards;
  animation-iteration-count: infinite;
  animation-name: placeHolderShimmer;
  animation-timing-function: linear;
  background: linear-gradient(to right, lightgrey 8%, grey 18%, lightgrey 33%);
  background-size: 1200px 104px;
  position: relative;
  height: 100%;
}

.lazyload {
  width: 500px;
  height: 500px;
  padding: 10rem;
}

.h1 {
  padding-left: 10rem;
}

Props you can send to Lazyload | Option name | Type | Required | Default | Description | | -------------------------- | -------- | ----------- | ----------- | -------------------------------------------------- | | lazyLoadContainerClassName | string | no | | Override Style of Container | | lazyLoadContentClassName | string | no | | Override Style of Content | | width | number | yes | | Width of view lazyload | | height | number | yes | | Height of view lazyload | | widthMobile | number | no | | Width of view lazyload mobile | | heightMobile | number | no | | Height of view lazyload mobile | | children | node | yes | | Node elements wrapped by Lazyload | | placeholder | node | no | | Node element to show until lazy-load real content | | options | object | no | {} | Options for Intersection (root, rootMargin, threshold) | | responsiveBreakpoint | number | no | 768 | Breakpoint when lazyload switches to mobileWidth and mobileHeight |

Options params | Option name | Type | Required | Default | Description | | -------------- | -------- | ----------- | ----------- | -------------------------------------------------- | | root | | no | | The element that is used as the viewport for checking visibility of the target. Must be the ancestor of the target. Defaults to the browser viewport if not specified or if null. | | rootMargin | string | no | 0px | This set of values serves to grow or shrink each side of the root element's bounding box before computing intersections, the options are similar to those of margin in CSS. | | threshold | number | no | 0.15 | Either a single number or an array of numbers which indicate at what percentage of the target's visibility the observer's callback should be executed, ranges from 0 to 1.0, where 1.0 means every pixel is visible in the viewport. |

References: Intersection: https://dev.to/producthackers/intersection-observer-using-react-49ko

Development

First, build the dist files
npm run build

Then, publish to npm
npm publish --access public