Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(module:tag): support status colors #4628

Merged
merged 1 commit into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions components/tag/demo/status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
order: 7
title:
zh-CN: 预设状态的标签
en-US: Status Tag
---

## zh-CN

预设五种状态颜色,可以通过设置 `nzColor` 为 `success`、 `processing`、`error`、`default`、`warning` 来代表不同的状态。

## en-US

We preset five different colors, you can set `nzColor` property such as `success`,`processing`,`error`,`default` and `warning` to indicate specific status.
13 changes: 13 additions & 0 deletions components/tag/demo/status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-tag-status',
template: `
<nz-tag nzColor="success">success</nz-tag>
<nz-tag nzColor="processing">processing</nz-tag>
<nz-tag nzColor="error">error</nz-tag>
<nz-tag nzColor="default">default</nz-tag>
<nz-tag nzColor="warning">warning</nz-tag>
`
})
export class NzDemoTagStatusComponent {}
6 changes: 5 additions & 1 deletion components/tag/nz-tag.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ export class NzTagComponent implements OnInit, OnChanges {
if (!color) {
return false;
}
return /^(pink|red|yellow|orange|cyan|green|blue|purple|geekblue|magenta|volcano|gold|lime)(-inverse)?$/.test(color);

return (
/^(pink|red|yellow|orange|cyan|green|blue|purple|geekblue|magenta|volcano|gold|lime)(-inverse)?$/.test(color) ||
/^(success|processing|error|default|warning)$/.test(color)
);
}

private updateClassMap(): void {
Expand Down
13 changes: 13 additions & 0 deletions components/tag/nz-tag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ describe('tag', () => {
expect(tag.nativeElement.classList).toContain('ant-tag-green');
expect(tag.nativeElement.style.backgroundColor).toBe('');
});

it('should status color work', () => {
fixture.detectChanges();
testComponent.color = 'success';
fixture.detectChanges();
expect(tag.nativeElement.classList).toContain('ant-tag-success');
testComponent.color = 'processing';
fixture.detectChanges();
expect(tag.nativeElement.classList).toContain('ant-tag-processing');
testComponent.color = 'invalid';
fixture.detectChanges();
expect(tag.nativeElement.classList).not.toContain('ant-tag-invalid');
});
it('issues #1176', () => {
testComponent.color = 'green';
fixture.detectChanges();
Expand Down