action-sheet.vue 2.33 KB
<template>
  <transition name="action-sheet-fade">
    <div class="yoho-popup" :class="actionCls" v-show="isVisible" :style="{'z-index': zIndex}">
      <div class="yoho-popup-mask" @click="maskClick"></div>
      <div class="yoho-popup-container">
        <div class="yoho-popup-content">
          <transition name="action-sheet-move">
            <div class="detail" v-show="isVisible">
              <slot></slot>
            </div>
          </transition>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
import { Popup } from 'cube-ui';

export default {
  name: 'YohoActionSheet',
  props: {
    maskClosable: {
      type: Boolean,
      default: true
    },
    zIndex: {
      type: Number,
      default: 100
    },
    visible: {
      type: Boolean,
      default: false
    },
    full: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      isVisible: false,
    };
  },
  mounted() {
    this.$watch('visible', (newVal) => {
      if (newVal) {
        this.show();
      } else {
        this.hide();
      }
    }, {
      immediate: true
    });
  },
  computed: {
    actionCls() {
      return [{ 'yoho-action-sheet': this.full }];
    }
  },
  components: {
    Popup
  },
  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>
  .action-sheet-fade-enter,
  .action-sheet-fade-leave-active {
    opacity: 0;
  }

  .action-sheet-fade-enter-active,
  .action-sheet-fade-leave-active {
    transition: all 0.3s ease-in-out;
  }

  .action-sheet-move-enter,
  .action-sheet-move-leave-active {
    transform: translate3d(0, 100%, 0);
  }

  .action-sheet-move-enter-active,
  .action-sheet-move-leave-active {
    transition: all 0.3s ease-in-out;
  }

  .yoho-popup {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 100;

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

    .yoho-popup-mask,
    .yoho-popup-container {
      position: absolute;
      width: 100%;
      height: 100%;
    }
  }

  .yoho-action-sheet {
    .yoho-popup-content {
      height: 100%;
    }
  }

  .detail {
    position: relative;
  }

</style>