Blame view

src/components/button/button.vue 3.37 KB
7fa943eb   梁灏   init
1
  <template>
bc6eb6f3   梁灏   Button add to, re...
2
3
4
5
6
7
8
      <a
          v-if="to"
          :class="classes"
          :disabled="disabled"
          :href="linkUrl"
          :target="target"
          @click="handleClickLink">
929fdf5c   梁灏   update loading icon
9
          <Icon class="ivu-load-loop" type="ios-loading" v-if="loading"></Icon>
bc6eb6f3   梁灏   Button add to, re...
10
11
12
          <Icon :type="icon" :custom="customIcon" v-if="(icon || customIcon) && !loading"></Icon>
          <span v-if="showSlot" ref="slot"><slot></slot></span>
      </a>
8cc60d22   Graham Fairweather   Use an added styl...
13
      <button
bc6eb6f3   梁灏   Button add to, re...
14
          v-else
8cc60d22   Graham Fairweather   Use an added styl...
15
16
17
          :type="htmlType"
          :class="classes"
          :disabled="disabled"
bc6eb6f3   梁灏   Button add to, re...
18
          @click="handleClickLink">
929fdf5c   梁灏   update loading icon
19
          <Icon class="ivu-load-loop" type="ios-loading" v-if="loading"></Icon>
3d1f3cf6   梁灏   close #3402
20
          <Icon :type="icon" :custom="customIcon" v-if="(icon || customIcon) && !loading"></Icon>
d47ea998   梁灏   support Button an...
21
          <span v-if="showSlot" ref="slot"><slot></slot></span>
7fa943eb   梁灏   init
22
23
24
25
26
      </button>
  </template>
  <script>
      import Icon from '../icon';
      import { oneOf } from '../../utils/assist';
bc6eb6f3   梁灏   Button add to, re...
27
      import mixinsLink from '../../mixins/link';
7fa943eb   梁灏   init
28
29
  
      const prefixCls = 'ivu-btn';
7fa943eb   梁灏   init
30
31
  
      export default {
06322514   梁灏   support Radio
32
          name: 'Button',
bc6eb6f3   梁灏   Button add to, re...
33
          mixins: [ mixinsLink ],
7fa943eb   梁灏   init
34
35
36
37
          components: { Icon },
          props: {
              type: {
                  validator (value) {
b4fe39f7   梁灏   Button add ghost ...
38
39
40
                      return oneOf(value, ['default', 'primary', 'dashed', 'text', 'info', 'success', 'warning', 'error']);
                  },
                  default: 'default'
7fa943eb   梁灏   init
41
42
43
44
45
46
47
48
              },
              shape: {
                  validator (value) {
                      return oneOf(value, ['circle', 'circle-outline']);
                  }
              },
              size: {
                  validator (value) {
77f1cc2e   梁灏   Checkbox add size...
49
                      return oneOf(value, ['small', 'large', 'default']);
7fa943eb   梁灏   init
50
51
52
53
54
55
56
57
58
59
                  }
              },
              loading: Boolean,
              disabled: Boolean,
              htmlType: {
                  default: 'button',
                  validator (value) {
                      return oneOf(value, ['button', 'submit', 'reset']);
                  }
              },
3d1f3cf6   梁灏   close #3402
60
61
62
63
64
65
66
67
              icon: {
                  type: String,
                  default: ''
              },
              customIcon: {
                  type: String,
                  default: ''
              },
71d9fc8e   梁灏   Button add new pr...
68
69
70
              long: {
                  type: Boolean,
                  default: false
bc6eb6f3   梁灏   Button add to, re...
71
              },
b4fe39f7   梁灏   Button add ghost ...
72
73
74
75
              ghost: {
                  type: Boolean,
                  default: false
              }
7fa943eb   梁灏   init
76
          },
698e3b61   梁灏   iButton add some ...
77
78
          data () {
              return {
698e3b61   梁灏   iButton add some ...
79
                  showSlot: true
b0893113   jingsam   :art: add eslint
80
              };
698e3b61   梁灏   iButton add some ...
81
          },
7fa943eb   梁灏   init
82
83
84
85
86
87
          computed: {
              classes () {
                  return [
                      `${prefixCls}`,
                      {
                          [`${prefixCls}-${this.type}`]: !!this.type,
71d9fc8e   梁灏   Button add new pr...
88
                          [`${prefixCls}-long`]: this.long,
7fa943eb   梁灏   init
89
90
                          [`${prefixCls}-${this.shape}`]: !!this.shape,
                          [`${prefixCls}-${this.size}`]: !!this.size,
698e3b61   梁灏   iButton add some ...
91
                          [`${prefixCls}-loading`]: this.loading != null && this.loading,
b4fe39f7   梁灏   Button add ghost ...
92
93
                          [`${prefixCls}-icon-only`]: !this.showSlot && (!!this.icon || !!this.customIcon || this.loading),
                          [`${prefixCls}-ghost`]: this.ghost
7fa943eb   梁灏   init
94
                      }
b0893113   jingsam   :art: add eslint
95
                  ];
7fa943eb   梁灏   init
96
              }
698e3b61   梁灏   iButton add some ...
97
          },
99d0429e   梁灏   update Button & T...
98
          methods: {
bc6eb6f3   梁灏   Button add to, re...
99
              handleClickLink (event) {
99d0429e   梁灏   update Button & T...
100
                  this.$emit('click', event);
bc6eb6f3   梁灏   Button add to, re...
101
  
7d0b7384   梁灏   fixed #3484
102
                  this.handleCheckClick(event);
9e5c7283   梁灏   Revert "Revert "u...
103
              }
99d0429e   梁灏   update Button & T...
104
          },
d47ea998   梁灏   support Button an...
105
          mounted () {
99d0429e   梁灏   update Button & T...
106
              this.showSlot = this.$slots.default !== undefined;
7fa943eb   梁灏   init
107
          }
b0893113   jingsam   :art: add eslint
108
      };
d6342fe1   jingsam   fixed ie bug
109
  </script>