Blame view

src/components/button/button.vue 2.64 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
          <Icon class="ivu-load-loop" type="load-c" v-if="loading"></Icon>
3d1f3cf6   梁灏   close #3402
8
          <Icon :type="icon" :custom="customIcon" v-if="(icon || customIcon) && !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']);
                  }
              },
3d1f3cf6   梁灏   close #3402
45
46
47
48
49
50
51
52
              icon: {
                  type: String,
                  default: ''
              },
              customIcon: {
                  type: String,
                  default: ''
              },
71d9fc8e   梁灏   Button add new pr...
53
54
55
56
              long: {
                  type: Boolean,
                  default: false
              }
7fa943eb   梁灏   init
57
          },
698e3b61   梁灏   iButton add some ...
58
59
          data () {
              return {
698e3b61   梁灏   iButton add some ...
60
                  showSlot: true
b0893113   jingsam   :art: add eslint
61
              };
698e3b61   梁灏   iButton add some ...
62
          },
7fa943eb   梁灏   init
63
64
65
66
67
68
          computed: {
              classes () {
                  return [
                      `${prefixCls}`,
                      {
                          [`${prefixCls}-${this.type}`]: !!this.type,
71d9fc8e   梁灏   Button add new pr...
69
                          [`${prefixCls}-long`]: this.long,
7fa943eb   梁灏   init
70
71
                          [`${prefixCls}-${this.shape}`]: !!this.shape,
                          [`${prefixCls}-${this.size}`]: !!this.size,
698e3b61   梁灏   iButton add some ...
72
                          [`${prefixCls}-loading`]: this.loading != null && this.loading,
3d1f3cf6   梁灏   close #3402
73
                          [`${prefixCls}-icon-only`]: !this.showSlot && (!!this.icon || !!this.customIcon || this.loading)
7fa943eb   梁灏   init
74
                      }
b0893113   jingsam   :art: add eslint
75
                  ];
7fa943eb   梁灏   init
76
              }
698e3b61   梁灏   iButton add some ...
77
          },
99d0429e   梁灏   update Button & T...
78
          methods: {
99d0429e   梁灏   update Button & T...
79
80
              handleClick (event) {
                  this.$emit('click', event);
9e5c7283   梁灏   Revert "Revert "u...
81
              }
99d0429e   梁灏   update Button & T...
82
          },
d47ea998   梁灏   support Button an...
83
          mounted () {
99d0429e   梁灏   update Button & T...
84
              this.showSlot = this.$slots.default !== undefined;
7fa943eb   梁灏   init
85
          }
b0893113   jingsam   :art: add eslint
86
      };
d6342fe1   jingsam   fixed ie bug
87
  </script>