Giter VIP home page Giter VIP logo

react-loader-advanced's Introduction

react-loader-advanced

npm version Download Count

Show loader overlaying your component during async events.

React-loader-advanced provides a component into which you can wrap an arbitrary React component. The loader will fill the area of the component and display a loading message. You may need multiple loader containers at different parts of your page. This loader also supports setting priority for the loaders so that the lower priority loaders will never show if there is another loader already showing. This is beneficial when you want to prevent transparent loaders overlapping, which would look ugly.

Demo

Loader example

Install

npm install react-loader-advanced --save

Compatibility

Compatible with React versions 0.13.x, 0.14.x, ^15.0.0 and ^16.0.0.

Usage

1. Include Loader

Node:

import Loader from 'react-loader-advanced';

2. Wrap your component inside the loader

<Loader show={true} message={'loading'}>
  <SomeComponent />
</Loader>

3. Style the loader using foregroundStyle and backgroundStyle

<Loader foregroundStyle={{color: 'white'}}
  backgroundStyle={{backgroundColor: 'black'}}>
...

You may optionally disable all default styling by setting property disableDefaultStyles to true.

4. Optionally if you wish, hack the loader using CSS styles knowing the class-hierarchy

<div class="Loader__background">
  <div class="Loader__foreground">
    <div class="Loader__message">
      Loading
    </div>
  </div>
</div>

See more thorough structure in ./src/react-loader-advanced.js.

Options (props)

show (bool)
This is the only required prop. When true, loader overlay is displayed. When false, only actual content is displayed.

priority (int)
The loader(s) with the highest priority will always be the only loader(s) showing. If loaders with lower priorities stop loading before the one with the highest priority, they will never be shown. Default priority is 0.

hideContentOnLoad (bool)
Hide content underneath loader overlay when loading.

contentBlur (int = px)
Blur the background on browsers that support CSS filter().

message (node = element|string)
Set the displayed message on foreground while loading. Can be an arbitrary element like a spinner of your choice -- or just a simple string. Defaults to string "loading...".

messageStyle (obj)
Extends the message element style.

foregroundStyle (obj)
Set a style for the loader foreground. Extends default styles.

backgroundStyle (obj)
Set a style for the loader background. Extends default styles.

contentStyle (obj)
Extends the content wrapper element style.

disableDefaultStyles (bool)
Disables default styles for background, foreground and message if set to true (not recommended).

transitionConfig (object)
Configure ReactCSSTransitionGroup for the loader overlay to add e.g. fade animation. See: react-transition-group

FAQ

Can I use a spinner element?

Yes, you can define a spinner element in the message-prop.

const spinner = <span>any-spinner-you-want</span>;

<Loader message={spinner}>
...
</Loader>

License

MIT

react-loader-advanced's People

Contributors

hoeck avatar nygardk avatar vaihtovirta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-loader-advanced's Issues

TransitionConfig is a required prop?

I started seeing these warnings in my tests recently:

console.error node_modules/fbjs/lib/warning.js:33
      Warning: Failed prop type: The prop `transitionConfig` is marked as required in `Loader`, but its value is `undefined`.
          in Loader

Is transitionConfig now required on all usages?

I found the change in this diff: ec0bd46

Typescript Support

Hi, thanks for writing this component. Been using it with a React + Typescript app and was just wondering if you would accept a PR that adds type information (a single index.d.ts file, looking a bit like this one)?

Warning about usage of componentWillMount and componentWillReceiveProps in React 17.x

Hi,
This is a package that I have used in all of my react projects and kind of a mandatory package for me. Thank you for this amazing package.

Problem:

There are two warning messages that are getting displayed on my browser console. One is regarding usage of componentWillMount and another is componentWillReceiveProps.

Here are the warning messages:

Warning: componentWillMount has been renamed, and is not recommended for use. See https://fb.me/react-async-component-lifecycle-hooks for details.

* Move code with side effects to componentDidMount, and set initial state in the constructor.
* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.

Please update the following components: Loader
Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://fb.me/react-async-component-lifecycle-hooks for details.

* Move data fetching code or side effects to componentDidUpdate.
* If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state
* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.

Please update the following components: Loader

Here is the screenshot of what is being displayed:

Screenshot 2019-08-25 at 3 57 38 PM

Packages used:

I am using these package versions:

"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-loader-advanced": "^1.7.1"

Thank you again for this amazing package.

Loader doesn't cover the complete component

I am unsure if this has something to do with the react-loader-advanced, or the table component, but a column of the table is showing through.

Would this have something to do with the z-order of the table poking through?

image

import { EventEmitter } from 'events' dependency issue

When I linked against this component for a browser app, a global 'events' object was used in my bundle.js that I had not installed. I installed an events lib to see if that would fix the require(), but it did not. Is this an unresolved devDependency, or a moved package within React?

I'm building with rollupjs rather than webpack, fyi.

CSSTransitionGroup Limitations

Hi,

Great plug-in!

I have a question though. I am using the contentBlur attribute and adding a <Spinner /> in the message. Both of these combined with a CSSTransitionGroup transitionConfig applied to the loader.

Right when the show attribute is changed, the content blur is removed and the Spinner resets to its starting position while the "fade out" animation begins. This makes for a jumpy animation.

Is this a limitation of using CSSTransitionGroup or could something be worked inside the Loader component?

Thanks.

Ability to override loader content div styles

Hi I've been enjoying your component, but I recently came across a need to alter the loader__content div styles by adding "height: 100%". Since you provided classes I was able to accomplish it using a stylesheet, however I'm using inline styles everywhere else so I hate to have a stylesheet just for this one little fix.

I'd be happy to submit a pull request for the ability to override the content container via props if I thought you'd accept it. Or perhaps having the content div include "height: 100%" would be good default behavior.

Regardless, thanks for all your work!

Possible EventEmitter memory leak detected

possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.

Every instance of Loader adds a 'change' event listener in componentDidMount to the same EventEmitter. By default, if over 10 listeners are added with the same type (i.e. 'change') to a EventEmitter, events.js throws this error (should be warning imo) in the console.

It is a common scenario to use more than 10 loaders on one page, for example a dashboard of multiple async cards.

To reproduce, simply mount multiple loaders. (Code below untested)

import React from 'react'
import ReactDOM from 'react-dom'
import Loader from 'react-loader-advanced'

const App = () => (
  <div>
    <Loader show><div /></Loader>
    <Loader show><div /></Loader>
    <Loader show><div /></Loader>
    <Loader show><div /></Loader>
    <Loader show><div /></Loader>
    <Loader show><div /></Loader>
    <Loader show><div /></Loader>
    <Loader show><div /></Loader>
    <Loader show><div /></Loader>
    <Loader show><div /></Loader>
    <Loader show><div /></Loader>
  </div>
)

ReactDOM.render(<App />, document.body)

fade in/fade out

Possible to enhance and use ReactTransitionGroup to do mount/unmount animations on the loader div?
Maybe the callbacks can be to add some class/styles object - when hiding or showing the loader.
It will end up looking much smoother.

Performance Issues

Here are 2 screenshots from Chrome Dev Tools:

I'm creating around 1000 elements with loaders in them (Wont be the case in prod, but wanted to check perf)

Before loaders

With loaders

Console error when setting foregroundStyle of only one loader

I added the Loader as follows:

<Loader show={this.props.page.isFetching} message={spinner} hideContentOnLoad={true} backgroundStyle={{backgroundColor: 'transparent'}} foregroundStyle={{color: '#333'}}>
  <About page={this.props.page} about={this.props.about} social={this.props.social} />
</Loader>

When this runs, I receive the following error in the console:

Warning: div was passed a style object that has previously been mutated. Mutating style is deprecated. Consider cloning it beforehand. Check the render of Loader. Previous style: {display: "table", width: "100%", height: "100%", textAlign: "center", zIndex: 20, color: "#333"}. Mutated style: {display: "table", width: "100%", height: "100%", textAlign: "center", zIndex: 20, color: "transparent"}.

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.