Commit 7d4b325be875de8222bbbbfdb74e8a27126f5788
1 parent
e6508e27
close #2406
Showing
3 changed files
with
88 additions
and
14 deletions
Show diff stats
examples/routers/tag.vue
... | ... | @@ -14,6 +14,11 @@ |
14 | 14 | <Tag closable color="red" checkable>标签三</Tag> |
15 | 15 | <Tag closable color="yellow" checkable>标签四</Tag> |
16 | 16 | <br><br> |
17 | + <Tag closable color="#EF6AFF" checkable>标签一</Tag> | |
18 | + <Tag type="border" closable color="#EF6AFF" checkable>标签二</Tag> | |
19 | + <Tag type="dot" closable color="#EF6AFF" checkable>标签三</Tag> | |
20 | + <Tag closable color="default" checkable>标签四</Tag> | |
21 | + <br><br> | |
17 | 22 | <Tag type="border" closable color="blue" checkable>标签一</Tag> |
18 | 23 | <Tag type="border" closable color="green">标签二</Tag> |
19 | 24 | <Tag type="border" closable color="red">标签三</Tag> | ... | ... |
src/components/tag/tag.vue
1 | 1 | <template> |
2 | 2 | <transition name="fade"> |
3 | - <div :class="classes" @click.stop="check"> | |
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> | |
3 | + <div :class="classes" @click.stop="check" :style="wraperStyles"> | |
4 | + <span :class="dotClasses" v-if="showDot" :style="bgColorStyle"></span> | |
5 | + <span :class="textClasses" :style="textColorStyle"><slot></slot></span> | |
6 | + <Icon v-if="closable" type="ios-close-empty" :color="lineColor" @click.native.stop="close"></Icon> | |
5 | 7 | </div> |
6 | 8 | </transition> |
7 | 9 | </template> |
8 | 10 | <script> |
9 | 11 | import Icon from '../icon'; |
10 | 12 | import { oneOf } from '../../utils/assist'; |
11 | - | |
12 | 13 | const prefixCls = 'ivu-tag'; |
13 | - | |
14 | + const initColorList = ['blue', 'green', 'red', 'yellow', 'default']; | |
14 | 15 | export default { |
15 | 16 | name: 'Tag', |
16 | 17 | components: { Icon }, |
... | ... | @@ -28,9 +29,8 @@ |
28 | 29 | default: true |
29 | 30 | }, |
30 | 31 | color: { |
31 | - validator (value) { | |
32 | - return oneOf(value, ['blue', 'green', 'red', 'yellow', 'default']); | |
33 | - } | |
32 | + type: String, | |
33 | + default: 'default' | |
34 | 34 | }, |
35 | 35 | type: { |
36 | 36 | validator (value) { |
... | ... | @@ -58,14 +58,51 @@ |
58 | 58 | } |
59 | 59 | ]; |
60 | 60 | }, |
61 | + wraperStyles () { | |
62 | + return oneOf(this.color, initColorList) ? {} : {background: this.defaultTypeColor, borderColor: this.lineColor, color: this.lineColor}; | |
63 | + }, | |
61 | 64 | textClasses () { |
62 | - return `${prefixCls}-text`; | |
65 | + return [ | |
66 | + `${prefixCls}-text`, | |
67 | + this.type === 'border' ? (oneOf(this.color, initColorList) ? `${prefixCls}-color-${this.color}` : '') : '', | |
68 | + (this.type !== 'dot' && this.type !== 'border' && this.color !== 'default') ? `${prefixCls}-color-white` : '' | |
69 | + ]; | |
63 | 70 | }, |
64 | 71 | dotClasses () { |
65 | 72 | return `${prefixCls}-dot-inner`; |
66 | 73 | }, |
67 | 74 | showDot () { |
68 | 75 | return !!this.type && this.type === 'dot'; |
76 | + }, | |
77 | + lineColor () { | |
78 | + if (this.type === 'dot') { | |
79 | + return ''; | |
80 | + } else if (this.type === 'border') { | |
81 | + return this.color !== undefined ? this.transferColor(this.color) : ''; | |
82 | + } else { | |
83 | + return this.color !== undefined ? (this.color === 'default' ? '' : 'rgb(255, 255, 255)') : ''; | |
84 | + } | |
85 | + }, | |
86 | + borderColor () { | |
87 | + if (this.type === 'dot') { | |
88 | + return ''; | |
89 | + } else if (this.type === 'border') { | |
90 | + return this.color !== undefined ? this.transferColor(this.color) : ''; | |
91 | + } else { | |
92 | + return ''; | |
93 | + } | |
94 | + }, | |
95 | + textColorStyle () { | |
96 | + return oneOf(this.color, initColorList) ? {} : {color: this.lineColor}; | |
97 | + }, | |
98 | + mainColor () { | |
99 | + return this.color !== undefined ? this.transferColor(this.color) : ''; | |
100 | + }, | |
101 | + bgColorStyle () { | |
102 | + return oneOf(this.color, initColorList) ? {} : {background: this.mainColor}; | |
103 | + }, | |
104 | + defaultTypeColor () { | |
105 | + return (this.type !== 'dot' && this.type !== 'border') ? (this.color !== undefined ? this.transferColor(this.color) : '') : ''; | |
69 | 106 | } |
70 | 107 | }, |
71 | 108 | methods: { |
... | ... | @@ -85,7 +122,20 @@ |
85 | 122 | } else { |
86 | 123 | this.$emit('on-change', checked, this.name); |
87 | 124 | } |
125 | + }, | |
126 | + transferColor (name) { | |
127 | + if (oneOf(name, initColorList)) { | |
128 | + switch (name) { | |
129 | + case 'red': return '#ed3f14'; | |
130 | + case 'green': return '#19be6b'; | |
131 | + case 'yellow': return '#ff9900'; | |
132 | + case 'blue': return '#2d8cf0'; | |
133 | + case 'default': return ''; | |
134 | + } | |
135 | + } else { | |
136 | + return name; | |
137 | + } | |
88 | 138 | } |
89 | 139 | } |
90 | 140 | }; |
91 | 141 | -</script> |
142 | +</script> | |
92 | 143 | \ No newline at end of file | ... | ... |
src/styles/components/tag.less
... | ... | @@ -27,6 +27,24 @@ |
27 | 27 | } |
28 | 28 | } |
29 | 29 | |
30 | + &-color{ | |
31 | + &-red{ | |
32 | + color: @error-color !important; | |
33 | + } | |
34 | + &-green{ | |
35 | + color: @success-color !important; | |
36 | + } | |
37 | + &-blue{ | |
38 | + color: @link-color !important; | |
39 | + } | |
40 | + &-yellow{ | |
41 | + color: @warning-color !important; | |
42 | + } | |
43 | + &-white{ | |
44 | + color: rgb(255, 255, 255) !important; | |
45 | + } | |
46 | + } | |
47 | + | |
30 | 48 | &-dot{ |
31 | 49 | height: 32px; |
32 | 50 | line-height: 32px; |
... | ... | @@ -54,13 +72,13 @@ |
54 | 72 | &-border{ |
55 | 73 | height: 24px; |
56 | 74 | line-height: 24px; |
57 | - border: 1px solid @border-color-split !important; | |
58 | - color: @text-color !important; | |
75 | + border: 1px solid @border-color-split; | |
76 | + color: @border-color-split; | |
59 | 77 | background: #fff !important; |
60 | 78 | position: relative; |
61 | 79 | |
62 | 80 | .@{tag-close-prefix-cls} { |
63 | - color: #666 !important; | |
81 | + color: #666; | |
64 | 82 | margin-left: 12px !important; |
65 | 83 | } |
66 | 84 | |
... | ... | @@ -68,7 +86,7 @@ |
68 | 86 | content: ""; |
69 | 87 | display: none; |
70 | 88 | width: 1px; |
71 | - background: @border-color-split; | |
89 | + background: currentColor; | |
72 | 90 | position: absolute; |
73 | 91 | top: 0; |
74 | 92 | bottom: 0; |
... | ... | @@ -137,7 +155,7 @@ |
137 | 155 | &, |
138 | 156 | a, |
139 | 157 | a:hover { |
140 | - color: @text-color; | |
158 | + // color: @text-color; | |
141 | 159 | } |
142 | 160 | |
143 | 161 | &-text { |
... | ... | @@ -146,6 +164,7 @@ |
146 | 164 | margin: 0 -8px; |
147 | 165 | padding: 0 8px; |
148 | 166 | } |
167 | + color: @text-color; | |
149 | 168 | } |
150 | 169 | |
151 | 170 | .@{tag-close-prefix-cls} { | ... | ... |