Skip to content

Commit 13587a4

Browse files
mateusjmafjhosefmarks
authored andcommitted
feat(tag): permitir o uso da paleta de cores e ícones
Agora o componente permite a utilização da paleta de cores além de ícones e navegação através do teclado. Fixes DTHFUI-1762
1 parent 1cacc4d commit 13587a4

File tree

8 files changed

+333
-90
lines changed

8 files changed

+333
-90
lines changed

projects/ui/src/lib/components/po-tag/enums/po-tag-icon.enum.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
*/
88
export enum PoTagIcon {
99

10-
/** Ícone fechar */
11-
Danger = 'close',
10+
/** Ícone fechar. */
11+
Danger = 'po-icon-close',
1212

13-
/** Ícone de informação */
14-
Info = 'info',
13+
/** Ícone de informação. */
14+
Info = 'po-icon-info',
1515

16-
/** Ícone que representa confirmação */
17-
Success = 'ok',
16+
/** Ícone que representa confirmação. */
17+
Success = 'po-icon-ok',
1818

19-
/** Ícone com ponto de exclamação */
20-
Warning = 'warning'
19+
/** Ícone com ponto de exclamação. */
20+
Warning = 'po-icon-warning'
2121
}

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

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,54 @@
11
import { expectPropertiesValues } from '../../util-test/util-expect.spec';
22

3+
import { PoColorPaletteEnum } from '../../enums/po-color-palette.enum';
4+
35
import { PoTagBaseComponent } from './po-tag-base.component';
4-
import { PoTagIcon } from './enums/po-tag-icon.enum';
56
import { PoTagOrientation } from './enums/po-tag-orientation.enum';
67
import { PoTagType } from './enums/po-tag-type.enum';
78

89
describe('PoTagBaseComponent:', () => {
910
const component = new PoTagBaseComponent();
11+
const poTagColors = (<any>Object).values(PoColorPaletteEnum);
1012

1113
it('should be created', () => {
1214
expect(component instanceof PoTagBaseComponent).toBeTruthy();
1315
});
1416

1517
describe('Properties:', () => {
1618

17-
it('icon: should update with true value.', () => {
19+
it('color: should update to true value.', () => {
20+
const colorsValidTrueValues = poTagColors;
21+
22+
expectPropertiesValues(component, 'color', colorsValidTrueValues, colorsValidTrueValues);
23+
});
24+
25+
it('color: shouldn´t update to false value.', () => {
26+
const colorsInalidTrueValues = [undefined, null, 2, 'string', 0, NaN];
27+
28+
expectPropertiesValues(component, 'color', colorsInalidTrueValues, undefined);
29+
});
30+
31+
it('icon: should update to true value with `type`.', () => {
32+
component.type = PoTagType.Info;
1833
const booleanValidTrueValues = [true, 'true', 1, ''];
1934

2035
expectPropertiesValues(component, 'icon', booleanValidTrueValues, true);
2136
});
2237

23-
it('icon: should update with false value.', () => {
38+
it('icon: should update to false if `type` is true.', () => {
39+
component.type = PoTagType.Info;
2440
const booleanInvalidValues = [undefined, null, 2, 'string', 0, NaN];
2541

2642
expectPropertiesValues(component, 'icon', booleanInvalidValues, false);
2743
});
2844

45+
it('icon: should update to true if `type` is undefined.', () => {
46+
component.type = undefined;
47+
const validValues = ['po-icon-ok', 'po-icon-company', 'po-icon-portinari'];
48+
49+
expectPropertiesValues(component, 'icon', validValues, validValues);
50+
});
51+
2952
it('orientation: should update property with valid values', () => {
3053
const validValues = (<any>Object).values(PoTagOrientation);
3154

@@ -47,21 +70,7 @@ describe('PoTagBaseComponent:', () => {
4770
it('type: should update property with `info` if values are invalid', () => {
4871
const invalidValues = [undefined, null, '', true, false, 0, -1, 12, 15, 'aa', [], {}];
4972

50-
expectPropertiesValues(component, 'type', invalidValues, 'info');
51-
});
52-
53-
it('iconFromType: should update property with valid values', () => {
54-
component.type = PoTagType.Danger;
55-
expect(component.iconFromType).toBe(PoTagIcon.Danger);
56-
57-
component.type = PoTagType.Danger;
58-
expect(component.iconFromType).toBe(PoTagIcon.Danger);
59-
60-
component.type = PoTagType.Danger;
61-
expect(component.iconFromType).toBe(PoTagIcon.Danger);
62-
63-
component.type = PoTagType.Danger;
64-
expect(component.iconFromType).toBe(PoTagIcon.Danger);
73+
expectPropertiesValues(component, 'type', invalidValues, undefined);
6574
});
6675

6776
});
Lines changed: 72 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
import { EventEmitter, Input, Output } from '@angular/core';
22

33
import { convertToBoolean } from '../../utils/util';
4+
import { PoColorPaletteEnum } from '../../enums/po-color-palette.enum';
45

5-
import { PoTagIcon } from './enums/po-tag-icon.enum';
66
import { PoTagItem } from './interfaces/po-tag-item.interface';
77
import { PoTagOrientation } from './enums/po-tag-orientation.enum';
88
import { PoTagType } from './enums/po-tag-type.enum';
99

10+
const poTagColors = (<any>Object).values(PoColorPaletteEnum);
1011
const poTagOrientationDefault = PoTagOrientation.Vertical;
11-
const poTagTypeDefault = PoTagType.Info;
1212

1313
/**
1414
* @description
1515
*
16-
* Este componente apresenta um valor em um marcador colorido que pode conter ícone e *label*, as cores são definidas conforme o tipo
17-
* escolhido.
18-
* Seu uso é indicado para informações que necessitam de destaque em forma de marcação.
16+
* Este componente permite exibir um valor em forma de um marcador colorido, sendo possível definir uma legenda e realizar customizações
17+
* na cor, iconografia e tipo.
18+
*
19+
* Além disso, é possível definir uma ação que será executada tanto ao *click* quanto através das teclas *enter/space* enquanto navega
20+
* utilizando a tecla *tab*.
21+
*
22+
* Seu uso é recomendado para informações que necessitem de destaque em forma de marcação.
1923
*/
2024
export class PoTagBaseComponent {
2125

22-
private _icon?: boolean;
26+
private _color?: string;
27+
private _icon?: boolean | string;
2328
private _orientation?: PoTagOrientation = poTagOrientationDefault;
24-
private _type?: PoTagType = poTagTypeDefault;
29+
private _type?: PoTagType;
2530

2631
public readonly poTagOrientation = PoTagOrientation;
2732

@@ -30,27 +35,60 @@ export class PoTagBaseComponent {
3035
*
3136
* @description
3237
*
33-
* Texto antes da tag.
38+
* Define uma cor para a *tag*.
39+
*
40+
* Valores válidos:
41+
* - <span class="dot po-color-01"></span> `color-01`
42+
* - <span class="dot po-color-02"></span> `color-02`
43+
* - <span class="dot po-color-03"></span> `color-03`
44+
* - <span class="dot po-color-04"></span> `color-04`
45+
* - <span class="dot po-color-05"></span> `color-05`
46+
* - <span class="dot po-color-06"></span> `color-06`
47+
* - <span class="dot po-color-07"></span> `color-07`
48+
* - <span class="dot po-color-08"></span> `color-08`
49+
* - <span class="dot po-color-09"></span> `color-09`
50+
* - <span class="dot po-color-10"></span> `color-10`
51+
* - <span class="dot po-color-11"></span> `color-11`
52+
* - <span class="dot po-color-12"></span> `color-12`
53+
*
54+
* > **Atenção:** A propriedade `p-type` sobrepõe esta definição.
3455
*/
35-
@Input('p-label') label?: string;
56+
@Input('p-color') set color(value: string) {
57+
this._color = poTagColors.includes(value) ? value : undefined;
58+
}
59+
60+
get color(): string {
61+
return this._color;
62+
}
3663

3764
/**
3865
* @optional
3966
*
4067
* @description
4168
*
42-
* Apresenta um ícone na tag conforme o tipo:
43-
* - `danger`: <span class="po-icon po-icon-close"></span>
44-
* - `info`: <span class="po-icon po-icon-info"></span>
45-
* - `success`: <span class="po-icon po-icon-ok"></span>
46-
* - `warning`: <span class="po-icon po-icon-warning"></span>
69+
* Define ou ativa um ícone que será exibido ao lado do valor da *tag*.
70+
*
71+
* > Veja os valores válidos na [biblioteca de ícones](guides/icons).
72+
*
73+
* Quando `p-type` estiver definida, basta informar um valor igual a `true` para que o ícone seja exibido conforme descrições abaixo:
74+
* - <span class="po-icon po-icon-ok"></span> - `success`
75+
* - <span class="po-icon po-icon-warning"></span> - `warning`
76+
* - <span class="po-icon po-icon-close"></span> - `danger`
77+
* - <span class="po-icon po-icon-info"></span> - `info`
4778
*
4879
* @default `false`
4980
*/
50-
@Input('p-icon') set icon(value: boolean) {
51-
this._icon = <any>value === '' ? true : convertToBoolean(value);
81+
@Input('p-icon') set icon(value: boolean | string) {
82+
if (this.type) {
83+
this._icon = convertToBoolean(value);
84+
85+
} else {
86+
this._icon = value;
87+
88+
}
5289
}
53-
get icon(): boolean {
90+
91+
get icon(): boolean | string {
5492
return this._icon;
5593
}
5694

@@ -59,13 +97,23 @@ export class PoTagBaseComponent {
5997
*
6098
* @description
6199
*
62-
* Define o layout de exibição.
100+
* Define uma legenda que será exibida acima ou ao lado da *tag*, de acordo com a `p-orientation`.
101+
*/
102+
@Input('p-label') label?: string;
103+
104+
/**
105+
* @optional
106+
*
107+
* @description
108+
*
109+
* Define o *layout* de exibição.
63110
*
64111
* @default `vertical`
65112
*/
66113
@Input('p-orientation') set orientation(value: PoTagOrientation) {
67114
this._orientation = (<any>Object).values(PoTagOrientation).includes(value) ? value : poTagOrientationDefault;
68115
}
116+
69117
get orientation(): PoTagOrientation {
70118
return this._orientation;
71119
}
@@ -75,19 +123,22 @@ export class PoTagBaseComponent {
75123
*
76124
* @description
77125
*
78-
* Define o tipo e determina a cor do `po-tag`.
126+
* Define o tipo da *tag*.
79127
*
80128
* Valores válidos:
81129
* - `success`: cor verde utilizada para simbolizar sucesso ou êxito.
82130
* - `warning`: cor amarela que representa aviso ou advertência.
83131
* - `danger`: cor vermelha para erro ou aviso crítico.
84132
* - `info`: cor cinza escuro que caracteriza conteúdo informativo.
85133
*
134+
* > Quando esta propriedade for definida, irá sobrepor a definição de `p-color` e `p-icon` somente será exibido caso seja `true`.
135+
*
86136
* @default `info`
87137
*/
88138
@Input('p-type') set type(value: PoTagType) {
89-
this._type = (<any>Object).values(PoTagType).includes(value) ? value : poTagTypeDefault;
139+
this._type = (<any>Object).values(PoTagType).includes(value) ? value : undefined;
90140
}
141+
91142
get type(): PoTagType {
92143
return this._type;
93144
}
@@ -100,21 +151,8 @@ export class PoTagBaseComponent {
100151
*
101152
* @description
102153
*
103-
* Ação que será executada quando o usuário clicar sobre o `po-tag`
104-
* e que receberá como parâmetro um objeto contendo o valor e tipo de tag.
154+
* Ação que será executada ao clicar sobre o `po-tag` e que receberá como parâmetro um objeto contendo o seu valor e tipo.
105155
*/
106156
@Output('p-click') click?: EventEmitter<any> = new EventEmitter<PoTagItem>();
107157

108-
get iconFromType() {
109-
switch (this.type) {
110-
case PoTagType.Danger: return PoTagIcon.Danger;
111-
112-
case PoTagType.Info: return PoTagIcon.Info;
113-
114-
case PoTagType.Success: return PoTagIcon.Success;
115-
116-
case PoTagType.Warning: return PoTagIcon.Warning;
117-
}
118-
}
119-
120158
}
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
<div class="po-tag-container" [class.po-tag-container-horizontal]="orientation === poTagOrientation.Horizontal">
1+
<div class="po-tag-container" [class.po-tag-container-horizontal]="tagOrientation">
22
<div *ngIf="label" class="po-tag-title po-text-nowrap">
3-
<span class="po-tag-label">{{ orientation === poTagOrientation.Horizontal ? label + ':' : label }}</span>
3+
<span class="po-tag-label">{{ tagOrientation ? label + ':' : label }}</span>
44
</div>
5-
<div
6-
class="po-tag po-tag-{{ type }}"
7-
[ngClass]="{'po-clickable': isClickable}"
8-
(click)="onClick()">
9-
<span *ngIf="icon" class="po-icon po-icon-{{ iconFromType }}"></span>
10-
<span class="po-tag-value">{{value}}</span>
5+
6+
<div class="po-tag-sub-container">
7+
<div class="po-tag"
8+
[class.po-clickable]="isClickable"
9+
[ngClass]="tagColor"
10+
tabindex="0"
11+
(click)="onClick()"
12+
(keydown)="onKeyPressed($event, 'enter')"
13+
(keyup)="onKeyPressed($event, 'space')">
14+
15+
<span *ngIf="icon" class="po-icon" [ngClass]="!type && iconTypeString ? icon : iconFromType"></span>
16+
<span class="po-tag-value">{{value}}</span>
17+
</div>
1118
</div>
1219
</div>

0 commit comments

Comments
 (0)