Blame view

src/components/tag/tag.vue 6.08 KB
7fa943eb   梁灏   init
1
  <template>
5f4a9bd5   梁灏   Tag add prop fade
2
      <transition name="fade" v-if="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>
dc12b92c   梁灏   update Tag Icons
6
              <Icon v-if="closable" :class="iconClass" :color="lineColor" type="ios-close" @click.native.stop="close"></Icon>
456daf34   梁灏   support Tag
7
8
          </div>
      </transition>
5f4a9bd5   梁灏   Tag add prop fade
9
10
11
      <div v-else :class="classes" @click.stop="check" :style="wraperStyles">
          <span :class="dotClasses" v-if="showDot" :style="bgColorStyle"></span>
          <span :class="textClasses" :style="textColorStyle"><slot></slot></span>
dc12b92c   梁灏   update Tag Icons
12
          <Icon v-if="closable" :class="iconClass" :color="lineColor" type="ios-close" @click.native.stop="close"></Icon>
5f4a9bd5   梁灏   Tag add prop fade
13
      </div>
7fa943eb   梁灏   init
14
15
16
17
  </template>
  <script>
      import Icon from '../icon';
      import { oneOf } from '../../utils/assist';
7fa943eb   梁灏   init
18
      const prefixCls = 'ivu-tag';
855d4940   梁灏   Tag add more colo...
19
20
21
      const initColorList = ['default', 'primary', 'success', 'warning', 'error', 'blue', 'green', 'red', 'yellow', 'pink', 'magenta', 'volcano', 'orange', 'gold', 'lime', 'cyan', 'geekblue', 'purple'];
      const colorList = ['pink', 'magenta', 'volcano', 'orange', 'gold', 'lime', 'cyan', 'geekblue', 'purple'];
  
7fa943eb   梁灏   init
22
      export default {
34ee7b4a   梁灏   support Tree & ad...
23
          name: 'Tag',
7fa943eb   梁灏   init
24
25
26
27
28
29
          components: { Icon },
          props: {
              closable: {
                  type: Boolean,
                  default: false
              },
dc39cc31   daiyanze   Feature: Checkabl...
30
31
32
33
34
35
36
37
              checkable: {
                  type: Boolean,
                  default: false
              },
              checked: {
                  type: Boolean,
                  default: true
              },
7fa943eb   梁灏   init
38
              color: {
7d4b325b   zhigang.li   close #2406
39
40
                  type: String,
                  default: 'default'
382c000c   梁灏   Tag add type prop...
41
42
43
44
45
              },
              type: {
                  validator (value) {
                      return oneOf(value, ['border', 'dot']);
                  }
ec4117cb   梁灏   tag add prop: name
46
47
48
              },
              name: {
                  type: [String, Number]
5f4a9bd5   梁灏   Tag add prop fade
49
50
51
52
              },
              fade: {
                  type: Boolean,
                  default: true
7fa943eb   梁灏   init
53
54
              }
          },
dc39cc31   daiyanze   Feature: Checkabl...
55
56
57
58
59
          data () {
              return {
                  isChecked: this.checked
              };
          },
7fa943eb   梁灏   init
60
61
62
63
64
          computed: {
              classes () {
                  return [
                      `${prefixCls}`,
                      {
3f7a5f1a   zhigang.li   udpate notice
65
                          [`${prefixCls}-${this.color}`]: !!this.color && oneOf(this.color, initColorList),
382c000c   梁灏   Tag add type prop...
66
                          [`${prefixCls}-${this.type}`]: !!this.type,
dc39cc31   daiyanze   Feature: Checkabl...
67
                          [`${prefixCls}-closable`]: this.closable,
fd79f102   Aresn   Update tag.vue
68
                          [`${prefixCls}-checked`]: this.isChecked
7fa943eb   梁灏   init
69
                      }
b0893113   jingsam   :art: add eslint
70
                  ];
7fa943eb   梁灏   init
71
              },
7d4b325b   zhigang.li   close #2406
72
              wraperStyles () {
40365cfc   zhigang.li   update
73
                  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
74
              },
7fa943eb   梁灏   init
75
              textClasses () {
7d4b325b   zhigang.li   close #2406
76
77
78
                  return [
                      `${prefixCls}-text`,
                      this.type === 'border' ? (oneOf(this.color, initColorList) ? `${prefixCls}-color-${this.color}` : '') : '',
855d4940   梁灏   Tag add more colo...
79
                      (this.type !== 'dot' && this.type !== 'border' && this.color !== 'default') ? (this.isChecked && colorList.indexOf(this.color) < 0 ? `${prefixCls}-color-white` : '') : ''
7d4b325b   zhigang.li   close #2406
80
                  ];
382c000c   梁灏   Tag add type prop...
81
82
83
84
              },
              dotClasses () {
                  return `${prefixCls}-dot-inner`;
              },
78fc1e14   zhigang.li   update tag custom...
85
              iconClass () {
7d4b325b   zhigang.li   close #2406
86
87
88
                  if (this.type === 'dot') {
                      return '';
                  } else if (this.type === 'border') {
3f7a5f1a   zhigang.li   udpate notice
89
                      return oneOf(this.color, initColorList) ? `${prefixCls}-color-${this.color}` : '';
7d4b325b   zhigang.li   close #2406
90
91
92
93
                  } else {
                      return this.color !== undefined ? (this.color === 'default' ? '' : 'rgb(255, 255, 255)') : '';
                  }
              },
78fc1e14   zhigang.li   update tag custom...
94
95
96
97
              showDot () {
                  return !!this.type && this.type === 'dot';
              },
              lineColor () {
7d4b325b   zhigang.li   close #2406
98
99
100
                  if (this.type === 'dot') {
                      return '';
                  } else if (this.type === 'border') {
78fc1e14   zhigang.li   update tag custom...
101
                      return this.color !== undefined ? (oneOf(this.color, initColorList) ? '' : this.color) : '';
7d4b325b   zhigang.li   close #2406
102
                  } else {
78fc1e14   zhigang.li   update tag custom...
103
                      return this.color !== undefined ? (this.color === 'default' ? '' : 'rgb(255, 255, 255)') : '';
7d4b325b   zhigang.li   close #2406
104
105
                  }
              },
40365cfc   zhigang.li   update
106
107
108
              borderColor () {
                  return this.color !== undefined ? (this.color === 'default' ? '' : this.color) : '';
              },
78fc1e14   zhigang.li   update tag custom...
109
110
111
              dotColor () {
                  return this.color !== undefined ? (oneOf(this.color, initColorList) ? '' : this.color) : '';
              },
7d4b325b   zhigang.li   close #2406
112
              textColorStyle () {
2a6f6058   zhigang.li   fixed the bug abo...
113
                  return oneOf(this.color, initColorList) ? {} : ((this.type !== 'dot' && this.type !== 'border') ? (this.isChecked ? {color: this.lineColor} : {}) : {color: this.lineColor});
7d4b325b   zhigang.li   close #2406
114
              },
7d4b325b   zhigang.li   close #2406
115
              bgColorStyle () {
78fc1e14   zhigang.li   update tag custom...
116
                  return oneOf(this.color, initColorList) ? {} : {background: this.dotColor};
7d4b325b   zhigang.li   close #2406
117
118
              },
              defaultTypeColor () {
78fc1e14   zhigang.li   update tag custom...
119
                  return (this.type !== 'dot' && this.type !== 'border') ? (this.color !== undefined ? (oneOf(this.color, initColorList) ? '' : this.color) : '') : '';
7fa943eb   梁灏   init
120
121
122
              }
          },
          methods: {
ec4117cb   梁灏   tag add prop: name
123
              close (event) {
4c6d9962   Aresn   Update tag.vue
124
125
126
127
128
                  if (this.name === undefined) {
                      this.$emit('on-close', event);
                  } else {
                      this.$emit('on-close', event, this.name);
                  }
dc39cc31   daiyanze   Feature: Checkabl...
129
              },
4c6d9962   Aresn   Update tag.vue
130
131
132
133
              check () {
                  if (!this.checkable) return;
                  const checked = !this.isChecked;
                  this.isChecked = checked;
ec4117cb   梁灏   tag add prop: name
134
                  if (this.name === undefined) {
4c6d9962   Aresn   Update tag.vue
135
                      this.$emit('on-change', checked);
ec4117cb   梁灏   tag add prop: name
136
                  } else {
4c6d9962   Aresn   Update tag.vue
137
                      this.$emit('on-change', checked, this.name);
ec4117cb   梁灏   tag add prop: name
138
                  }
7fa943eb   梁灏   init
139
              }
5776bcbf   梁灏   fix #4587
140
141
142
143
144
          },
          watch: {
              checked (val) {
                  this.isChecked = val;
              }
7fa943eb   梁灏   init
145
          }
b0893113   jingsam   :art: add eslint
146
      };
7d4b325b   zhigang.li   close #2406
147
  </script>