Blame view

src/components/tag/tag.vue 1.68 KB
7fa943eb   梁灏   init
1
  <template>
456daf34   梁灏   support Tag
2
3
4
5
6
      <transition name="fade">
          <div :class="classes">
              <span :class="dotClasses" v-if="showDot"></span><span :class="textClasses"><slot></slot></span><Icon v-if="closable" type="ios-close-empty" @click.native.stop="close"></Icon>
          </div>
      </transition>
7fa943eb   梁灏   init
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  </template>
  <script>
      import Icon from '../icon';
      import { oneOf } from '../../utils/assist';
  
      const prefixCls = 'ivu-tag';
  
      export default {
          components: { Icon },
          props: {
              closable: {
                  type: Boolean,
                  default: false
              },
              color: {
                  validator (value) {
                      return oneOf(value, ['blue', 'green', 'red', 'yellow']);
                  }
382c000c   梁灏   Tag add type prop...
25
26
27
28
29
              },
              type: {
                  validator (value) {
                      return oneOf(value, ['border', 'dot']);
                  }
7fa943eb   梁灏   init
30
31
              }
          },
7fa943eb   梁灏   init
32
33
34
35
36
          computed: {
              classes () {
                  return [
                      `${prefixCls}`,
                      {
382c000c   梁灏   Tag add type prop...
37
38
39
                          [`${prefixCls}-${this.color}`]: !!this.color,
                          [`${prefixCls}-${this.type}`]: !!this.type,
                          [`${prefixCls}-closable`]: this.closable
7fa943eb   梁灏   init
40
                      }
b0893113   jingsam   :art: add eslint
41
                  ];
7fa943eb   梁灏   init
42
43
44
              },
              textClasses () {
                  return `${prefixCls}-text`;
382c000c   梁灏   Tag add type prop...
45
46
47
48
49
50
              },
              dotClasses () {
                  return `${prefixCls}-dot-inner`;
              },
              showDot () {
                  return !!this.type && this.type === 'dot';
7fa943eb   梁灏   init
51
52
53
54
              }
          },
          methods: {
              close (e) {
7fa943eb   梁灏   init
55
56
57
                  this.$emit('on-close', e);
              }
          }
b0893113   jingsam   :art: add eslint
58
59
      };
  </script>