├── .gitignore ├── LICENSE.md ├── README.md ├── package.json └── src ├── Bus.js ├── LoadingComponent.vue ├── LoadingMixin.js └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | package-lock.json 2 | node_modules/ -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016-2017 Val from Bubbleflat (@val-bubbleflat) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Component Loading 2 | 3 | by [bubbleflat.com]() 4 | 5 | This package allows you to manage a loading state inside all component, and to display a progressbar (thanks to [vue-progressbar](https://github.com/hilongjw/vue-progressbar)) to show the global loading state of your app. 6 | 7 | All components have their own loading state, but the progressbar show the global loading state of all components. 8 | 9 | ## Installation 10 | 11 | ```` 12 | npm install vue-component-loading 13 | ```` 14 | 15 | ```javascript 16 | import VueLoading from 'vue-component-loading' 17 | 18 | let config = { 19 | progressBar:{ 20 | color: '#000', 21 | failedColor: '#874b4b', 22 | thickness: '5px', 23 | transition: { 24 | speed: '0.2s', 25 | opacity: '0.6s', 26 | termination: 300 27 | }, 28 | } 29 | } 30 | 31 | Vue.use(VueLoading, config); 32 | ``` 33 | 34 | See [progressbar doc](https://github.com/hilongjw/vue-progressbar#constructor-options) for all options for the progressbar 35 | 36 | ## Usage 37 | 38 | First, register your progressbar : 39 | 40 | ```html 41 | 45 | ``` 46 | 47 | You can use these methods inside a component to manage its loading state 48 | 49 | ```javascript 50 | this.startLoading(); // --> this.loading = true : the component starts to load, the progressbar appear 51 | this.endLoading(); // --> this.loading = false : the component end to load, the progressbar progress :p (if it's the last component, it disappear) 52 | this.failLoading(); // --> this.loading = false : show the fail progressbar 53 | ``` 54 | 55 | Depending on the loading state, you can access `loading` boolean in your component 56 | 57 | ## Exemple 58 | 59 | ```html 60 | 65 | 79 | ``` 80 | 81 | ## License 82 | 83 | [The MIT License](https://opensource.org/licenses/MIT) -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-component-loading", 3 | "version": "1.0.0", 4 | "description": "Vuejs package, allow you to manage a loading state inside all component, and to display a progressbar", 5 | "main": "src/index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": { 10 | "name": "Valentin Vivies - Bubbleflat", 11 | "email": "valentin@bubbleflat.com", 12 | "url": "https://bubbleflat.com" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/val-bubbleflat/vue-component-loading" 17 | }, 18 | "keywords": [ 19 | "vue", 20 | "vue-component-loading", 21 | "vue loading", 22 | "progressbar", 23 | "vue progressbar" 24 | ], 25 | "license": "MIT", 26 | "bugs": { 27 | "url": "https://github.com/val-bubbleflat/vue-component-loading/issues" 28 | }, 29 | "homepage": "https://github.com/val-bubbleflat/vue-component-loading#readme", 30 | "dependencies": { 31 | "vue-progressbar": "^0.7.3" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Bus.js: -------------------------------------------------------------------------------- 1 | class Bus{ 2 | 3 | constructor(){ 4 | this.vue = null; 5 | } 6 | 7 | init(Vue){ 8 | this.vue = new Vue(); 9 | } 10 | 11 | $emit(event, arg){ 12 | if(this.vue){ 13 | this.vue.$emit(event, arg) 14 | } 15 | } 16 | 17 | $on(event, callback){ 18 | if(this.vue){ 19 | this.vue.$on(event, callback) 20 | } 21 | } 22 | 23 | } 24 | 25 | export default new Bus(); -------------------------------------------------------------------------------- /src/LoadingComponent.vue: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /src/LoadingMixin.js: -------------------------------------------------------------------------------- 1 | import Bus from './Bus' 2 | import Vue from 'vue' 3 | 4 | export default { 5 | 6 | methods: { 7 | 8 | startLoading(){ 9 | this.$options.load = true; 10 | Bus.$emit('start_loading') 11 | }, 12 | 13 | endLoading(){ 14 | this.$options.load = false; 15 | Bus.$emit('end_loading'); 16 | 17 | }, 18 | 19 | failLoading(){ 20 | this.$options.load = false; 21 | Bus.$emit('fail_loading'); 22 | 23 | } 24 | 25 | }, 26 | 27 | computed: { 28 | 29 | /*loading(){ 30 | return this.load 31 | }*/ 32 | 33 | }, 34 | 35 | beforeCreate(){ 36 | Vue.util.defineReactive(this.$options, 'load', false); 37 | if(!this.$options.computed){ 38 | this.$options.computed = {} 39 | } 40 | this.$options.computed["loading"] = function() { 41 | return this.$options.load; 42 | }; 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import Bus from './Bus' 2 | import LoadingMixin from './LoadingMixin'; 3 | import VueProgressBar from 'vue-progressbar'; 4 | import LoadingComponent from './LoadingComponent.vue' 5 | 6 | export default { 7 | 8 | install(Vue, config = {}){ 9 | Bus.init(Vue); 10 | 11 | let pbConfig = null; 12 | if(config.progressBar){ 13 | pbConfig = config.progressBar 14 | } 15 | Vue.use(VueProgressBar, pbConfig); 16 | 17 | Vue.mixin(LoadingMixin); 18 | Vue.component('vue-loading-component', LoadingComponent); 19 | } 20 | 21 | } --------------------------------------------------------------------------------