Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-pulsable

Package Overview
Dependencies
Maintainers
0
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-pulsable

This is a simple and customizable react component library to add a pulsing/skeleton loading effect to your existing component.

  • 1.0.19
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13
decreased by-62.86%
Maintainers
0
Weekly downloads
 
Created
Source

React Pulsable

This is a simple react component that can be used to wrap other components and add a pulsing/skeleton effect to them.

Code Sandbox Link

Demo Image

Importing

import Pulsable from 'react-pulsable';
import 'react-pulsable/index.css';

how to use it?

const App = ({ isLoading }: { isLoading: boolean }) => {
  return (
    <>
      {/* default background */}
      <Pulsable isLoading={isLoading}>
        <YourComponent2 />
      </Pulsable>

      {/* custom background */}
      <Pulsable
        isLoading={isLoading}
        config={{
          bgColors: {
            light: 'rgba(0, 128, 0, 0.2)',
            medium: 'rgba(0, 128, 0, 0.3)',
          },
        }}
      >
        <YourComponent />
      </Pulsable>

      {/* custom background with no rounded corners */}
      <Pulsable
        isLoading={isLoading}
        config={{
          noRadius: true,
          bgColors: {
            light: 'rgba(0, 0, 255, 0.2)',
            medium: 'rgba(0, 0, 255, 0.3)',
          },
        }}
      >
        <YourComponent />
      </Pulsable>

      {/* custom background with no padding in each skeleton items */}
      <Pulsable
        isLoading={isLoading}
        config={{
          noPadding: true,
          bgColors: {
            light: 'tomato',
            medium: 'orange',
          },
        }}
      >
        <YourComponent />
      </Pulsable>
    </>
  );
};

what you have to do in your component?

const YourComponent = () => {
  return (
    <form>
      <label htmlFor="name" className="pulsable">
        Name:
      </label>
      <div className="pulsable">
        <input type="text" id="name" />
      </div>

      <label htmlFor="email" className="pulsable">
        Email:
      </label>
      <div className="pulsable">
        <input type="email" id="email" />
      </div>

      <button className="pulsable" type="submit">
        Submit
      </button>
    </form>
  );
};

Usage Guide

The component takes following props:

  • isLoading: a boolean that indicates whether the component should be pulsing or not.

  • config: an object that contains the configuration for the pulsing effect. It has following properties:

    • bgColors: an object that contains the background colors for the pulsing effect. It has two properties:
      • light: the light color of the background.
      • medium: the medium color of the background.
    • noRadius: a boolean that indicates whether the pulsing effect should have rounded corners or not. By default it has rounded corners.
    • noPadding: a boolean that indicates whether the pulsing effect should have padding in each skeleton items or not. By default it has padding.
    • animation: you can pass animation type as a string. default is wave and other options are wave-reverse, pulse, `none
  • className: as Pulsable component is a wrapper component, you can pass className or alomost all attributes of div element.[means you can treat it as a div, and use accordingly]

check example for more.

Conditions:

  • You must wrap the component you want to add the pulsing effect to with the Pulsable component.

  • You must provide isLoading state to the Pulsable component.

  • You can use the className="pulsable" to add the pulsing effect to any element.

  • if your component is a self closing tag like <img /> you should have to wrap it with div and add pulsable class to that.

  • if you want to hide some components while loading add class name pulsable-hidden

  • if you want to add image icon in skeleton add class name pulsable-img

  • for the paragraph use classname pulsable-para

  • while applying base config to all elements, you may need some exceptions. for that you can use pulsable-no-radius, pulsable-no-padding, pulsable-radius and pulsable-padding. by using these classes you can override some specific elements.

  • As Shown in example, for better performance you can use flex and align-items: flex-start in parentNode to avoid the pulsing effect from stretching the component. you can also add these styles conditionally wihile loading, if it's affecting your design.

Using CDN

for cdn you can use another package pulsable

Keywords

FAQs

Package last updated on 28 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc