Skip to content

Commit 338dfd0

Browse files
alinelariguetjhosefmarks
authored andcommitted
feat(tag): permite inversão de cores
Nova propriedade p-inverse, permite a inversão de cores no componente. Possibilita representação de status ativo e inativo. Fixes DTHFUI-1763
1 parent bd60d71 commit 338dfd0

File tree

8 files changed

+85
-7
lines changed

8 files changed

+85
-7
lines changed

projects/ui/src/lib/components/po-tag/po-tag-base.component.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ describe('PoTagBaseComponent:', () => {
4949
expectPropertiesValues(component, 'icon', validValues, validValues);
5050
});
5151

52+
it('inverse: should update property with valid and invalid values.', () => {
53+
const validValues = [true, 'true', 1, ''];
54+
const invalidValues = [false, 'false', 0];
55+
56+
expectPropertiesValues(component, 'inverse', validValues, true);
57+
expectPropertiesValues(component, 'inverse', invalidValues, false);
58+
});
59+
5260
it('orientation: should update property with valid values', () => {
5361
const validValues = (<any>Object).values(PoTagOrientation);
5462

projects/ui/src/lib/components/po-tag/po-tag-base.component.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class PoTagBaseComponent {
2525

2626
private _color?: string;
2727
private _icon?: boolean | string;
28+
private _inverse?: boolean;
2829
private _orientation?: PoTagOrientation = poTagOrientationDefault;
2930
private _type?: PoTagType;
3031

@@ -92,6 +93,26 @@ export class PoTagBaseComponent {
9293
return this._icon;
9394
}
9495

96+
/**
97+
* @optional
98+
*
99+
* @description
100+
*
101+
* Ativa a inversão de cores configuradas no componente, possibilitando uma visualização de status ativo e inativo.
102+
*
103+
* > A cor do texto, do ícone e da borda ficam com a cor utilizada na propriedade `p-color` ou a cor correspondente ao `p-type`,
104+
* e a cor do fundo fica branca.
105+
*
106+
* @default `false`
107+
*/
108+
@Input('p-inverse') set inverse(value: boolean) {
109+
this._inverse = convertToBoolean(value);
110+
}
111+
112+
get inverse(): boolean {
113+
return this._inverse;
114+
}
115+
95116
/**
96117
* @optional
97118
*

projects/ui/src/lib/components/po-tag/po-tag.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<div class="po-tag-sub-container">
77
<div class="po-tag"
88
[class.po-clickable]="isClickable"
9+
[class.po-tag-inverse]="inverse"
910
[ngClass]="tagColor"
1011
tabindex="0"
1112
(click)="onClick()"

projects/ui/src/lib/components/po-tag/po-tag.component.spec.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,46 @@ describe('PoTagComponent:', () => {
7777
expect(component.iconTypeString).toBe(false);
7878
});
7979

80-
it('tagColor: should return tag type.', () => {
80+
it('tagColor: should return tag type without `inverse`.', () => {
8181
component.type = PoTagType.Danger;
82+
component.inverse = false;
8283
expect(component.tagColor).toBe('po-tag-danger');
8384
});
8485

85-
it('tagColor: should return tag color.', () => {
86+
it('tagColor: should return tag type with `inverse`.', () => {
87+
component.type = PoTagType.Danger;
88+
component.inverse = true;
89+
expect(component.tagColor).toBe('po-tag-danger-inverse');
90+
});
91+
92+
it('tagColor: should return tag color without `text`.', () => {
8693
component.color = 'color-07';
8794
component.type = undefined;
95+
component.inverse = false;
8896
expect(component.tagColor).toBe('po-color-07');
8997
});
9098

91-
it('tagColor: should return tag type default.', () => {
99+
it('tagColor: should return tag color with `text`.', () => {
100+
component.color = 'color-07';
101+
component.type = undefined;
102+
component.inverse = true;
103+
expect(component.tagColor).toBe('po-text-color-07');
104+
});
105+
106+
it('tagColor: should return tag type default without `inverse`.', () => {
92107
component.color = undefined;
93108
component.type = undefined;
109+
component.inverse = false;
94110
expect(component.tagColor).toBe('po-tag-info');
95111
});
96112

113+
it('tagColor: should return tag type default with `inverse`.', () => {
114+
component.color = undefined;
115+
component.type = undefined;
116+
component.inverse = true;
117+
expect(component.tagColor).toBe('po-tag-info-inverse');
118+
});
119+
97120
it('tagOrientation: should return true if orientation is horizontal.', () => {
98121
component.orientation = PoTagOrientation.Horizontal;
99122
expect(component.tagOrientation).toBe(true);
@@ -293,6 +316,20 @@ describe('PoTagComponent:', () => {
293316
expect(nativeElement.querySelector('.po-clickable')).toBeFalsy();
294317
});
295318

319+
it('should add `po-tag-inverse` if `inverse` is true.', () => {
320+
component.inverse = true;
321+
322+
fixture.detectChanges();
323+
expect(nativeElement.querySelector('.po-tag-inverse')).toBeTruthy();
324+
});
325+
326+
it('shouldn`t add `po-tag-inverse` if `inverse` is false.', () => {
327+
component.inverse = false;
328+
329+
fixture.detectChanges();
330+
expect(nativeElement.querySelector('.po-tag-inverse')).toBeFalsy();
331+
});
332+
296333
});
297334

298335
});

projects/ui/src/lib/components/po-tag/po-tag.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ export class PoTagComponent extends PoTagBaseComponent implements OnInit {
5959

6060
get tagColor() {
6161
if (this.type) {
62-
return 'po-tag-' + this.type;
62+
return this.inverse ? `po-tag-${this.type}-inverse` : `po-tag-${this.type}`;
6363
}
6464

6565
if (this.color && !this.type) {
66-
return 'po-' + this.color;
66+
return this.inverse ? `po-text-${this.color}` : `po-${this.color}`;
6767
}
6868

6969
if (!this.type && !this.color) {
70-
return poTagTypeDefault;
70+
return this.inverse ? `${poTagTypeDefault}-inverse` : poTagTypeDefault;
7171
}
7272
}
7373

projects/ui/src/lib/components/po-tag/samples/sample-po-tag-bank-account/sample-po-tag-bank-account.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<div class="po-row">
3131
<po-tag *ngFor="let investiment of investiments"
3232
class="po-md-6 po-lg-3"
33+
p-inverse
3334
[p-label]="investiment.label"
3435
[p-type]="investiment.type"
3536
[p-value]="investiment.value">

projects/ui/src/lib/components/po-tag/samples/sample-po-tag-labs/sample-po-tag-labs.component.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<po-tag
22
[p-color]="color"
33
[p-icon]="icon"
4+
[p-inverse]="inverse"
45
[p-label]="label"
56
[p-orientation]="orientation"
67
[p-type]="type"
@@ -83,13 +84,20 @@
8384
</po-radio-group>
8485

8586
<po-radio-group
86-
class="po-md-8"
87+
class="po-md-6"
8788
name="type"
8889
[(ngModel)]="type"
8990
p-columns="3"
9091
p-label="Type"
9192
[p-options]="typeOptions">
9293
</po-radio-group>
94+
95+
<po-switch
96+
class="po-md-2"
97+
name="inverse"
98+
[(ngModel)]="inverse"
99+
p-label="Inverse">
100+
</po-switch>
93101
</div>
94102

95103
<div class="po-row">

projects/ui/src/lib/components/po-tag/samples/sample-po-tag-labs/sample-po-tag-labs.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class SamplePoTagLabsComponent implements OnInit {
2121
color: string;
2222
event: string;
2323
icon: boolean | string;
24+
inverse: boolean;
2425
label: string;
2526
orientation: PoTagOrientation;
2627
type: PoTagType;
@@ -79,6 +80,7 @@ export class SamplePoTagLabsComponent implements OnInit {
7980
this.value = 'Portinari Tag';
8081
this.type = undefined;
8182
this.event = '';
83+
this.inverse = false;
8284
}
8385

8486
}

0 commit comments

Comments
 (0)