Blame view

apps/components/action-sheet/action-sheet.vue 2.29 KB
htoooth authored
1
<template>
陈峰 authored
2
  <div v-transfer-dom :data-transfer="transfer">
陈峰 authored
3
    <transition name="action-sheet-move">
陈峰 authored
4
      <div class="yoho-popup" :class="actionCls" v-show="isVisible" :style="{'z-index': zIndex}">
TaoHuang authored
5
        <div class="yoho-popup-mask" @click="maskClick" v-if="mask"></div>
陈峰 authored
6 7
        <div class="yoho-popup-container">
          <div class="yoho-popup-content">
陈峰 authored
8 9 10
            <div class="detail">
              <slot></slot>
            </div>
陈峰 authored
11
          </div>
htoooth authored
12
        </div>
htoooth authored
13
      </div>
陈峰 authored
14 15
    </transition>
  </div>
htoooth authored
16 17 18 19 20 21 22 23 24 25
</template>

<script>
export default {
  name: 'YohoActionSheet',
  props: {
    maskClosable: {
      type: Boolean,
      default: true
    },
TaoHuang authored
26 27 28 29
    mask: {
      type: Boolean,
      default: true
    },
陈峰 authored
30
    transfer: Boolean,
htoooth authored
31 32
    zIndex: {
      type: Number,
陈峰 authored
33
      default: 100
htoooth authored
34 35 36 37
    },
    visible: {
      type: Boolean,
      default: false
htoooth authored
38 39 40 41
    },
    full: {
      type: Boolean,
      default: false
htoooth authored
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    }
  },
  data() {
    return {
      isVisible: false,
    };
  },
  mounted() {
    this.$watch('visible', (newVal) => {
      if (newVal) {
        this.show();
      } else {
        this.hide();
      }
    }, {
      immediate: true
    });
  },
htoooth authored
60 61 62 63 64
  computed: {
    actionCls() {
      return [{ 'yoho-action-sheet': this.full }];
    }
  },
htoooth authored
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
  methods: {
    maskClick() {
      this.maskClosable && this.cancel();
    },

    cancel() {
      this.hide();
      this.$emit('cancel');
    },

    show() {
      this.isVisible = true;
    },

    hide() {
      this.isVisible = false;
    }
  }
};

</script>

<style lang="scss" scoped>
htoooth authored
88 89 90 91
  .action-sheet-move-enter,
  .action-sheet-move-leave-active {
    transform: translate3d(0, 100%, 0);
  }
htoooth authored
92
陈峰 authored
93 94 95 96
  .action-sheet-move-enter-active {
    transition: all 0.2s cubic-bezier(0.165, 0.84, 0.44, 1);
  }
htoooth authored
97
  .action-sheet-move-leave-active {
陈峰 authored
98
    transition: all 0.2s ease;
htoooth authored
99
  }
htoooth authored
100
htoooth authored
101 102 103 104 105 106
  .yoho-popup {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
陈峰 authored
107
    z-index: 100;
htoooth authored
108 109 110 111 112 113 114

    .yoho-popup-mask {
      display: block;
    }

    .yoho-popup-mask,
    .yoho-popup-container {
TaoHuang authored
115
      background-color: rgba(0, 0, 0, 0);
htoooth authored
116 117 118 119 120 121
      position: absolute;
      width: 100%;
      height: 100%;
    }
  }
htoooth authored
122
  .yoho-action-sheet {
htoooth authored
123
    .yoho-popup-content {
htoooth authored
124 125
      height: 100%;
    }
htoooth authored
126 127
  }
htoooth authored
128 129
  .detail {
    position: relative;
陈峰 authored
130 131
    width: 100%;
    height: 100%;
htoooth authored
132
  }
htoooth authored
133 134

</style>