mand-mobile/components/dialog/dialog.vue

295 lines
6.6 KiB
Vue
Raw Normal View History

2018-03-26 16:04:04 +08:00
<template>
<div class="md-dialog">
<md-popup
:value="value"
2018-03-26 16:04:04 +08:00
:hasMask="hasMask"
:maskClosable="maskClosable"
position="center"
2018-03-26 16:04:04 +08:00
:transition="transition"
:preventScroll="preventScroll"
:preventScrollExclude="preventScrollExclude"
@input="$_onInput"
@show="$_onShow"
@hide="$_onHide"
>
<div class="md-dialog-content">
<slot name="header"></slot>
2018-03-26 16:04:04 +08:00
<div class="md-dialog-body">
<a
role="button"
v-if="closable"
class="md-dialog-close"
@click="close"
>
2018-10-15 15:16:58 +08:00
<md-icon name="close" />
2018-03-26 16:04:04 +08:00
</a>
2018-03-30 11:16:44 +08:00
<div v-if="icon" class="md-dialog-icon">
2018-10-15 15:49:02 +08:00
<md-icon :name="icon" :svg="iconSvg"/>
2018-03-30 11:16:44 +08:00
</div>
2018-03-26 16:04:04 +08:00
<h2 class="md-dialog-title" v-if="title" v-text="title"></h2>
2018-08-27 19:15:52 +08:00
<slot>
<div class="md-dialog-text" v-html="content"></div>
</slot>
2018-03-26 16:04:04 +08:00
</div>
<footer class="md-dialog-actions" :class="{ 'is-column': layout === 'column' }">
<template v-for="(btn, index) in btns">
<a
role="button"
class="md-dialog-btn"
:class="{
disabled: !!btn.disabled,
warning: !btn.disabled && !!btn.warning
}"
:key="index"
@click="$_onClick(btn)"
@touchmove.prevent
>
<md-activity-indicator-rolling v-if="btn.loading" class="md-dialog-btn-loading"></md-activity-indicator-rolling>
<md-icon
v-else-if="btn.icon"
class="md-dialog-btn-icon"
:name="btn.icon"
:svg="btn.iconSvg"
size="md"
></md-icon>
{{ btn.text }}
</a>
</template>
2018-03-26 16:04:04 +08:00
</footer>
</div>
</md-popup>
</div>
</template>
<script> import Popup from '../popup'
import Icon from '../icon'
import ActivityIndicatorRolling from '../activity-indicator/roller'
import {mdDocument} from '../_util'
2018-03-26 16:04:04 +08:00
export default {
name: 'md-dialog',
components: {
[Popup.name]: Popup,
[Icon.name]: Icon,
[ActivityIndicatorRolling.name]: ActivityIndicatorRolling,
2018-03-26 16:04:04 +08:00
},
props: {
value: {
type: Boolean,
default: false,
},
title: {
type: String,
default: '',
},
icon: {
type: String,
default: '',
},
2018-10-15 15:49:02 +08:00
iconSvg: {
type: Boolean,
default: false,
},
2018-03-26 16:04:04 +08:00
closable: {
type: Boolean,
default: true,
},
content: {
type: String,
default: '',
},
btns: {
type: Array,
default() {
/* istanbul ignore next */
return []
},
2018-03-26 16:04:04 +08:00
},
layout: {
type: String,
default: 'row',
},
2018-03-26 16:04:04 +08:00
appendTo: {
default: () => mdDocument.body,
2018-03-26 16:04:04 +08:00
},
hasMask: {
type: Boolean,
default: true,
},
maskClosable: {
type: Boolean,
default: false,
},
transition: {
type: String,
default: 'md-fade',
2018-03-26 16:04:04 +08:00
},
preventScroll: {
type: Boolean,
default: false,
},
preventScrollExclude: {
type: String,
default: '',
},
},
mounted() {
if (this.appendTo) {
this.appendTo.appendChild(this.$el)
}
},
2018-04-18 15:05:47 +08:00
beforeDestroy() {
if (this.appendTo) {
this.appendTo.removeChild(this.$el)
}
},
2018-03-26 16:04:04 +08:00
methods: {
// MARK: private methods
// MARK: events handler
$_onInput(val) {
this.$emit('input', val)
},
$_onShow() {
this.$emit('show')
},
$_onHide() {
this.$emit('hide')
},
$_onClick(btn) {
if (btn.disabled || btn.loading) {
return
}
2018-03-26 16:04:04 +08:00
if (typeof btn.handler === 'function') {
btn.handler.call(null, btn)
2018-03-26 16:04:04 +08:00
} else {
this.close()
}
},
// MARK: public methods
close() {
this.$emit('input', false)
},
},
}
</script>
<style lang="stylus">
.md-dialog
2018-11-11 12:17:35 +08:00
.md-popup
2018-09-12 20:56:27 +08:00
z-index dialog-zindex
2018-08-27 19:15:52 +08:00
.md-dialog-content
width dialog-width
border-radius dialog-radius
background-color color-bg-inverse
2018-08-27 19:15:52 +08:00
overflow hidden
.md-dialog-body
color dialog-text-color
font-size dialog-text-font-size
text-align left
padding dialog-body-padding
2018-08-27 19:15:52 +08:00
.md-dialog-icon
position relative
display block
width dialog-icon-size
height dialog-icon-size
margin v-gap-md auto 28px
2018-08-27 19:15:52 +08:00
.md-dialog .md-dialog-icon .md-icon
.md-dialog .md-dialog-icon .md-icon.icon-svg
.md-dialog .md-dialog-icon .md-icon.icon-font
2018-10-15 15:16:58 +08:00
display flex
align-items center
justify-content center
position absolute
top 0
left 0
2018-08-27 19:15:52 +08:00
width dialog-icon-size
height dialog-icon-size
fill dialog-icon-fill
2018-10-15 15:16:58 +08:00
color dialog-icon-fill
font-size dialog-icon-size
line-height dialog-icon-size
2018-08-27 19:15:52 +08:00
.md-dialog-close
position absolute
color dialog-close-color
top 32px
right 32px
z-index 15
.md-dialog-title
color dialog-title-color
text-align center
font-size dialog-title-font-size
font-weight font-weight-normal
2018-08-27 19:15:52 +08:00
line-height 1.2
margin 0 0 28px 0
.md-dialog-text
display flex
justify-content center
.md-dialog-actions
2018-09-26 20:10:47 +08:00
position relative
2018-08-27 19:15:52 +08:00
display flex
hairline(top, dialog-action-border-color)
&.is-column
flex-direction column
2018-08-27 19:15:52 +08:00
.md-dialog-btn
flex 0 0 auto
remove-hairline(right)
2018-08-27 19:15:52 +08:00
&:not(:first-child)
hairline(top, dialog-action-border-color)
&:last-child
color color-text-minor
2018-08-27 19:15:52 +08:00
&:first-child
color dialog-action-highlight-color
.md-dialog-btn
2018-09-26 20:10:47 +08:00
position relative
2018-08-27 19:15:52 +08:00
flex 1 1 0%
display flex
align-items center
justify-content center
height dialog-action-height
font-size dialog-action-font-size
font-weight dialog-action-font-weight
color color-text-minor
2018-08-27 19:15:52 +08:00
text-align center
hairline(right, dialog-action-border-color)
transition background-color .3s
-webkit-user-select none
-webkit-tap-highlight-color transparent
&.warning
color color-text-error !important
.md-dialog-btn-loading .md-activity-indicator-svg .circle circle
stroke color-text-error !important
&.disabled
color color-text-disabled !important
.md-dialog-btn-loading .md-activity-indicator-svg .circle circle
stroke color-text-disabled !important
2018-08-27 19:15:52 +08:00
&:last-child
color dialog-action-highlight-color
remove-hairline(right)
.md-dialog-btn-loading .md-activity-indicator-svg .circle circle
stroke dialog-action-highlight-color
&:not(.disabled):active
background-color color-bg-tap
.md-dialog-btn-loading .md-activity-indicator-svg
width 32px !important
height 32px !important
margin-right 10px
.circle circle
stroke color-text-minor
.md-dialog-btn-icon
margin-right 10px
2018-03-26 16:04:04 +08:00
</style>