Blame view

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