Blame view

src/components/button/button.vue 3.49 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']);
48611626   梁灏   Button support gl...
50
51
52
                  },
                  default () {
                      return this.$IVIEW.size === '' ? 'default' : this.$IVIEW.size;
7fa943eb   梁灏   init
53
54
55
56
57
58
59
60
61
62
                  }
              },
              loading: Boolean,
              disabled: Boolean,
              htmlType: {
                  default: 'button',
                  validator (value) {
                      return oneOf(value, ['button', 'submit', 'reset']);
                  }
              },
3d1f3cf6   梁灏   close #3402
63
64
65
66
67
68
69
70
              icon: {
                  type: String,
                  default: ''
              },
              customIcon: {
                  type: String,
                  default: ''
              },
71d9fc8e   梁灏   Button add new pr...
71
72
73
              long: {
                  type: Boolean,
                  default: false
bc6eb6f3   梁灏   Button add to, re...
74
              },
b4fe39f7   梁灏   Button add ghost ...
75
76
77
78
              ghost: {
                  type: Boolean,
                  default: false
              }
7fa943eb   梁灏   init
79
          },
698e3b61   梁灏   iButton add some ...
80
81
          data () {
              return {
698e3b61   梁灏   iButton add some ...
82
                  showSlot: true
b0893113   jingsam   :art: add eslint
83
              };
698e3b61   梁灏   iButton add some ...
84
          },
7fa943eb   梁灏   init
85
86
87
88
          computed: {
              classes () {
                  return [
                      `${prefixCls}`,
381417a8   梁灏   Update Button
89
                      `${prefixCls}-${this.type}`,
7fa943eb   梁灏   init
90
                      {
71d9fc8e   梁灏   Button add new pr...
91
                          [`${prefixCls}-long`]: this.long,
7fa943eb   梁灏   init
92
                          [`${prefixCls}-${this.shape}`]: !!this.shape,
381417a8   梁灏   Update Button
93
                          [`${prefixCls}-${this.size}`]: this.size !== 'default',
698e3b61   梁灏   iButton add some ...
94
                          [`${prefixCls}-loading`]: this.loading != null && this.loading,
b4fe39f7   梁灏   Button add ghost ...
95
96
                          [`${prefixCls}-icon-only`]: !this.showSlot && (!!this.icon || !!this.customIcon || this.loading),
                          [`${prefixCls}-ghost`]: this.ghost
7fa943eb   梁灏   init
97
                      }
b0893113   jingsam   :art: add eslint
98
                  ];
7fa943eb   梁灏   init
99
              }
698e3b61   梁灏   iButton add some ...
100
          },
99d0429e   梁灏   update Button & T...
101
          methods: {
bc6eb6f3   梁灏   Button add to, re...
102
              handleClickLink (event) {
99d0429e   梁灏   update Button & T...
103
                  this.$emit('click', event);
bc6eb6f3   梁灏   Button add to, re...
104
  
7d0b7384   梁灏   fixed #3484
105
                  this.handleCheckClick(event);
9e5c7283   梁灏   Revert "Revert "u...
106
              }
99d0429e   梁灏   update Button & T...
107
          },
d47ea998   梁灏   support Button an...
108
          mounted () {
99d0429e   梁灏   update Button & T...
109
              this.showSlot = this.$slots.default !== undefined;
7fa943eb   梁灏   init
110
          }
b0893113   jingsam   :art: add eslint
111
      };
d6342fe1   jingsam   fixed ie bug
112
  </script>