UNPKG

2.57 kBPlain TextView Raw
1<template>
2 <transition name="actionsheet-float">
3 <div v-show="currentValue" class="mint-actionsheet">
4 <ul class="mint-actionsheet-list" :style="{ 'margin-bottom': cancelText ? '5px' : '0' }">
5 <li v-for="( item, index ) in actions" class="mint-actionsheet-listitem" @click.stop="itemClick(item, index)">{{ item.name }}</li>
6 </ul>
7 <a class="mint-actionsheet-button" @click.stop="currentValue = false" v-if="cancelText">{{ cancelText }}</a>
8 </div>
9 </transition>
10</template>
11
12<style>
13 @component-namespace mint {
14 @component actionsheet {
15 position: fixed;
16 background: #e0e0e0;
17 width: 100%;
18 text-align: center;
19 bottom: 0;
20 left: 50%;
21 transform: translate3d(-50%, 0, 0);
22 backface-visibility: hidden;
23 transition: transform .3s ease-out;
24
25 @descendent list {
26 list-style: none;
27 padding: 0;
28 margin: 0;
29 }
30
31 @descendent listitem {
32 border-bottom: solid 1px #e0e0e0;
33 }
34
35 @descendent listitem, button {
36 display: block;
37 width: 100%;
38 height: 45px;
39 line-height: 45px;
40 font-size: 18px;
41 color: #333;
42 background-color: #fff;
43 &:active {
44 background-color: #f0f0f0;
45 }
46 }
47 }
48 }
49
50 .actionsheet-float-enter,
51 .actionsheet-float-leave-active {
52 transform: translate3d(-50%, 100%, 0);
53 }
54</style>
55
56<script type="text/babel">
57 import Popup from 'mint-ui/src/utils/popup';
58 import 'mint-ui/src/style/popup.css';
59
60 export default {
61 name: 'mt-actionsheet',
62
63 mixins: [Popup],
64
65 props: {
66 modal: {
67 default: true
68 },
69
70 modalFade: {
71 default: false
72 },
73
74 lockScroll: {
75 default: false
76 },
77
78 closeOnClickModal: {
79 default: true
80 },
81
82 cancelText: {
83 type: String,
84 default: '取消'
85 },
86
87 actions: {
88 type: Array,
89 default: () => []
90 }
91 },
92
93 data() {
94 return {
95 currentValue: false
96 };
97 },
98
99 watch: {
100 currentValue(val) {
101 this.$emit('input', val);
102 },
103
104 value(val) {
105 this.currentValue = val;
106 }
107 },
108
109 methods: {
110 itemClick(item, index) {
111 if (item.method && typeof item.method === 'function') {
112 item.method(item, index);
113 }
114 this.currentValue = false;
115 }
116 },
117
118 mounted() {
119 if (this.value) {
120 this.rendered = true;
121 this.currentValue = true;
122 this.open();
123 }
124 }
125 };
126</script>