all files / src/flatButton/ flatButton.vue

0% Statements 0/8
0% Branches 0/2
100% Functions 0/0
0% Lines 0/8
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204                                                                                                                                                                                                                                                                                                                                                                                                                       
<template>
<abstract-button
  :disabled="disabled" :keyboardFocused="keyboardFocused" wrapperClass="mu-flat-button-wrapper"
  :type="type" :href="href" :target="target" :style="buttonStyle" class="mu-flat-button"
  @click="handleClick" :rippleColor="rippleColor"
  @keyboardFocus="handleKeyboardFocus" @hover="handleHover" @hoverExit="handleHoverExit"
  :rippleOpacity="rippleOpacity"
  :class="buttonClass" :centerRipple="false">
  <span class="mu-flat-button-label" :class="labelClass" v-if="label && labelPosition === 'before'">{{label}}</span>
  <icon :value="icon" :class="iconClass"></icon>
  <slot></slot>
  <span class="mu-flat-button-label" :class="labelClass" v-if="label && labelPosition === 'after'">{{label}}</span>
</abstract-button>
</template>
 
<script>
import abstractButton from '../internal/abstractButton'
import icon from '../icon'
import {getColor} from '../utils'
export default {
  name: 'mu-flat-button',
  props: {
    icon: {
      type: String
    },
    iconClass: {
      type: [String, Array, Object]
    },
    type: {
      type: String
    },
    label: {
      type: String
    },
    labelPosition: {
      type: String,
      default: 'after'
    },
    labelClass: {
      type: [String, Array, Object],
      default: ''
    },
    primary: {
      type: Boolean,
      default: false
    },
    secondary: {
      type: Boolean,
      default: false
    },
    disabled: {
      type: Boolean,
      default: false
    },
    keyboardFocused: {
      type: Boolean,
      default: false
    },
    href: {
      type: String,
      default: ''
    },
    target: {
      type: String
    },
    backgroundColor: {
      type: String,
      default: ''
    },
    color: {
      type: String,
      default: ''
    },
    hoverColor: {
      type: String,
      default: ''
    },
    rippleColor: {
      type: String
    },
    rippleOpacity: {
      type: Number
    }
  },
  methods: {
    handleClick (e) {
      this.$emit('click', e)
    },
    handleKeyboardFocus (isFocus) {
      this.$emit('keyboardFocus', isFocus)
      this.$emit('keyboard-focus', isFocus)  // 兼容 html 里的用法
    },
    handleHover (event) {
      this.$emit('hover', event)
    },
    handleHoverExit (event) {
      this.$emit('hoverExit', event)
      this.$emit('hover-exit', event)  // 兼容 html 里的用法
    }
  },
  computed: {
    buttonStyle () {
      return {
        'background-color': this.hover ? getColor(this.hoverColor) : getColor(this.backgroundColor),
        'color': getColor(this.color)
      }
    },
    buttonClass () {
      return {
        'mu-flat-button-primary': this.primary,
        'mu-flat-button-secondary': this.secondary,
        'label-before': this.labelPosition === 'before',
        'no-label': !this.label
      }
    }
  },
  components: {
    'abstract-button': abstractButton,
    icon
  }
}
</script>
 
<style lang="less">
@import "../styles/import.less";
.mu-flat-button {
  display: inline-block;
  overflow: hidden;
  position: relative;
  border-radius: 2px;
  height: 36px;
  line-height: 36px;
  min-width: 88px;
  transition-duration: 300ms;
  transition-timing-function: @easeOutFunction;
  transform: translate3d(0, 0, 0);
  text-decoration: none;
  text-transform: uppercase;
  border: none;
  appearance: none;
  background: none;
  color: @textColor;
  .flex-shrink(0);
  margin: 0;
  outline: 0;
  padding: 0;
  cursor: pointer;
  &.hover {
    background-color: fade(@textColor, 10%);
  }
  &.disabled{
    color: @disabledColor;
    cursor: not-allowed;
    background: none;
  }
  .mu-icon {
    vertical-align: middle;
    margin-left: 12px;
    margin-right: 0;
    + .mu-flat-button-label {
      padding-left: 8px;
    }
 
  }
  &.no-label .mu-icon {
    margin-left: 0;
  }
  .mu-circle-ripple{
    color: @textColor;
  }
  &.label-before {
    padding-right: 8px;
    .mu-icon {
      margin-right: 4px;
      margin-left: 0;
    }
    .mu-flat-button-label {
      padding-right: 8px;
    }
  }
}
.mu-flat-button-wrapper{
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}
.mu-flat-button-primary{
  color: @primaryColor;
}
 
.mu-flat-button-secondary{
  color: @accentColor;
}
 
.mu-flat-button-label{
  vertical-align: middle;
  padding-right: 16px;
  padding-left: 16px;
  font-size: 14px;
}
 
</style>