mand-mobile/components/dialog/dialog.vue

228 lines
4.5 KiB
Vue
Raw Normal View History

2018-03-26 16:04:04 +08:00
<template>
<div class="md-dialog">
<md-popup
:value="value"
: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">
<div class="md-dialog-body">
<a
role="button"
v-if="closable"
class="md-dialog-close"
@click="close"
>
<md-icon name="cross" />
</a>
2018-03-30 11:16:44 +08:00
<div v-if="icon" class="md-dialog-icon">
<md-icon :name="icon" />
</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' }">
2018-03-26 16:04:04 +08:00
<a
role="button"
class="md-dialog-btn"
2018-03-26 16:04:04 +08:00
v-for="(btn, index) in btns"
:key="index"
v-text="btn.text"
@click="$_onClick(btn)"
></a>
</footer>
</div>
</md-popup>
</div>
</template>
<script> import Popup from '../popup'
import Icon from '../icon'
export default {
name: 'md-dialog',
components: {
[Popup.name]: Popup,
[Icon.name]: Icon,
},
props: {
value: {
type: Boolean,
default: false,
},
title: {
type: String,
default: '',
},
icon: {
type: String,
default: '',
},
closable: {
type: Boolean,
default: true,
},
content: {
type: String,
default: '',
},
btns: {
type: Array,
default: () => [],
},
layout: {
type: String,
default: 'row',
},
2018-03-26 16:04:04 +08:00
appendTo: {
default: () => document.body,
},
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 (typeof btn.handler === 'function') {
btn.handler.call(null)
} else {
this.close()
}
},
// MARK: public methods
close() {
this.$emit('input', false)
},
},
}
</script>
<style lang="stylus">
.md-dialog
2018-09-12 20:56:27 +08:00
.md-popup.with-mask, .md-popup .md-popup-box
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-base
overflow hidden
.md-dialog-body
color dialog-text-color
font-size dialog-text-font-size
text-align left
padding v-gap-sl h-gap-sl
.md-dialog-icon
position relative
display block
width dialog-icon-size
height dialog-icon-size
margin v-gap-md auto
.md-dialog .md-dialog-icon .md-icon
width dialog-icon-size
height dialog-icon-size
fill dialog-icon-fill
.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
line-height 1.2
margin 0 0 28px 0
.md-dialog-text
display flex
justify-content center
.md-dialog-actions
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-caption
&:first-child
color dialog-action-highlight-color
.md-dialog-btn
flex 1 1 0%
display flex
align-items center
justify-content center
height dialog-action-height
font-size dialog-action-font-size
color color-text-caption
text-align center
hairline(right, dialog-action-border-color)
&:last-child
color dialog-action-highlight-color
remove-hairline(right)
2018-03-26 16:04:04 +08:00
</style>