Blame view

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