react-top-loading-bar

A very simple, highly customisable youtube-like react loader component.

README

react-top-loading-bar


>
NPM JavaScript Style Guide [![npm download][download-image]][download-url]

[download-image]: https://img.shields.io/npm/dm/react-top-loading-bar.svg
[download-url]: https://npmjs.org/package/react-top-loading-bar
react-top-loading-bar

Install


- using npm

  1. ``` sh
  2. npm install --save react-top-loading-bar
  3. ```

- using yarn

  1. ``` sh
  2. yarn add react-top-loading-bar
  3. ```

- CDN

  1. ```
  2. https://unpkg.com/react-top-loading-bar
  3. ```

Usage


With ref


  1. ``` js
  2. import React, { useRef } from 'react'
  3. import LoadingBar from 'react-top-loading-bar'

  4. const App = () => {
  5.   const ref = useRef(null)

  6.   return (
  7.     <div>
  8.       <LoadingBar color='#f11946' ref={ref} />
  9.       <button onClick={() => ref.current.continuousStart()}>
  10.         Start Continuous Loading Bar
  11.       </button>
  12.       <button onClick={() => ref.current.staticStart()}>
  13.         Start Static Loading Bar
  14.       </button>
  15.       <button onClick={() => ref.current.complete()}>Complete</button>
  16.       <br />
  17.     </div>
  18.   )
  19. }

  20. export default App
  21. ```

With state


  1. ``` js
  2. import React, { useState } from 'react'
  3. import LoadingBar from 'react-top-loading-bar'

  4. const App = () => {
  5.   const [progress, setProgress] = useState(0)

  6.   return (
  7.     <div>
  8.       <LoadingBar
  9.         color='#f11946'
  10.         progress={progress}
  11.         onLoaderFinished={() => setProgress(0)}
  12.       />
  13.       <button onClick={() => setProgress(progress + 10)}>Add 10%</button>
  14.       <button onClick={() => setProgress(progress + 20)}>Add 20%</button>
  15.       <button onClick={() => setProgress(100)}>Complete</button>
  16.       <br />
  17.     </div>
  18.   )
  19. }

  20. export default App
  21. ```

Demo



Built-in Methods


MethodsParametersDescriptions
-------------------------------------------:---------------------------------:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
add(value)NumberAdds
decrease(value)NumberDecreases
continuousStart(startingValue,NumberStarts
staticStart(startingValue)NumberStarts
complete()|

Properties


| Property         | Type     | Default | Description                                                                                                                       |
| :--------------- | :------- | :------ | :-------------------------------------------------------------------------------------------------------------------------------- |
| progress         | Number   | 0     | The progress/width indicator, progress prop varies from 0 to 100.                                                             |
| color            | String   | red   | The color of the loading bar, color take values like css property background: do, for example red, #000 rgb(255,0,0) etc. |
| shadow           | Boolean  | true  | Enables / Disables shadow underneath the loader.                                                                                  |
| height           | Number   | 2     | The height of the loading bar in pixels.                                                                                          |
| background       | String   | transparent     | The loader parent background color.                                                                                               |
| style       | CSSProperties   |    | The style attribute to loader's div                                                                                             |
| containerStyle       | CSSProperties   |    | The style attribute to loader's container                                                                                            |
| shadowStyle       | CSSProperties   |    | The style attribute to loader's shadow                                                                                          |
| transitionTime   | Number   | 300   | Fade transition time in miliseconds.                                                                                              |
| loaderSpeed      | Number   | 500   | Loader transition speed in miliseconds.                                                                                           |
| waitingTime      | Number   | 1000  | The delay we wait when bar reaches 100% before we proceed fading the loader out.                                                  |
| className        | String   |         | You can provide a class you'd like to add to the loading bar to add some styles to it                                             |
| containerClassName        | String   |         | You can provide a class you'd like to add to the loading bar container to add some css styles                                         |
| onLoaderFinished | Function |         | This is called when the loading bar completes, reaches 100% of his width.                                                         |

Projects using react-top-loading-bar



Add your own project. Make a PR

Migrate from V.1


- Replace onRef prop with 'ref', assign it to a react ref. Access methods with reactRef.current.xxx

Code Style

js-standard-style

License


MIT © Klendi Gocci | klendi.dev