Blame view

src/components/button/button.vue 2.42 KB
7fa943eb   梁灏   init
1
  <template>
8cc60d22   Graham Fairweather   Use an added styl...
2
3
4
5
      <button
          :type="htmlType"
          :class="classes"
          :disabled="disabled"
9e5c7283   梁灏   Revert "Revert "u...
6
          @click="handleClick">
9817ce99   jingsam   :hammer: Use Icon...
7
8
          <Icon class="ivu-load-loop" type="load-c" v-if="loading"></Icon>
          <Icon :type="icon" v-if="icon && !loading"></Icon>
d47ea998   梁灏   support Button an...
9
          <span v-if="showSlot" ref="slot"><slot></slot></span>
7fa943eb   梁灏   init
10
11
12
13
14
15
16
      </button>
  </template>
  <script>
      import Icon from '../icon';
      import { oneOf } from '../../utils/assist';
  
      const prefixCls = 'ivu-btn';
7fa943eb   梁灏   init
17
18
  
      export default {
06322514   梁灏   support Radio
19
          name: 'Button',
7fa943eb   梁灏   init
20
21
22
23
          components: { Icon },
          props: {
              type: {
                  validator (value) {
6c912a7b   梁灏   update Button
24
                      return oneOf(value, ['primary', 'ghost', 'dashed', 'text', 'info', 'success', 'warning', 'error', 'default']);
7fa943eb   梁灏   init
25
26
27
28
29
30
31
32
33
                  }
              },
              shape: {
                  validator (value) {
                      return oneOf(value, ['circle', 'circle-outline']);
                  }
              },
              size: {
                  validator (value) {
77f1cc2e   梁灏   Checkbox add size...
34
                      return oneOf(value, ['small', 'large', 'default']);
7fa943eb   梁灏   init
35
36
37
38
39
40
41
42
43
44
                  }
              },
              loading: Boolean,
              disabled: Boolean,
              htmlType: {
                  default: 'button',
                  validator (value) {
                      return oneOf(value, ['button', 'submit', 'reset']);
                  }
              },
71d9fc8e   梁灏   Button add new pr...
45
46
47
48
49
              icon: String,
              long: {
                  type: Boolean,
                  default: false
              }
7fa943eb   梁灏   init
50
          },
698e3b61   梁灏   iButton add some ...
51
52
          data () {
              return {
698e3b61   梁灏   iButton add some ...
53
                  showSlot: true
b0893113   jingsam   :art: add eslint
54
              };
698e3b61   梁灏   iButton add some ...
55
          },
7fa943eb   梁灏   init
56
57
58
59
60
61
          computed: {
              classes () {
                  return [
                      `${prefixCls}`,
                      {
                          [`${prefixCls}-${this.type}`]: !!this.type,
71d9fc8e   梁灏   Button add new pr...
62
                          [`${prefixCls}-long`]: this.long,
7fa943eb   梁灏   init
63
64
                          [`${prefixCls}-${this.shape}`]: !!this.shape,
                          [`${prefixCls}-${this.size}`]: !!this.size,
698e3b61   梁灏   iButton add some ...
65
                          [`${prefixCls}-loading`]: this.loading != null && this.loading,
9e5c7283   梁灏   Revert "Revert "u...
66
                          [`${prefixCls}-icon-only`]: !this.showSlot && (!!this.icon || this.loading)
7fa943eb   梁灏   init
67
                      }
b0893113   jingsam   :art: add eslint
68
                  ];
7fa943eb   梁灏   init
69
              }
698e3b61   梁灏   iButton add some ...
70
          },
99d0429e   梁灏   update Button & T...
71
          methods: {
99d0429e   梁灏   update Button & T...
72
73
              handleClick (event) {
                  this.$emit('click', event);
9e5c7283   梁灏   Revert "Revert "u...
74
              }
99d0429e   梁灏   update Button & T...
75
          },
d47ea998   梁灏   support Button an...
76
          mounted () {
99d0429e   梁灏   update Button & T...
77
              this.showSlot = this.$slots.default !== undefined;
7fa943eb   梁灏   init
78
          }
b0893113   jingsam   :art: add eslint
79
      };
d6342fe1   jingsam   fixed ie bug
80
  </script>