Blame view

src/components/tag/tag.vue 1.94 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
  </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
24
25
          components: { Icon },
          props: {
              closable: {
                  type: Boolean,
                  default: false
              },
              color: {
                  validator (value) {
                      return oneOf(value, ['blue', 'green', 'red', 'yellow']);
                  }
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);
                  }
7fa943eb   梁灏   init
64
65
              }
          }
b0893113   jingsam   :art: add eslint
66
67
      };
  </script>