Blame view

src/components/tag/tag.vue 5.24 KB
7fa943eb   梁灏   init
1
  <template>
456daf34   梁灏   support Tag
2
      <transition name="fade">
7d4b325b   zhigang.li   close #2406
3
4
5
          <div :class="classes" @click.stop="check" :style="wraperStyles">
              <span :class="dotClasses" v-if="showDot" :style="bgColorStyle"></span>
              <span :class="textClasses" :style="textColorStyle"><slot></slot></span>
78fc1e14   zhigang.li   update tag custom...
6
              <Icon v-if="closable" :class="iconClass" :color="lineColor" type="ios-close-empty" @click.native.stop="close"></Icon>
456daf34   梁灏   support Tag
7
8
          </div>
      </transition>
7fa943eb   梁灏   init
9
10
11
12
  </template>
  <script>
      import Icon from '../icon';
      import { oneOf } from '../../utils/assist';
7fa943eb   梁灏   init
13
      const prefixCls = 'ivu-tag';
7d4b325b   zhigang.li   close #2406
14
      const initColorList = ['blue', 'green', 'red', 'yellow', 'default'];
7fa943eb   梁灏   init
15
      export default {
34ee7b4a   梁灏   support Tree & ad...
16
          name: 'Tag',
7fa943eb   梁灏   init
17
18
19
20
21
22
          components: { Icon },
          props: {
              closable: {
                  type: Boolean,
                  default: false
              },
dc39cc31   daiyanze   Feature: Checkabl...
23
24
25
26
27
28
29
30
              checkable: {
                  type: Boolean,
                  default: false
              },
              checked: {
                  type: Boolean,
                  default: true
              },
7fa943eb   梁灏   init
31
              color: {
7d4b325b   zhigang.li   close #2406
32
33
                  type: String,
                  default: 'default'
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}`,
                      {
3f7a5f1a   zhigang.li   udpate notice
54
                          [`${prefixCls}-${this.color}`]: !!this.color && oneOf(this.color, initColorList),
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
              },
7d4b325b   zhigang.li   close #2406
61
              wraperStyles () {
40365cfc   zhigang.li   update
62
                  return oneOf(this.color, initColorList) ? {} : {background: this.isChecked ? this.defaultTypeColor : 'transparent', borderWidth: '1px', borderStyle: 'solid', borderColor: ((this.type !== 'dot' && this.type !== 'border' && this.isChecked) ? this.borderColor : this.lineColor), color: this.lineColor};
7d4b325b   zhigang.li   close #2406
63
              },
7fa943eb   梁灏   init
64
              textClasses () {
7d4b325b   zhigang.li   close #2406
65
66
67
                  return [
                      `${prefixCls}-text`,
                      this.type === 'border' ? (oneOf(this.color, initColorList) ? `${prefixCls}-color-${this.color}` : '') : '',
2a6f6058   zhigang.li   fixed the bug abo...
68
                      (this.type !== 'dot' && this.type !== 'border' && this.color !== 'default') ? (this.isChecked ? `${prefixCls}-color-white` : '') : ''
7d4b325b   zhigang.li   close #2406
69
                  ];
382c000c   梁灏   Tag add type prop...
70
71
72
73
              },
              dotClasses () {
                  return `${prefixCls}-dot-inner`;
              },
78fc1e14   zhigang.li   update tag custom...
74
              iconClass () {
7d4b325b   zhigang.li   close #2406
75
76
77
                  if (this.type === 'dot') {
                      return '';
                  } else if (this.type === 'border') {
3f7a5f1a   zhigang.li   udpate notice
78
                      return oneOf(this.color, initColorList) ? `${prefixCls}-color-${this.color}` : '';
7d4b325b   zhigang.li   close #2406
79
80
81
82
                  } else {
                      return this.color !== undefined ? (this.color === 'default' ? '' : 'rgb(255, 255, 255)') : '';
                  }
              },
78fc1e14   zhigang.li   update tag custom...
83
84
85
86
              showDot () {
                  return !!this.type && this.type === 'dot';
              },
              lineColor () {
7d4b325b   zhigang.li   close #2406
87
88
89
                  if (this.type === 'dot') {
                      return '';
                  } else if (this.type === 'border') {
78fc1e14   zhigang.li   update tag custom...
90
                      return this.color !== undefined ? (oneOf(this.color, initColorList) ? '' : this.color) : '';
7d4b325b   zhigang.li   close #2406
91
                  } else {
78fc1e14   zhigang.li   update tag custom...
92
                      return this.color !== undefined ? (this.color === 'default' ? '' : 'rgb(255, 255, 255)') : '';
7d4b325b   zhigang.li   close #2406
93
94
                  }
              },
40365cfc   zhigang.li   update
95
96
97
              borderColor () {
                  return this.color !== undefined ? (this.color === 'default' ? '' : this.color) : '';
              },
78fc1e14   zhigang.li   update tag custom...
98
99
100
              dotColor () {
                  return this.color !== undefined ? (oneOf(this.color, initColorList) ? '' : this.color) : '';
              },
7d4b325b   zhigang.li   close #2406
101
              textColorStyle () {
2a6f6058   zhigang.li   fixed the bug abo...
102
                  return oneOf(this.color, initColorList) ? {} : ((this.type !== 'dot' && this.type !== 'border') ? (this.isChecked ? {color: this.lineColor} : {}) : {color: this.lineColor});
7d4b325b   zhigang.li   close #2406
103
              },
7d4b325b   zhigang.li   close #2406
104
              bgColorStyle () {
78fc1e14   zhigang.li   update tag custom...
105
                  return oneOf(this.color, initColorList) ? {} : {background: this.dotColor};
7d4b325b   zhigang.li   close #2406
106
107
              },
              defaultTypeColor () {
78fc1e14   zhigang.li   update tag custom...
108
                  return (this.type !== 'dot' && this.type !== 'border') ? (this.color !== undefined ? (oneOf(this.color, initColorList) ? '' : this.color) : '') : '';
7fa943eb   梁灏   init
109
110
111
              }
          },
          methods: {
ec4117cb   梁灏   tag add prop: name
112
              close (event) {
4c6d9962   Aresn   Update tag.vue
113
114
115
116
117
                  if (this.name === undefined) {
                      this.$emit('on-close', event);
                  } else {
                      this.$emit('on-close', event, this.name);
                  }
dc39cc31   daiyanze   Feature: Checkabl...
118
              },
4c6d9962   Aresn   Update tag.vue
119
120
121
122
              check () {
                  if (!this.checkable) return;
                  const checked = !this.isChecked;
                  this.isChecked = checked;
ec4117cb   梁灏   tag add prop: name
123
                  if (this.name === undefined) {
4c6d9962   Aresn   Update tag.vue
124
                      this.$emit('on-change', checked);
ec4117cb   梁灏   tag add prop: name
125
                  } else {
4c6d9962   Aresn   Update tag.vue
126
                      this.$emit('on-change', checked, this.name);
ec4117cb   梁灏   tag add prop: name
127
                  }
7fa943eb   梁灏   init
128
129
              }
          }
b0893113   jingsam   :art: add eslint
130
      };
7d4b325b   zhigang.li   close #2406
131
  </script>