Blame view

src/components/tag/tag.vue 2.71 KB
7fa943eb   梁灏   init
1
  <template>
456daf34   梁灏   support Tag
2
      <transition name="fade">
dc39cc31   daiyanze   Feature: Checkabl...
3
          <div :class="classes" @click.stop="check">
4c6d9962   Aresn   Update tag.vue
4
              <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>
456daf34   梁灏   support Tag
5
6
          </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
          components: { Icon },
          props: {
              closable: {
                  type: Boolean,
                  default: false
              },
dc39cc31   daiyanze   Feature: Checkabl...
22
23
24
25
26
27
28
29
              checkable: {
                  type: Boolean,
                  default: false
              },
              checked: {
                  type: Boolean,
                  default: true
              },
7fa943eb   梁灏   init
30
31
              color: {
                  validator (value) {
ca131354   梁灏   update Tag
32
                      return oneOf(value, ['blue', 'green', 'red', 'yellow', 'default']);
7fa943eb   梁灏   init
33
                  }
382c000c   梁灏   Tag add type prop...
34
35
36
37
38
              },
              type: {
                  validator (value) {
                      return oneOf(value, ['border', 'dot']);
                  }
ec4117cb   梁灏   tag add prop: name
39
40
41
              },
              name: {
                  type: [String, Number]
7fa943eb   梁灏   init
42
43
              }
          },
dc39cc31   daiyanze   Feature: Checkabl...
44
45
46
47
48
          data () {
              return {
                  isChecked: this.checked
              };
          },
7fa943eb   梁灏   init
49
50
51
52
53
          computed: {
              classes () {
                  return [
                      `${prefixCls}`,
                      {
2079c47b   梁灏   update Tag
54
                          [`${prefixCls}-${this.color}`]: !!this.color,
382c000c   梁灏   Tag add type prop...
55
                          [`${prefixCls}-${this.type}`]: !!this.type,
dc39cc31   daiyanze   Feature: Checkabl...
56
                          [`${prefixCls}-closable`]: this.closable,
fd79f102   Aresn   Update tag.vue
57
                          [`${prefixCls}-checked`]: this.isChecked
7fa943eb   梁灏   init
58
                      }
b0893113   jingsam   :art: add eslint
59
                  ];
7fa943eb   梁灏   init
60
61
62
              },
              textClasses () {
                  return `${prefixCls}-text`;
382c000c   梁灏   Tag add type prop...
63
64
65
66
67
68
              },
              dotClasses () {
                  return `${prefixCls}-dot-inner`;
              },
              showDot () {
                  return !!this.type && this.type === 'dot';
7fa943eb   梁灏   init
69
70
71
              }
          },
          methods: {
ec4117cb   梁灏   tag add prop: name
72
              close (event) {
4c6d9962   Aresn   Update tag.vue
73
74
75
76
77
                  if (this.name === undefined) {
                      this.$emit('on-close', event);
                  } else {
                      this.$emit('on-close', event, this.name);
                  }
dc39cc31   daiyanze   Feature: Checkabl...
78
              },
4c6d9962   Aresn   Update tag.vue
79
80
81
82
              check () {
                  if (!this.checkable) return;
                  const checked = !this.isChecked;
                  this.isChecked = checked;
ec4117cb   梁灏   tag add prop: name
83
                  if (this.name === undefined) {
4c6d9962   Aresn   Update tag.vue
84
                      this.$emit('on-change', checked);
ec4117cb   梁灏   tag add prop: name
85
                  } else {
4c6d9962   Aresn   Update tag.vue
86
                      this.$emit('on-change', checked, this.name);
ec4117cb   梁灏   tag add prop: name
87
                  }
7fa943eb   梁灏   init
88
89
              }
          }
b0893113   jingsam   :art: add eslint
90
91
      };
  </script>