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

react-blur-img

v1.0.6

Published

Reausable blur-image component

Downloads

786

Readme

BlurImg Component

The BlurImg component is a React component that provides a blurred placeholder image until the main image finishes loading. It also supports an optional loading spinner for a better user experience.

Try the Demo

Demo

Features

  • Lazy-loads images with a blurred placeholder.
  • Displays a loading spinner while the image loads.
  • Fully customizable via props for aspectRatio, objectFit, and objectPosition.
  • Easy to use and integrate into any React project.

Installation

  1. Download the package via NPM.
npm i react-blur-img
  1. Import the component in your project
import { BlurImg } from "react-blur-img";
  1. Usage
import { BlurImg } from "react-blur-img";
import { img } from "https://example.com/real-image.jpg";
import { placeHolder } from "https://example.com/placeholder.jpg";

function App() {
  return (
    <div>
      <BlurImg img={img} placeHolder={placeHolder} alt="Descriptive Alt Text" />
    </div>
  );
}

Props

Required props

| Prop | Type | Description | | :---------- | :------- | :-------------------------------------------- | | img | String | The image to render. | | placeHolder | String | PlaceHolder to render while image is loading. | | alt | String | The alt text |

Optional props

| Prop | Type | Default | Description | | :------------- | :-------------------------------------- | :-------- | :---------------------------------------------------------------------------------- | | aspectRatio | React.CSSProperties["aspectRatio"] | 1/1 | Controls the aspect ratio of the image (e.g., "16/9") | | objectFit | React.CSSProperties["objectFit"] | contain | Specifies how the image should fit within its container (e.g., "cover", "contain"). | | objectPosition | React.CSSProperties["objectPosition"] | center | Determines the position of the image within its container (e.g., "center", "top"). | | Spinner | SpinnerProps | | Can change the default Spinner. |

Spinner Props structure

| Prop | Type | Default | Description | | :---------- | :----------------------------------- | :------- | :----------------------------------------------------- | | width | React.CSSProperties["width"] | 40px | Controls the width for the spinner. | | height | React.CSSProperties["height"] | 40px | Controls the height for the spinner. | | borderWidth | React.CSSProperties["borderWidth"] | 4px | Controls the thicknes for the spinner. | | color | React.CSSProperties["borderColor"] | black | Controls the color for the spinner. | | style | React.CSSProperties["borderStyle"] | dotted | Controls the style for the spinner. | | borderTop | React.CSSProperties["borderTop"] | none | Controls Top border to create another rotating effect. |

CSS classes

| Name | Description | | :------------------ | :------------------------------------------------------------------------------------------------------------- | | blur-load-container | The main wrapper for the image and the loading placeholder. | | blur-load-img | Handle img style | | loaded | Added to the container once the image has fully loaded, removing the placeholder and making the image visible. | | blur-load-spinner | Defines the spinner's appearance and animation. |

Custom Spinner usage

import { BlurImg, SpinnerProps } from "react-blur-img";
import { img } from "https://example.com/real-image.jpg";
import { placeHolder } from "https://example.com/placeholder.jpg";

const spinner: SpinnerProps = {
  width: 40,
  height: 40,
  borderTop: "4px dashed red",
  color: "white",
  style: "dashed",
};

function App() {
  return (
    <div>
      <BlurImg
        img={img}
        placeHolder={placeHolder}
        alt="Descriptive Alt Text"
        spinner={spinner}
      />
    </div>
  );
}

Demo

Tip for Improving Placeholder Loading

To create a placeholder background similar to the original image, you can simply take the original image and resize it to a very small dimension, such as 20x20px or 30x30px. This way, the placeholder will visually resemble the final version, and its loading will be almost instantaneous due to the reduced size, providing a smoother user experience.