Blame view

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