Blame view

src/components/button/button.vue 3.92 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) {
22d9901b   wynn   update
22
                      return oneOf(value, ['default', 'primary', 'dashed', 'text', 'info', 'success', 'warning', 'error', 'search', 'confirm', 'cancel', 'reset']);
b4fe39f7   梁灏   Button add ghost ...
23
24
                  },
                  default: 'default'
7fa943eb   梁灏   init
25
26
27
28
29
30
31
32
              },
              shape: {
                  validator (value) {
                      return oneOf(value, ['circle', 'circle-outline']);
                  }
              },
              size: {
                  validator (value) {
77f1cc2e   梁灏   Checkbox add size...
33
                      return oneOf(value, ['small', 'large', 'default']);
48611626   梁灏   Button support gl...
34
35
                  },
                  default () {
fe5ffd7f   梁灏   fixed #4196 #4165
36
                      return !this.$IVIEW || this.$IVIEW.size === '' ? 'default' : this.$IVIEW.size;
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']);
                  }
              },
3d1f3cf6   梁灏   close #3402
47
48
49
50
51
52
53
54
              icon: {
                  type: String,
                  default: ''
              },
              customIcon: {
                  type: String,
                  default: ''
              },
71d9fc8e   梁灏   Button add new pr...
55
56
57
              long: {
                  type: Boolean,
                  default: false
bc6eb6f3   梁灏   Button add to, re...
58
              },
b4fe39f7   梁灏   Button add ghost ...
59
60
61
62
              ghost: {
                  type: Boolean,
                  default: false
              }
7fa943eb   梁灏   init
63
          },
698e3b61   梁灏   iButton add some ...
64
65
          data () {
              return {
698e3b61   梁灏   iButton add some ...
66
                  showSlot: true
b0893113   jingsam   :art: add eslint
67
              };
698e3b61   梁灏   iButton add some ...
68
          },
7fa943eb   梁灏   init
69
70
71
72
          computed: {
              classes () {
                  return [
                      `${prefixCls}`,
381417a8   梁灏   Update Button
73
                      `${prefixCls}-${this.type}`,
7fa943eb   梁灏   init
74
                      {
71d9fc8e   梁灏   Button add new pr...
75
                          [`${prefixCls}-long`]: this.long,
7fa943eb   梁灏   init
76
                          [`${prefixCls}-${this.shape}`]: !!this.shape,
381417a8   梁灏   Update Button
77
                          [`${prefixCls}-${this.size}`]: this.size !== 'default',
698e3b61   梁灏   iButton add some ...
78
                          [`${prefixCls}-loading`]: this.loading != null && this.loading,
b4fe39f7   梁灏   Button add ghost ...
79
80
                          [`${prefixCls}-icon-only`]: !this.showSlot && (!!this.icon || !!this.customIcon || this.loading),
                          [`${prefixCls}-ghost`]: this.ghost
7fa943eb   梁灏   init
81
                      }
b0893113   jingsam   :art: add eslint
82
                  ];
d77476f8   范文杰   [feature] 优化butto...
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
              },
              // 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
102
              }
698e3b61   梁灏   iButton add some ...
103
          },
99d0429e   梁灏   update Button & T...
104
          methods: {
f9a6a467   梁灏   update Button
105
              // Ctrl or CMD and click, open in new window when use `to`
d77476f8   范文杰   [feature] 优化butto...
106
              handleClickLink (event) {
99d0429e   梁灏   update Button & T...
107
                  this.$emit('click', event);
d77476f8   范文杰   [feature] 优化butto...
108
                  const openInNewWindow = event.ctrlKey || event.metaKey;
bc6eb6f3   梁灏   Button add to, re...
109
  
d77476f8   范文杰   [feature] 优化butto...
110
                  this.handleCheckClick(event, openInNewWindow);
9e5c7283   梁灏   Revert "Revert "u...
111
              }
99d0429e   梁灏   update Button & T...
112
          },
d47ea998   梁灏   support Button an...
113
          mounted () {
99d0429e   梁灏   update Button & T...
114
              this.showSlot = this.$slots.default !== undefined;
7fa943eb   梁灏   init
115
          }
b0893113   jingsam   :art: add eslint
116
      };
d6342fe1   jingsam   fixed ie bug
117
  </script>