Socket
Socket
Sign inDemoInstall

react-top-loader

Package Overview
Dependencies
8
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-top-loader

Simple fixed-to-top progress bar / loader component for React (similar to sites like GitHub, Medium etc.)


Version published
Weekly downloads
1.4K
decreased by-23.22%
Maintainers
1
Install size
38.4 kB
Created
Weekly downloads
 

Readme

Source

react-top-loader

Simple fixed-to-top progress bar / loader component for React (similar to sites like GitHub, Medium etc.)

NPM

demo

Installation

npm install react-top-loader

or

yarn add react-top-loader

Usage

  • Just import TopLoader and set the show prop to true. This will show the indeterminate loader with looping animation at the top of the page.
  • Use the progress prop to control the animation manually.
  • The loading bar is fixed to top by default. Set fixed to false to disable it.

Here are some more examples:

import TopLoader from "react-top-loader";

const Examples = () => (
  <div>
    {/* Fixed to Top with looping animation */}
    <TopLoader show color="#61d800" />

    {/* Progress Indicator */}
    <div style={{ padding: 16 }}>
      <TopLoader show progress={0.2} fixed={false} backgroundColor="#ddd" />
    </div>

    {/* Animated */}
    <div style={{ padding: 16 }}>
      <Animator
        color="#61d800"
        fixed={false}
        backgroundColor="#ddd"
        progressDuration={400}
      />
    </div>

    {/* Indeterminate */}
    <div style={{ padding: 16 }}>
      <TopLoader backgroundColor="#eee6ff" show fixed={false} color="#0000e4" />
    </div>

    {/* Indeterminate (no background) */}
    <div style={{ padding: 16 }}>
      <div>Indeterminate (no background)</div>
      <TopLoader color="#D32F2F" show fixed={false} duration={2500} />
    </div>
  </div>
);

// Helper class to animate the loader
class Animator extends React.Component {
  state = { progress: 0 };

  componentDidMount() {
    setInterval(
      () => this.setState({ progress: Math.min(1, this.state.progress + 0.1) }),
      400
    );
  }

  render() {
    return <TopLoader show progress={this.state.progress} {...this.props} />;
  }
}

Props

PropTypeDefaultRequiredDescription
showbooleanfalseyesSet this to true to show the loader
progressnull (or) number (between 0 and 1)noIf undefined or null, indeterminate animated loader is shown. If specified, a fraction of the strip is filled
fixedbooleantruenoIf true, loader is shown at the top of the page (position:fixed). Otherwise you have to position it yourself
thicknessnumber2noThickness (height) of the loading strip in pixels (px)
colorstring"#03a9f4"noColor of the loading strip
backgroundColorstring"transparent"noColor of the empty region behind the loading strip (transparent by default)
delaynumber (milliseconds)0noShow the loader after a specified delay (use this to prevent flashing of loader of very short tasks/requests)
durationnumber (milliseconds)1500noDuration of the animation of the indeterminate loader (not applicable if progress is provided)
progressDurationnumber (milliseconds)400noIf you're changing the value of progress to animate the loader, then use this to control the speed of animation
zIndexnumber10000noZ-Index of the top-level loader div
classNamestringnoSpecify a custom class for the top-level div
styleobjectnoOverride styles for the top-level div

Credits

Developed by the Jovian.ml team. Released under the MIT Licence. Inspired by this Codepen example by Shahen Algoo.

FAQs

Last updated on 24 Feb 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc