A React loading indicator displayed globally or locally or both, which interoperate with each other.
-
Configurate global loading signal once for all (usually in ajax layer), and add any local loading signals anywhere, which could intercept global one, or not based on your needs.
-
Simple extendability to supply custom themes.
-
Support React 15.
npm install react-loading-signal
Take GlobalLoading
as example
import { GlobalLoading } from 'react-loading-signal';
const GlobalLoading = require('react-loading-signal').GlobalLoading;
import { GlobalLoading } from 'react-loading-signal/bundle';
or
const GlobalLoading = require('react-loading-signal/bundle').GlobalLoading;
or in global scope:
const GlobalLoading = LoadingSignal.GlobalLoading;
Substitute 'bundle' with 'bundle.min'.
// ajax layer
import { GlobalLoading, LocalLoading } from 'react-loading-signal';
const gLoading = new GlobalLoading();
// to change the global loading signal style, create a new one:
// new GlobalLoading(theme, true, true);
function request(url) {
const idLoading = gLoading.open();
// pass idLoading to LocalLoading, take redux for example:
// dispatch({ type: url, loading: idLoading })
fetch(url)
.then(function(response) {
return response.json();
}, () => {})
.then(function() {
gLoading.close(idLoading);
});
}
// local loading signal
<LocalLoading active={idLoading} />
- Spinning
- Blobs
- Circling
- Progress
import { Themes } from 'react-loading-signal';
const { Spinning, Blobs, Circling, Progress } = Themes;
Any valid React Component can be used as a theme. It will receive any props that's passed to LocalLoading
.
In bundled version, Classes are all prepended with LoadingSignal__
. Details please refer to /styles/LoadingSignal.css
. (src/styles/LoadingSignal.css
in source code.)
This class is singleton internally, But could be created more than once. Exactly that is the only correct way to change the global loading signal styles on the fly.
Parameters
theme
React.ComponentType<any> Customized theme. (optional, defaultSpinning
)masked
bool Whether to display overlay below. (optional, defaultfalse
)closable
bool Whether the signal can be closed by clicking the mask. (optional, defaultfalse
)
Open global loading signal
Parameters
msg
React.Node? Message to show. (React.Node: anything React can render.)
Returns Indicator An identifier for this signal, ignoring its internal structure.
Close a signal
Parameters
idLoading
Indicator The identifier returned by open().
Returns void
[static] Retrieve the GlobalLoading singleton instance.
Returns instance
-
Indicator
opaque - WhatGlobalLoaing.open()
returns, it's accepted byGlobalLoaing.close()
andLoadingProps.active
. -
Active
Indicator | bool - The type ofLoadingProps.active
. -
LoadingProps
- Props ofLocalLoading
active
Active - Flag its visibility. WhenIndicator
is passed, the global one will not shown. Passtrue
to leave global alone.masked
boolean - Flag its mask visibility. (optional, defaultfalse
)message
Node - Content to display. (optional, defaultundefined
)button
HTMLElement - Button to be disabled, both a property and a class nameddisabled
are set. (optional, defaultfalse
)container
HTMLElement | false - Container where its placed. When not provided, parentNode is implied. If set tofalse
, no signal will be shown, other functions still work. (optional, defaultundefined
)theme
React.ComponentType<*> - The Component defining its actual visual outlook. You can pass any props toLocalLoading
which will be relayed to this component. (optional, defaultBlobs
)
import { type Indicator, type Active, type LoadingProps } from 'react-loading-signal';
-
Caption
(number) => string Handler to generate progressing caption string. -
ProgressProps
Props ofProgress
Component.- message number The decimal number indicating current progress. The max is 1.
- caption Caption see above.
import { Themes } from 'react-loading-signal';
const { Progress } = Themes;
const Props: Themes.ProgressProps = {...};
// or
import { Progress, ProgressProps } from 'react-loading-signal/themes';
// or
import { Progress, type ProgressProps } from 'react-loading-signal/themes/progress';
- To test when developing, run the demo:
npm start
- E2e tests are run against PhantomJS v2.1.1, if you adopt other versions or tools, the snapshots shipped maybe invalidated, run this command to update:
npm run test:e2e--updateSnapshots
MIT.