@kasko/fe-loading-indicator 1.0.3 → 1.1.1

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.
package/README.md CHANGED
@@ -1 +1,30 @@
1
- # fe-loading-indicator-lib
1
+ # FE loading indicator library
2
+
3
+ ## Installation
4
+ ```sh
5
+ yarn install
6
+ yarn build
7
+ ```
8
+
9
+ ## Installing in other projects
10
+ ```sh
11
+ yarn add @kasko/fe-loading-indicator
12
+ ```
13
+
14
+ ### Using in other projects
15
+ Requiring `@kasko/fe-loading-indicator` will return string that could be injected in
16
+ HTML using 'HtmlWebpackPlugin'.
17
+ ```js
18
+ const loader = require('@kasko/fe-loading-indicator')();
19
+ ```
20
+
21
+ Module accepts configuration object, where custom CSS loading colors could be provided e.g.
22
+ ```js
23
+ {
24
+ colors: ['red', 'green', 'white']
25
+ }
26
+ ```
27
+ Loader adds global `LoadingIndicator` instance, for more information see in [type definitions](dist/loader.d.ts)
28
+
29
+ ### Hiding loader
30
+ Call `window.LoadingIndicator.hide()` to hide loading indicator
@@ -0,0 +1,22 @@
1
+ declare var LoadingIndicator: LoadingIndicator;
2
+ declare global {
3
+ interface Window {
4
+ LoadingIndicator: LoadingIndicator;
5
+ }
6
+ }
7
+
8
+ export interface LoadingIndicator {
9
+ /**
10
+ * Hides loading indicator
11
+ */
12
+ hide: () => void;
13
+
14
+ /**
15
+ * Sets custom CSS colors for loading indicators.
16
+ * Currently supported 3 colors.
17
+ * Default values ['#ebbb2a', '#fff', '#a07c0f']
18
+ *
19
+ * @param {string[]} colors
20
+ */
21
+ setColors: (colors: string[]) => void;
22
+ }
package/dist/loader.js ADDED
@@ -0,0 +1,13 @@
1
+ module.exports = function (config = {}) {
2
+ let result = '<style title="li-loader">@keyframes spinner-loader{0%{transform:rotate(0deg)}to{transform:rotate(360deg)}}@keyframes spin{0%{transform:rotate(0deg)}to{transform:rotate(360deg)}}#loader-wrapper{position:fixed;top:0;left:0;width:100%;height:100%;z-index:1500}#loader-wrapper:not(.li-loaded){background:#222;opacity:.9}#loader,#loader::after,#loader::before{border-radius:50%;border:3px solid transparent}#loader{display:block;width:150px;height:150px;margin:-75px 0 0 -75px;z-index:1501;position:relative;left:50%;top:50%;border-top-color:"@color1";animation:spin 2s linear infinite}#loader::after,#loader::before{content:"";position:absolute;top:5px;left:5px;right:5px;bottom:5px;border-top-color:"@color2";animation:spin 3s linear infinite}#loader::after{top:15px;left:15px;right:15px;bottom:15px;border-top-color:"@color3";animation:spin 1.5s linear infinite}#loader-wrapper .loader-section{position:fixed;top:0;width:50%;height:100%;z-index:1500;transform:translateX(0)}.li-loaded .loader-section{background:#222;opacity:.9}#loader-wrapper .loader-section.section-left{left:0}#loader-wrapper .loader-section.section-right{right:0}#loader-wrapper.li-loaded .loader-section.section-left{transform:translateX(-100%);transition:all .7s .3s cubic-bezier(.645,.045,.355,1)}#loader-wrapper.li-loaded .loader-section.section-right{transform:translateX(100%);transition:all .7s .3s cubic-bezier(.645,.045,.355,1)}.li-loaded #loader{opacity:0;transition:all .3s ease-out}#loader-wrapper.li-loaded{visibility:hidden}.spinner-loader:not(:requigray){animation:spinner-loader 1500ms infinite linear;border-radius:.5em;box-shadow:#025983 1.5em 0 0 0,#025983 1.1em 1.1em 0 0,#025983 0 1.5em 0 0,#025983 -1.1em 1.1em 0 0,#025983 -1.5em 0 0 0,#025983 -1.1em -1.1em 0 0,#025983 0 -1.5em 0 0,#025983 1.1em -1.1em 0 0;display:inline-block;font-size:10px;width:1em;height:1em;margin:1.5em;overflow:hidden;text-indent:100%}</style> <script>function LoadingIndicator(){this.hide=function(){const o=document.getElementById("loader-wrapper");o&&o.classList.add("li-loaded")},this.setColors=function(o){for(var e,t=0;t<document.styleSheets.length;t++){var r=document.styleSheets.item(t);if("li-loader"===r.title){e=r;break}}e&&(e.insertRule("#loader { border-top-color:"+o[0]+"!important;}"),e.insertRule("#loader::before { border-top-color:"+o[1]+"!important;}"),e.insertRule("#loader::after { border-top-color:"+o[2]+"!important;}"))}}window.LoadingIndicator=new LoadingIndicator;</script> <div id="loader-wrapper"> <div id="loader"></div> <div class="loader-section section-left"></div> <div class="loader-section section-right"></div> </div> ';
3
+
4
+ if (!config.colors) {
5
+ config.colors = ['#ebbb2a', '#fff', '#a07c0f']
6
+ }
7
+
8
+ config.colors.forEach((color, index) => {
9
+ result = result.replace('\"@color' + (index + 1) + '\"', color);
10
+ });
11
+
12
+ return result;
13
+ }
package/gulpfile.js CHANGED
@@ -1,13 +1,11 @@
1
1
  const gulp = require('gulp');
2
2
  const less = require('gulp-less');
3
3
  const minifyCSS = require('gulp-csso');
4
- const inlineCss = require('gulp-inline-css');
5
4
  const runSequence = require('run-sequence');
6
- const htmlmin = require('gulp-htmlmin');
7
5
  const clean = require('gulp-clean');
8
- const htmlToJs = require('gulp-html-to-js');
9
6
  const replace = require('gulp-replace');
10
7
  const fs = require('fs');
8
+ const minify = require('gulp-minify');
11
9
 
12
10
  gulp.task('clean', function () {
13
11
  return gulp.src(['.tmp'], { read: false }).pipe(clean());
@@ -25,21 +23,35 @@ gulp.task('css', function () {
25
23
  .pipe(gulp.dest('.tmp/html'))
26
24
  });
27
25
 
28
- gulp.task('inline:css', function () {
26
+ gulp.task('inline', function () {
29
27
  return gulp.src('.tmp/html/*.html')
30
- .pipe(replace(/<link rel="stylesheet" href="loader.css">/, function (s) {
28
+ .pipe(replace(/<script href="loader.js"><\/script>/, function () {
29
+ const script = fs.readFileSync('./.tmp/loader-min.js', 'utf8');
30
+ return '<script>' + script + '</script>';
31
+ }))
32
+ .pipe(replace(/<link rel="stylesheet" href="loader.css">/, function () {
31
33
  const style = fs.readFileSync('.tmp/html/loader.css', 'utf8');
32
- return '<style>' + style + '</style>';
34
+ return '<style title="li-loader">' + style + '</style>';
33
35
  }))
34
36
  .pipe(gulp.dest('./.tmp'));
35
37
  });
36
38
 
39
+ gulp.task('compress', function () {
40
+ gulp.src('./src/loader.js')
41
+ .pipe(minify())
42
+ .pipe(gulp.dest('./.tmp'))
43
+ });
44
+
37
45
  gulp.task('compile', function () {
38
- return gulp.src('.tmp/loader.html')
39
- .pipe(htmlToJs())
40
- .pipe(gulp.dest('dist'));
46
+ return gulp.src('./conf/loader.js')
47
+ .pipe(replace(/\$template/, function () {
48
+ const content = fs.readFileSync('./.tmp/loader.html', 'utf8');
49
+
50
+ return content.toString().replace(/\n|\t/g, ' ');
51
+ }))
52
+ .pipe(gulp.dest('./dist'));
41
53
  });
42
54
 
43
55
  gulp.task('default', function (callback) {
44
- runSequence(['clean'], ['html', 'css'], ['inline:css'], ['compile'], ['clean'], callback);
45
- });
56
+ runSequence(['clean'], ['html', 'css', 'compress'], ['inline'], ['compile'], ['clean'], callback);
57
+ });
package/index.js CHANGED
@@ -1 +1 @@
1
- module.exports = require('./dist/loader.html.js');
1
+ module.exports = require('./dist/loader.js');
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@kasko/fe-loading-indicator",
3
3
  "shortname": "fe-loading-indicator",
4
- "version": "1.0.3",
4
+ "version": "1.1.1",
5
5
  "description": "Kasko frontend loading indicator",
6
6
  "license": "UNLICENSED",
7
- "main": "npdist/loader.html.js",
7
+ "main": "index.js",
8
8
  "less": "src/loader.less",
9
9
  "repository": {
10
10
  "type": "git",
@@ -13,20 +13,18 @@
13
13
  "bugs": {
14
14
  "url": "https://github.com/kasko/fe-loading-indicator-lib/issues"
15
15
  },
16
- "dependencies": {
17
- "gulp-clean": "^0.3.2",
18
- "gulp-replace": "^0.6.1"
19
- },
16
+ "dependencies": {},
20
17
  "devDependencies": {
21
18
  "gulp": "^3.9.1",
19
+ "gulp-clean": "^0.3.2",
22
20
  "gulp-csso": "^3.0.0",
23
- "gulp-html-to-js": "^0.0.5",
24
- "gulp-htmlmin": "^3.0.0",
25
- "gulp-inline-css": "^3.1.0",
26
21
  "gulp-less": "^3.3.2",
22
+ "gulp-minify": "^1.0.0",
23
+ "gulp-replace": "^0.6.1",
27
24
  "run-sequence": "^2.2.0"
28
25
  },
29
26
  "scripts": {
30
- "build": "gulp"
27
+ "build": "gulp",
28
+ "test": "echo 'No tests for this project!'"
31
29
  }
32
30
  }
package/src/loader.html CHANGED
@@ -1,6 +1,7 @@
1
1
  <link rel="stylesheet" href="loader.css">
2
+ <script href="loader.js"></script>
2
3
  <div id="loader-wrapper">
3
- <div id="loader"></div>
4
- <div class="loader-section section-left"></div>
5
- <div class="loader-section section-right"></div>
6
- </div>
4
+ <div id="loader"></div>
5
+ <div class="loader-section section-left"></div>
6
+ <div class="loader-section section-right"></div>
7
+ </div>
package/src/loader.js ADDED
@@ -0,0 +1,30 @@
1
+ function LoadingIndicator() {
2
+ this.hide = function () {
3
+ const elementById = document.getElementById('loader-wrapper');
4
+
5
+ if (elementById) {
6
+ elementById.classList.add('li-loaded');
7
+ }
8
+ };
9
+
10
+ this.setColors = function (colors) {
11
+ var styleSheet;
12
+
13
+ for (var i = 0; i < document.styleSheets.length; i++) {
14
+ var styleSheetItem = document.styleSheets.item(i);
15
+
16
+ if (styleSheetItem.title === 'li-loader') {
17
+ styleSheet = styleSheetItem;
18
+ break;
19
+ }
20
+ }
21
+
22
+ if (styleSheet) {
23
+ styleSheet.insertRule('#loader { border-top-color:' + colors[0] + '!important;}');
24
+ styleSheet.insertRule('#loader::before { border-top-color:' + colors[1] + '!important;}');
25
+ styleSheet.insertRule('#loader::after { border-top-color:' + colors[2] + '!important;}');
26
+ }
27
+ };
28
+ }
29
+
30
+ window.LoadingIndicator = new LoadingIndicator();
package/src/loader.less CHANGED
@@ -17,6 +17,11 @@
17
17
  z-index: 1500;
18
18
  }
19
19
 
20
+ #loader-wrapper:not(.li-loaded) {
21
+ background: #222;
22
+ opacity: .9;
23
+ }
24
+
20
25
  #loader {
21
26
  display: block;
22
27
  position: relative;
@@ -27,7 +32,7 @@
27
32
  margin: -75px 0 0 -75px;
28
33
  border-radius: 50%;
29
34
  border: 3px solid transparent;
30
- //border-top-color: @brand-primary;
35
+ border-top-color: "@color1";
31
36
  animation: spin 2s linear infinite;
32
37
  z-index: 1501;
33
38
  }
@@ -41,7 +46,7 @@
41
46
  bottom: 5px;
42
47
  border-radius: 50%;
43
48
  border: 3px solid transparent;
44
- border-top-color: #fff;
49
+ border-top-color: "@color2";
45
50
  animation: spin 3s linear infinite;
46
51
  }
47
52
 
@@ -54,7 +59,7 @@
54
59
  bottom: 15px;
55
60
  border-radius: 50%;
56
61
  border: 3px solid transparent;
57
- //border-top-color: darken(@brand-primary, 20%);
62
+ border-top-color: "@color3";
58
63
  animation: spin 1.5s linear infinite;
59
64
  }
60
65
 
@@ -73,12 +78,15 @@
73
78
  top: 0;
74
79
  width: 50%;
75
80
  height: 100%;
76
- background: #222;
77
- opacity: 0.9;
78
81
  z-index: 1500;
79
82
  transform: translateX(0);
80
83
  }
81
84
 
85
+ .li-loaded .loader-section {
86
+ background: #222;
87
+ opacity: .9;
88
+ }
89
+
82
90
  #loader-wrapper .loader-section.section-left {
83
91
  left: 0;
84
92
  }
@@ -89,28 +97,26 @@
89
97
 
90
98
  /* Loaded */
91
99
 
92
- #loader-wrapper.loaded .loader-section.section-left {
100
+ #loader-wrapper.li-loaded .loader-section.section-left {
93
101
  transform: translateX(-100%);
94
102
  transition: all 0.7s 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
95
103
  }
96
104
 
97
- #loader-wrapper.loaded .loader-section.section-right {
105
+ #loader-wrapper.li-loaded .loader-section.section-right {
98
106
  transform: translateX(100%);
99
107
  transition: all 0.7s 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
100
108
  }
101
109
 
102
- .loaded #loader {
110
+ .li-loaded #loader {
103
111
  opacity: 0;
104
112
  transition: all 0.3s ease-out;
105
113
  }
106
114
 
107
- #loader-wrapper.loaded {
115
+ #loader-wrapper.li-loaded {
108
116
  visibility: hidden;
109
- transform: translateY(-100%);
110
- transition: all 0.3s 1s ease-out;
111
117
  }
112
118
 
113
- .spinner-loader:not(:required) {
119
+ .spinner-loader:not(:requigray) {
114
120
  animation: spinner-loader 1500ms infinite linear;
115
121
  border-radius: 0.5em;
116
122
  box-shadow: #025983 1.5em 0 0 0, #025983 1.1em 1.1em 0 0, #025983 0 1.5em 0 0, #025983 -1.1em 1.1em 0 0, #025983 -1.5em 0 0 0, #025983 -1.1em -1.1em 0 0, #025983 0 -1.5em 0 0, #025983 1.1em -1.1em 0 0;
@@ -121,4 +127,4 @@
121
127
  margin: 1.5em;
122
128
  overflow: hidden;
123
129
  text-indent: 100%;
124
- }
130
+ }
package/conf/loader.js DELETED
@@ -1,2 +0,0 @@
1
- const test = require('../dist')
2
- console.log(test);
@@ -1,2 +0,0 @@
1
- 'use strict';
2
- module.exports = '<style>@keyframes spinner-loader{0%{transform:rotate(0deg)}to{transform:rotate(360deg)}}@keyframes spin{0%{transform:rotate(0deg)}to{transform:rotate(360deg)}}#loader-wrapper{position:fixed;top:0;left:0;width:100%;height:100%;z-index:1500}#loader,#loader::after,#loader::before{border-radius:50%;border:3px solid transparent}#loader{display:block;left:50%;top:50%;width:150px;height:150px;margin:-75px 0 0 -75px;animation:spin 2s linear infinite;z-index:1501;position:relative}#loader::after,#loader::before{content:"";position:absolute}#loader::before{border-top-color:#fff;top:5px;left:5px;right:5px;bottom:5px;animation:spin 3s linear infinite}#loader::after{top:15px;left:15px;right:15px;bottom:15px;animation:spin 1.5s linear infinite}#loader-wrapper .loader-section{position:fixed;top:0;width:50%;height:100%;background:#222;opacity:.9;z-index:1500;transform:translateX(0)}#loader-wrapper .loader-section.section-left{left:0}#loader-wrapper .loader-section.section-right{right:0}#loader-wrapper.loaded .loader-section.section-left,#loader-wrapper.loaded .loader-section.section-right{transform:translateX(-100%);transition:all .7s .3s cubic-bezier(.645,.045,.355,1)}#loader-wrapper.loaded .loader-section.section-right{transform:translateX(100%)}.loaded #loader{opacity:0;transition:all .3s ease-out}#loader-wrapper.loaded{visibility:hidden;transform:translateY(-100%);transition:all .3s 1s ease-out}.spinner-loader:not(:required){animation:spinner-loader 1500ms infinite linear;border-radius:.5em;box-shadow:#025983 1.5em 0 0 0,#025983 1.1em 1.1em 0 0,#025983 0 1.5em 0 0,#025983 -1.1em 1.1em 0 0,#025983 -1.5em 0 0 0,#025983 -1.1em -1.1em 0 0,#025983 0 -1.5em 0 0,#025983 1.1em -1.1em 0 0;display:inline-block;font-size:10px;width:1em;height:1em;margin:1.5em;overflow:hidden;text-indent:100%}</style>\n<div id="loader-wrapper">\n <div id="loader"></div>\n <div class="loader-section section-left"></div>\n <div class="loader-section section-right"></div>\n</div>';