Skip to content

Commit 5bd2ce6

Browse files
feat(modal): adiciona suporte a ícone nas ações do modal
O componente po-modal não permitia exibir ícones nos botões de ação. Adiciona a propriedade `icon` na interface `PoModalAction` e vincula `[p-icon]` nos botões primário e secundário do template do modal. Fixes DTHFUI-11656, DTHFUI-12113
1 parent 3df28f7 commit 5bd2ce6

File tree

5 files changed

+82
-7
lines changed

5 files changed

+82
-7
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,12 @@ export class PoButtonBaseComponent {
9595
* @description
9696
* Ícone exibido ao lado esquerdo do label do botão.
9797
*
98-
* É possível usar qualquer um dos ícones da [Biblioteca de ícones](https://po-ui.io/icons). conforme exemplo abaixo:
98+
* É possível usar qualquer um dos ícones da [Biblioteca de ícones](https://po-ui.io/icons), conforme exemplo:
9999
* ```
100100
* <po-button p-icon="an an-user" p-label="PO button"></po-button>
101101
* ```
102-
* Também é possível utilizar outras fontes de ícones, por exemplo a biblioteca *Font Awesome*, da seguinte forma:
102+
* Também é possível utilizar outras fontes de ícones, por exemplo a biblioteca *Font Awesome*, desde que a biblioteca
103+
* esteja carregada no projeto:
103104
* ```
104105
* <po-button p-icon="fa fa-podcast" p-label="PO button"></po-button>
105106
* ```

projects/ui/src/lib/components/po-modal/po-modal-action.interface.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { TemplateRef } from '@angular/core';
2+
13
/**
24
* @usedBy PoModalComponent
35
*
@@ -19,6 +21,50 @@ export interface PoModalAction {
1921
/** Desabilita o botão impossibilitando que sua ação seja executada. */
2022
disabled?: boolean;
2123

24+
/**
25+
* Ícone exibido ao lado esquerdo do label do botão.
26+
*
27+
* É possível usar qualquer um dos ícones da [Biblioteca de ícones](https://po-ui.io/icons), conforme exemplo:
28+
* ```
29+
* const modalAction: PoModalAction = {
30+
* action: () => {},
31+
* label: 'Botão com ícone PO',
32+
* icon: 'an an-user'
33+
* };
34+
* ```
35+
* Também é possível utilizar outras fontes de ícones, por exemplo a biblioteca *Font Awesome*, desde que a biblioteca
36+
* esteja carregada no projeto:
37+
* ```
38+
* const modalAction: PoModalAction = {
39+
* action: () => {},
40+
* label: 'Botão com ícone Font Awesome',
41+
* icon: 'fa fa-user'
42+
* };
43+
* ```
44+
* Outra opção seria a customização do ícone através do `TemplateRef`, conforme exemplo abaixo:
45+
* ```
46+
* // Template HTML
47+
* <ng-template #customIcon>
48+
* <span class="fa fa-user"></span>
49+
* </ng-template>
50+
*
51+
* // Componente TypeScript
52+
* @ViewChild('customIcon', { static: true }) customIcon: TemplateRef<void>;
53+
*
54+
* const modalAction: PoModalAction = {
55+
* action: () => {},
56+
* label: 'Botão com ícone customizado',
57+
* };
58+
*
59+
* // Atribuição do TemplateRef à propriedade icon após a inicialização da view
60+
* ngAfterViewInit() {
61+
* this.modalAction.icon = this.customIcon;
62+
* }
63+
* ```
64+
* > Para o ícone enquadrar corretamente, deve-se utilizar `font-size: inherit` caso o ícone utilizado não aplique-o.
65+
*/
66+
icon?: string | TemplateRef<void>;
67+
2268
/** Rótulo do botão. */
2369
label: string;
2470

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<po-button
3737
[p-danger]="getSecondaryActionButtonDanger()"
3838
[p-disabled]="secondaryAction.disabled"
39+
[p-icon]="secondaryAction.icon"
3940
[p-label]="secondaryAction.label"
4041
[p-loading]="secondaryAction.loading"
4142
p-kind="secondary"
@@ -48,6 +49,7 @@
4849
class="po-button-modal-first-action"
4950
[p-danger]="primaryAction.danger"
5051
[p-disabled]="primaryAction.disabled"
52+
[p-icon]="primaryAction.icon"
5153
[p-label]="primaryAction.label"
5254
[p-loading]="primaryAction.loading"
5355
p-kind="primary"

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
[p-options]="iconOptions"
2828
></po-select>
2929

30-
<po-input class="po-md-6" name="Content" [(ngModel)]="content" p-clean p-label="Content" p-maxlength="200">
30+
<po-input class="po-md-12 po-lg-6" name="Content" [(ngModel)]="content" p-clean p-label="Content" p-maxlength="200">
3131
</po-input>
3232

3333
<po-input
@@ -40,8 +40,18 @@
4040
>
4141
</po-input>
4242

43+
<po-input
44+
class="po-md-6 po-lg-3"
45+
name="primaryActionIcon"
46+
[(ngModel)]="primaryActionIcon"
47+
p-clean
48+
p-label="Primary action icon"
49+
p-maxlength="30"
50+
>
51+
</po-input>
52+
4353
<po-checkbox-group
44-
class="po-md-12 po-lg-9"
54+
class="po-md-12 po-lg-6"
4555
name="primaryActionProperties"
4656
[(ngModel)]="primaryActionProperties"
4757
p-columns="3"
@@ -60,8 +70,18 @@
6070
>
6171
</po-input>
6272

73+
<po-input
74+
class="po-md-6 po-lg-3"
75+
name="secondaryActionIcon"
76+
[(ngModel)]="secondaryActionIcon"
77+
p-clean
78+
p-label="Secondary action icon"
79+
p-maxlength="100"
80+
>
81+
</po-input>
82+
6383
<po-checkbox-group
64-
class="po-md-12 po-lg-9"
84+
class="po-md-12 po-lg-6"
6585
name="secondaryActionProperties"
6686
[(ngModel)]="secondaryActionProperties"
6787
p-columns="3"

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export class SamplePoModalLabsComponent implements OnInit {
3030
};
3131

3232
primaryActionLabel: string;
33+
primaryActionIcon: string;
3334
primaryActionProperties: Array<string>;
3435
primaryActionOptions: Array<PoCheckboxGroupOption> = [
3536
{ value: 'danger', label: 'Danger' },
@@ -56,11 +57,12 @@ export class SamplePoModalLabsComponent implements OnInit {
5657
};
5758

5859
secondaryActionLabel: string;
60+
secondaryActionIcon: string;
5961
secondaryActionProperties: Array<string>;
6062
secondaryActionOptions: Array<PoCheckboxGroupOption> = [
63+
{ value: 'danger', label: 'Danger' },
6164
{ value: 'disabled', label: 'Disabled' },
62-
{ value: 'loading', label: 'Loading' },
63-
{ value: 'danger', label: 'Danger' }
65+
{ value: 'loading', label: 'Loading' }
6466
];
6567

6668
propertiesOptions: Array<PoCheckboxGroupOption> = [
@@ -81,11 +83,13 @@ export class SamplePoModalLabsComponent implements OnInit {
8183
openModal() {
8284
this.primaryAction.disabled = this.primaryActionProperties.includes('disabled');
8385
this.primaryAction.label = this.primaryActionLabel;
86+
this.primaryAction.icon = this.primaryActionIcon;
8487
this.primaryAction.loading = this.primaryActionProperties.includes('loading');
8588
this.primaryAction.danger = this.primaryActionProperties.includes('danger');
8689

8790
this.secondaryAction.disabled = this.secondaryActionProperties.includes('disabled');
8891
this.secondaryAction.label = this.secondaryActionLabel;
92+
this.secondaryAction.icon = this.secondaryActionIcon;
8993
this.secondaryAction.loading = this.secondaryActionProperties.includes('loading');
9094
this.secondaryAction.danger = this.secondaryActionProperties.includes('danger');
9195

@@ -102,8 +106,10 @@ export class SamplePoModalLabsComponent implements OnInit {
102106
this.title = 'PO Modal';
103107
this.properties = [];
104108
this.primaryActionLabel = undefined;
109+
this.primaryActionIcon = undefined;
105110
this.primaryActionProperties = [];
106111
this.secondaryActionLabel = undefined;
112+
this.secondaryActionIcon = undefined;
107113
this.secondaryActionProperties = [];
108114
this.componentsSize = 'medium';
109115
this.icon = undefined;

0 commit comments

Comments
 (0)