11import { EventEmitter , Input , Output } from '@angular/core' ;
22
33import { convertToBoolean } from '../../utils/util' ;
4+ import { PoColorPaletteEnum } from '../../enums/po-color-palette.enum' ;
45
5- import { PoTagIcon } from './enums/po-tag-icon.enum' ;
66import { PoTagItem } from './interfaces/po-tag-item.interface' ;
77import { PoTagOrientation } from './enums/po-tag-orientation.enum' ;
88import { PoTagType } from './enums/po-tag-type.enum' ;
99
10+ const poTagColors = ( < any > Object ) . values ( PoColorPaletteEnum ) ;
1011const 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 */
2024export 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}
0 commit comments