Giter Club home page Giter Club logo

react-global-loader's Introduction

React Global Loader

Simple Customizable Global React Loader. Demo page

Install

npm i react-global-loader

Simple Usage

Import LoaderContainer in App.js or root js

import { LoaderContainer } from "react-global-loader";

export default function App() {
  return (
    <div>
      <LoaderContainer />
    </div>
  );
}

Or LoaderContainer with default spinner component

import { LoaderContainer, DefaultSpinner } from "react-global-loader";

export default function App() {
  return (
    <div>
      <LoaderContainer>
        <DefaultSpinner />
      </LoaderContainer>
    </div>
  );
}

Or LoaderContainer with a image file

import { LoaderContainer } from "react-global-loader";
import FidgetLoader from "./loader.gif";

export default function App() {
  return (
    <div>
      <LoaderContainer>
        <img src={FidgetLoader} alt="loading" />
      </LoaderContainer>
    </div>
  );
}

Usage inside pages, components and services

import { loader } from "react-global-loader";

export default function PageName() {
  const showLoader = () => {
    loader.show();
  };

  const hideLoader = () => {
    loader.hide();
  };

  useEffect(() => {
    showLoader();

    setTimeout(() => {
      hideLoader();
    }, 3000);
  });

  return <div>Page 1</div>;
}

Extended Usage

import { LoaderContainer, loader } from "react-global-loader";

export default function App() {
  const showLoader = () => {
    loader.show();
  };

  const hideLoader = () => {
    loader.hide();
  };

  useEffect(() => {
    showLoader();

    setTimeout(() => {
      hideLoader();
    }, 3000);
  });

  const Arrow = () => (
    <div
      style={{
        width: 0,
        height: 0,
        borderTop: "10px solid transparent",
        borderRight: "20px solid red",
        borderBottom: "10px solid transparent",
      }}
    ></div>
  );

  return (
    <div>
      <LoaderContainer opacity={0.5} backgroundColor="#ccc">
        <div style={{ display: "inline-flex" }}>
          <Arrow />
          <div style={{ marginLeft: "10px" }}> Custom Loader</div>
        </div>
      </LoaderContainer>
    </div>
  );
}

Using with react-loader-spinner

If you are familiar with react-loader spinner please do check out the official page and npm page .

import { Audio } from "react-loader-spinner";
import { LoaderContainer, loader } from "react-global-loader";

export default function App() {
  useEffect(() => {
    loader.show();
    setTimeout(() => {
      loader.hide();
    }, 5000);
  });
  return (
    <LoaderContainer>
      <Audio
        height="100"
        width="100"
        color="#4fa94d"
        ariaLabel="audio-loading"
        wrapperStyle={{}}
        wrapperClass="wrapper-class"
        visible={true}
      />
    </LoaderContainer>
  );
}

Container Properties

Property Default Value Type Description
opacity 1 number Set Opacity level for overlay background
backgroundColor #0000003a string Set background color for overlay
justify center string Horizontal alignment of loader content (flex)
align center string Horizontal alignment of loader content (flex)
defaultText Loading.. string Default text for loader
defaultShow false boolean Set to true if you want to show by default
id rgl-overlay string HTML id value, if you want to have multiple type of loaders
autoHide false boolean If you want to automatically hide the loader after a certain time period
hideDuration 3000 number Increase or decrease the value if autoHide is enabled

Loader Properties

Property Default Value Type Description
id rgl-overlay string Pass Id if multiple loader are there to hide and show

react-global-loader's People

Contributors

shafeequeom avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.