@kasko/fe-loading-indicator 1.0.2 → 1.1.0

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,#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%;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.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;transform:translateY(-100%);transition:all .3s 1s ease-out}.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,11 +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');
6
+ const replace = require('gulp-replace');
7
+ const fs = require('fs');
8
+ const minify = require('gulp-minify');
9
9
 
10
10
  gulp.task('clean', function () {
11
11
  return gulp.src(['.tmp'], { read: false }).pipe(clean());
@@ -23,19 +23,35 @@ gulp.task('css', function () {
23
23
  .pipe(gulp.dest('.tmp/html'))
24
24
  });
25
25
 
26
- gulp.task('inline:css', function () {
26
+ gulp.task('inline', function () {
27
27
  return gulp.src('.tmp/html/*.html')
28
- .pipe(inlineCss())
29
- .pipe(htmlmin({ collapseWhitespace: true }))
30
- .pipe(gulp.dest('.tmp'))
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 () {
33
+ const style = fs.readFileSync('.tmp/html/loader.css', 'utf8');
34
+ return '<style title="li-loader">' + style + '</style>';
35
+ }))
36
+ .pipe(gulp.dest('./.tmp'));
37
+ });
38
+
39
+ gulp.task('compress', function () {
40
+ gulp.src('./src/loader.js')
41
+ .pipe(minify())
42
+ .pipe(gulp.dest('./.tmp'))
31
43
  });
32
44
 
33
45
  gulp.task('compile', function () {
34
- return gulp.src('.tmp/loader.html')
35
- .pipe(htmlToJs())
36
- .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'));
37
53
  });
38
54
 
39
55
  gulp.task('default', function (callback) {
40
- runSequence(['clean'], ['html', 'css'], ['inline:css'], ['compile'], ['clean'], callback);
41
- });
56
+ runSequence(['clean'], ['html', 'css', 'compress'], ['inline'], ['compile'], ['clean'], callback);
57
+ });
package/index.js CHANGED
@@ -1 +1 @@
1
- export default '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.2",
4
+ "version": "1.1.0",
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,19 +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
- },
16
+ "dependencies": {},
19
17
  "devDependencies": {
20
18
  "gulp": "^3.9.1",
19
+ "gulp-clean": "^0.3.2",
21
20
  "gulp-csso": "^3.0.0",
22
- "gulp-html-to-js": "^0.0.5",
23
- "gulp-htmlmin": "^3.0.0",
24
- "gulp-inline-css": "^3.1.0",
25
21
  "gulp-less": "^3.3.2",
22
+ "gulp-minify": "^1.0.0",
23
+ "gulp-replace": "^0.6.1",
26
24
  "run-sequence": "^2.2.0"
27
25
  },
28
26
  "scripts": {
29
- "build": "gulp"
27
+ "build": "gulp",
28
+ "test": "echo 'No tests for this project!'"
30
29
  }
31
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
@@ -27,7 +27,7 @@
27
27
  margin: -75px 0 0 -75px;
28
28
  border-radius: 50%;
29
29
  border: 3px solid transparent;
30
- //border-top-color: @brand-primary;
30
+ border-top-color: "@color1";
31
31
  animation: spin 2s linear infinite;
32
32
  z-index: 1501;
33
33
  }
@@ -41,7 +41,7 @@
41
41
  bottom: 5px;
42
42
  border-radius: 50%;
43
43
  border: 3px solid transparent;
44
- border-top-color: #fff;
44
+ border-top-color: "@color2";
45
45
  animation: spin 3s linear infinite;
46
46
  }
47
47
 
@@ -54,7 +54,7 @@
54
54
  bottom: 15px;
55
55
  border-radius: 50%;
56
56
  border: 3px solid transparent;
57
- //border-top-color: darken(@brand-primary, 20%);
57
+ border-top-color: "@color3";
58
58
  animation: spin 1.5s linear infinite;
59
59
  }
60
60
 
@@ -89,28 +89,28 @@
89
89
 
90
90
  /* Loaded */
91
91
 
92
- #loader-wrapper.loaded .loader-section.section-left {
92
+ #loader-wrapper.li-loaded .loader-section.section-left {
93
93
  transform: translateX(-100%);
94
94
  transition: all 0.7s 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
95
95
  }
96
96
 
97
- #loader-wrapper.loaded .loader-section.section-right {
97
+ #loader-wrapper.li-loaded .loader-section.section-right {
98
98
  transform: translateX(100%);
99
99
  transition: all 0.7s 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
100
100
  }
101
101
 
102
- .loaded #loader {
102
+ .li-loaded #loader {
103
103
  opacity: 0;
104
104
  transition: all 0.3s ease-out;
105
105
  }
106
106
 
107
- #loader-wrapper.loaded {
107
+ #loader-wrapper.li-loaded {
108
108
  visibility: hidden;
109
109
  transform: translateY(-100%);
110
110
  transition: all 0.3s 1s ease-out;
111
111
  }
112
112
 
113
- .spinner-loader:not(:required) {
113
+ .spinner-loader:not(:requigray) {
114
114
  animation: spinner-loader 1500ms infinite linear;
115
115
  border-radius: 0.5em;
116
116
  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 +121,4 @@
121
121
  margin: 1.5em;
122
122
  overflow: hidden;
123
123
  text-indent: 100%;
124
- }
124
+ }
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 = '<div id="loader-wrapper" style="height: 100%; left: 0; position: fixed; top: 0; width: 100%; z-index: 1500"><div id="loader" style="animation: spin 2s linear infinite; border: 3px solid transparent; border-radius: 50%; display: block; height: 150px; left: 50%; margin: -75px 0 0 -75px; position: relative; top: 50%; width: 150px; z-index: 1501"></div><div class="loader-section section-left" style="background: #222; height: 100%; left: 0; opacity: .9; position: fixed; top: 0; transform: translateX(0); width: 50%; z-index: 1500"></div><div class="loader-section section-right" style="background: #222; height: 100%; opacity: .9; position: fixed; right: 0; top: 0; transform: translateX(0); width: 50%; z-index: 1500"></div></div>';