koel/resources/assets/js/components/shared/overlay.vue

124 lines
2.5 KiB
Vue
Raw Normal View History

2015-12-13 04:42:28 +00:00
<template>
2016-11-30 09:23:11 +00:00
<div id="overlay" v-show="state.showing" class="overlay" :class="state.type">
2016-06-25 16:05:24 +00:00
<div class="display">
2016-10-31 04:28:12 +00:00
<sound-bar v-show="state.type === 'loading'"/>
<i class="fa fa-exclamation-circle" v-show="state.type === 'error'"/>
<i class="fa fa-exclamation-triangle" v-show="state.type === 'warning'"/>
<i class="fa fa-info-circle" v-show="state.type === 'info'"/>
<i class="fa fa-check-circle" v-show="state.type === 'success'"/>
2016-06-25 16:05:24 +00:00
2016-10-31 04:28:12 +00:00
<span v-html="state.message"/>
2015-12-13 04:42:28 +00:00
</div>
2016-06-25 16:05:24 +00:00
<button v-show="state.dismissable" @click.prevent="state.showing = false">Close</button>
</div>
2015-12-13 04:42:28 +00:00
</template>
<script>
2016-11-26 03:25:35 +00:00
import { assign } from 'lodash'
2016-06-25 16:05:24 +00:00
2016-11-26 03:25:35 +00:00
import { event } from '../../utils'
import soundBar from './sound-bar.vue'
2016-06-25 16:05:24 +00:00
export default {
components: { soundBar },
2016-11-26 03:25:35 +00:00
data () {
2016-06-25 16:05:24 +00:00
return {
state: {
showing: true,
dismissable: false,
/**
* Either 'loading', 'success', 'info', 'warning', or 'error'.
* This dictates the icon as well as possibly other visual appearances.
*
* @type {String}
*/
type: 'loading',
2016-11-26 03:25:35 +00:00
message: ''
}
}
2016-06-25 16:05:24 +00:00
},
methods: {
/**
* Shows the overlay.
*
* @param {String} message The message to display.
* @param {String} type (loading|success|info|warning|error)
* @param {Boolean} dismissable Whether to show the Close button
*/
2016-11-26 03:25:35 +00:00
show (options) {
assign(this.state, options)
this.state.showing = true
2016-06-25 16:05:24 +00:00
},
/**
* Hide the overlay.
*/
2016-11-26 03:25:35 +00:00
hide () {
this.state.showing = false
2016-06-25 16:05:24 +00:00
},
/**
* Set the overlay to be dismissable (or not).
* A Close button will be shown/hidden correspondingly.
*
* @param {Boolean} dismissable
*/
2016-11-26 03:25:35 +00:00
setDimissable (dismissable = true) {
this.state.dismissable = dismissable
}
2016-06-25 16:05:24 +00:00
},
2016-11-26 03:25:35 +00:00
created () {
2016-06-25 16:05:24 +00:00
event.on({
2016-09-23 10:12:42 +00:00
'overlay:show': options => this.show(options),
2016-11-26 03:25:35 +00:00
'overlay:hide': () => this.hide()
})
}
}
2015-12-13 04:42:28 +00:00
</script>
<style lang="sass">
2016-06-25 16:05:24 +00:00
@import "../../../sass/partials/_vars.scss";
@import "../../../sass/partials/_mixins.scss";
#overlay {
background-color: rgba(0, 0, 0, 1);
flex-direction: column;
.display {
@include vertical-center();
i {
margin-right: 6px;
2015-12-13 04:42:28 +00:00
}
2016-06-25 16:05:24 +00:00
}
button {
margin-top: 16px;
}
&.error {
color: $colorRed;
}
&.success {
color: $colorGreen;
}
&.info {
color: $colorBlue;
}
&.loading {
color: $color2ndText;
}
&.warning {
color: $colorOrange;
}
}
2015-12-13 04:42:28 +00:00
</style>