Blame view

src/components/tag/tag.vue 2.22 KB
7fa943eb   梁灏   init
1
  <template>
456daf34   梁灏   support Tag
2
      <transition name="fade">
2c6c41be   zhigang.li   add event 'on-cli...
3
          <div :class="classes" @click.native.stop="clickTag">
456daf34   梁灏   support Tag
4
5
6
              <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
  </template>
  <script>
      import Icon from '../icon';
      import { oneOf } from '../../utils/assist';
  
      const prefixCls = 'ivu-tag';
  
      export default {
34ee7b4a   梁灏   support Tree & ad...
15
          name: 'Tag',
7fa943eb   梁灏   init
16
17
18
19
20
21
22
23
          components: { Icon },
          props: {
              closable: {
                  type: Boolean,
                  default: false
              },
              color: {
                  validator (value) {
ca131354   梁灏   update Tag
24
                      return oneOf(value, ['blue', 'green', 'red', 'yellow', 'default']);
7fa943eb   梁灏   init
25
                  }
382c000c   梁灏   Tag add type prop...
26
27
28
29
30
              },
              type: {
                  validator (value) {
                      return oneOf(value, ['border', 'dot']);
                  }
ec4117cb   梁灏   tag add prop: name
31
32
33
              },
              name: {
                  type: [String, Number]
7fa943eb   梁灏   init
34
35
              }
          },
7fa943eb   梁灏   init
36
37
38
39
40
          computed: {
              classes () {
                  return [
                      `${prefixCls}`,
                      {
382c000c   梁灏   Tag add type prop...
41
42
43
                          [`${prefixCls}-${this.color}`]: !!this.color,
                          [`${prefixCls}-${this.type}`]: !!this.type,
                          [`${prefixCls}-closable`]: this.closable
7fa943eb   梁灏   init
44
                      }
b0893113   jingsam   :art: add eslint
45
                  ];
7fa943eb   梁灏   init
46
47
48
              },
              textClasses () {
                  return `${prefixCls}-text`;
382c000c   梁灏   Tag add type prop...
49
50
51
52
53
54
              },
              dotClasses () {
                  return `${prefixCls}-dot-inner`;
              },
              showDot () {
                  return !!this.type && this.type === 'dot';
7fa943eb   梁灏   init
55
56
57
              }
          },
          methods: {
ec4117cb   梁灏   tag add prop: name
58
59
60
61
62
63
              close (event) {
                  if (this.name === undefined) {
                      this.$emit('on-close', event);
                  } else {
                      this.$emit('on-close', event, this.name);
                  }
2c6c41be   zhigang.li   add event 'on-cli...
64
65
66
67
68
69
70
              },
              clickTag (event) {
                  if (this.name === undefined) {
                      this.$emit('on-click', event);
                  } else {
                      this.$emit('on-click', event, this.name);
                  }
7fa943eb   梁灏   init
71
72
              }
          }
b0893113   jingsam   :art: add eslint
73
74
      };
  </script>