sba-confirm-button.vue 1.51 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<!--
  - Copyright 2014-2018 the original author or authors.
  -
  - Licensed under the Apache License, Version 2.0 (the "License");
  - you may not use this file except in compliance with the License.
  - You may obtain a copy of the License at
  -
  -     http://www.apache.org/licenses/LICENSE-2.0
  -
  - Unless required by applicable law or agreed to in writing, software
  - distributed under the License is distributed on an "AS IS" BASIS,
  - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  - See the License for the specific language governing permissions and
  - limitations under the License.
  -->

<template>
18 19 20 21
  <button @click="click" class="confirm-button" :class="{ 'is-warning' : confirm }" v-on-clickaway="abort">
    <slot name="confirm" v-if="confirm">Confirm</slot>
    <slot v-else/>
  </button>
22 23 24
</template>

<script>
25 26
  import {directive as onClickaway} from 'vue-clickaway';

27
  export default {
28
    directives: {onClickaway},
29 30 31 32
    data: () => ({
      confirm: false
    }),
    methods: {
33 34 35
      abort() {
        this.confirm = false;
      },
36 37
      click(event) {
        if (this.confirm) {
38
          this.$el.style.width = null;
39
          this.$emit('click', event);
40
        } else {
41 42
          const width = this.$el.getBoundingClientRect().width;
          this.$el.style.width = `${width}px`;
43 44 45 46 47
        }
        this.confirm = !this.confirm;
      }
    }
  }
48 49 50 51
</script>


<style lang="scss">
52
  @import "~@/assets/css/utilities";
53

54 55 56 57
  .confirm-button {
    transition: all $easing 150ms;
  }
</style>