all files / src/button/ button.vue

100% Statements 1/1
100% Branches 2/2
100% Functions 1/1
100% Lines 1/1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83                                                                                                                                                                   
<template>
  <button class="w-button" :class="{[`icon-${iconPosition}`]: true}" @click="$emit('click')">
    <w-icon class="icon" v-if="icon && !loading" :name="icon" ></w-icon>
    <w-icon class="loading icon" v-if="loading" name="loading"></w-icon>
    <div class="button-content">
      <slot />
    </div>
  </button>  
</template>
 
<script>
import Icon from '../icon/icon'
export default {
  name: 'WheelButton',
  components: {
    'w-icon': Icon
  },
  props: {
    icon: {},
    loading: {
      type: Boolean,
      default: false
    },
    iconPosition: {
      type: String,
      default: 'left',
      validator (value) {
        return value === 'left' || value === 'right'
      }
    }
  }
}
</script>
 
<style lang="scss" scoped>
  @import '../../styles/_var.scss';
 
  .w-button {
    height: $button-height;
    padding: 0 1em;
    font-size: $font-size;
    border-radius: $border-radius;
    border: 1px solid $border-color;
    background: $button-bg;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    vertical-align: middle;
    &:hover {
      cursor: pointer;
      border-color: $border-color-hover;
    }
    &:active {
      background: $button-active-bg;
    }
 
    &:focus {
      outline: none;
    }
    > .icon {
      order: 1;
      margin-right: .1em;
    }
    > .button-content {
      order: 2;
    }
    &.icon-right {
      > .icon {
        order: 2;
        margin-right: 0;
        margin-left: .1em;
      }
      > .button-content {
        order: 1;
      }
    }
    .loading {
      @include spin
    }
  }
 
</style>