Skip to content

Commit

Permalink
support tag color property
Browse files Browse the repository at this point in the history
  • Loading branch information
baiyaaaaa authored and Leopoldthecoder committed Dec 13, 2016
1 parent 998dcce commit 8917704
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
3 changes: 2 additions & 1 deletion examples/docs/en-US/tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Used for marking and selection.

### Basic usage

::: demo Use the `type` attribute to define Tag's type.
::: demo Use the `type` attribute to define Tag's type. In addition, the `color` attribute can be used to set the background color of the Tag.

```html
<el-tag>Tag One</el-tag>
Expand Down Expand Up @@ -93,6 +93,7 @@ Used for marking and selection.
| closable | whether Tab can be removed | boolean || false |
| close-transition | whether the removal animation is disabled | boolean || false |
| hit | whether Tag has a highlighted border | boolean || false |
| color | background color of the tag | string |||


### Events
Expand Down
3 changes: 2 additions & 1 deletion examples/docs/zh-CN/tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

### 基础用法

:::demo 由`type`属性来定义,该属性可选填
:::demo 由`type`属性来选择tag的类型,也可以通过`color`属性来自定义背景色

```html
<el-tag>标签一</el-tag>
Expand Down Expand Up @@ -93,6 +93,7 @@
| closable | 是否可关闭 | boolean || false |
| close-transition | 是否禁用关闭时的渐变动画 | boolean || false |
| hit | 是否有边框描边 | boolean || false |
| color | 背景色 | string |||


### Events
Expand Down
6 changes: 4 additions & 2 deletions packages/tag/src/tag.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<transition :name="closeTransition ? '' : 'el-zoom-in-center'">
<span
class="el-tag"
:class="[type ? 'el-tag--' + type : '', {'is-hit': hit}]">
:class="[type ? 'el-tag--' + type : '', {'is-hit': hit}]"
:style="{backgroundColor: color}">
<slot></slot>
<i class="el-tag__close el-icon-close"
v-if="closable"
Expand All @@ -18,7 +19,8 @@
closable: Boolean,
type: String,
hit: Boolean,
closeTransition: Boolean
closeTransition: Boolean,
color: String
},
methods: {
handleClose(event) {
Expand Down
1 change: 0 additions & 1 deletion packages/theme-default/src/common/var.css
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@
-------------------------- */
--tag-padding: 0 5px;
--tag-fill: var(--border-color-hover);
--tag-border: var(--border-color-hover);
--tag-color: var(--color-white);
--tag-close-color: #666;
--tag-font-size: 12px;
Expand Down
7 changes: 4 additions & 3 deletions packages/theme-default/src/tag.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
background-color: var(--tag-fill);
display: inline-block;
padding: var(--tag-padding);
height: 22px;
line-height: @height;
height: 24px;
line-height: calc(@height - 2);
font-size: var(--tag-font-size);
color: var(--tag-color);
border-radius: var(--tag-border-radius);
border: 1px solid var(--tag-border);
box-sizing: border-box;
border: 1px solid transparent;

& .el-icon-close {
border-radius: 50%;
Expand Down
9 changes: 9 additions & 0 deletions test/unit/specs/tag.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,13 @@ describe('Tag', () => {
}, true);
expect(vm.$el.classList.contains('md-fade-center')).to.be.false;
});

it('color', () => {
vm = createVue({
template: `
<el-tag color="rgb(0, 0, 0)"></el-tag>
`
}, true);
expect(vm.$el.style.backgroundColor).to.equal('rgb(0, 0, 0)');
});
});

0 comments on commit 8917704

Please sign in to comment.