react-usespinner 1.0.15 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,12 +4,13 @@ interface Options {
4
4
  }
5
5
  interface SpinnerProps {
6
6
  children: React.ReactNode;
7
+ spinner: React.ReactNode;
7
8
  }
8
9
  declare const useSpinner: (globalOptions?: Options) => {
9
10
  start: (name: string, options?: Options) => void;
10
11
  end: (name: string) => void;
11
12
  clear: () => void;
12
13
  busy: () => boolean;
13
- SpinnerContainer: ({ children }: SpinnerProps) => JSX.Element | null;
14
+ SpinnerContainer: ({ spinner, children }: SpinnerProps) => JSX.Element;
14
15
  };
15
16
  export default useSpinner;
@@ -27,12 +27,16 @@ var useSpinner = function (globalOptions) {
27
27
  var _a = (0, react_1.useState)([]), actions = _a[0], setActions = _a[1];
28
28
  // set a timer that every second checks if any actions can be closed
29
29
  (0, react_1.useEffect)(function () {
30
- var timer = setTimeout(function () {
31
- if (actions) {
32
- setActions(function (prev) { return prev.filter(function (item) { return item.endtime > Date.now(); }); });
33
- }
34
- }, 1000);
35
- return function () { return clearTimeout(timer); };
30
+ if (actions.length > 0) {
31
+ var timer_1 = setTimeout(function () {
32
+ if (actions) {
33
+ setActions(function (prev) {
34
+ return prev.filter(function (item) { return item.endtime > Date.now(); });
35
+ });
36
+ }
37
+ }, 1000);
38
+ return function () { return clearTimeout(timer_1); };
39
+ }
36
40
  }, [actions]);
37
41
  // Allow the start of a new Action to be tracked
38
42
  var start = function (name, options) {
@@ -51,14 +55,15 @@ var useSpinner = function (globalOptions) {
51
55
  setActions([]);
52
56
  };
53
57
  var busy = function () {
58
+ console.log("Busy = ", actions && actions.length > 0);
54
59
  return actions && actions.length > 0;
55
60
  };
56
61
  // JSX component used to wrap spinner of choice
57
62
  var SpinnerContainer = function (_a) {
58
- var children = _a.children;
63
+ var spinner = _a.spinner, children = _a.children;
59
64
  // If no active Actions then dont display anything
60
- if (actions && actions.length === 0) {
61
- return null;
65
+ if (busy()) {
66
+ return (0, jsx_runtime_1.jsx)("div", __assign({ className: "useSpinner" }, { children: spinner }));
62
67
  }
63
68
  return (0, jsx_runtime_1.jsx)("div", __assign({ className: "useSpinner" }, { children: children }));
64
69
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-usespinner",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "Track actions in progress to know if a spinner should be display. Actions expire within 10 seconds if not expired in code",
5
5
  "private": false,
6
6
  "license": "MIT",