Skip to content

Commit

Permalink
feat(module:tag): support status colors (NG-ZORRO#4628)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsuanxyz authored and Ricbet committed Apr 9, 2020
1 parent 97c5b49 commit 0a1d0a6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
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

0 comments on commit 0a1d0a6

Please sign in to comment.