From d55262f61112b2860d577c5cc4d1fe965f83a591 Mon Sep 17 00:00:00 2001 From: jcorrea97 Date: Tue, 14 Nov 2023 16:31:00 -0300 Subject: [PATCH] =?UTF-8?q?feat(progress):=20implementa=20defini=C3=A7?= =?UTF-8?q?=C3=B5es=20do=20AnimaliaDS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implementa definições de estilo e acessibilidade definidos pelo AnimaliaDS Fixes DTHFUI-7808 --- .../enums/po-progress-size.enum.ts | 12 +++++ .../src/lib/components/po-progress/index.ts | 1 + .../po-progress-bar.component.html | 18 +++++-- .../po-progress-bar.component.spec.ts | 12 ++--- .../po-progress-base.component.spec.ts | 12 +++++ .../po-progress/po-progress-base.component.ts | 38 ++++++++++++- .../po-progress/po-progress.component.html | 54 +++++++++++-------- .../po-progress/po-progress.component.spec.ts | 12 ++--- .../po-progress/po-progress.component.ts | 4 +- .../po-progress/po-progress.module.ts | 5 +- .../sample-po-progress-labs.component.html | 5 ++ .../sample-po-progress-labs.component.ts | 14 ++++- ...ple-po-progress-publication.component.html | 2 +- 13 files changed, 144 insertions(+), 45 deletions(-) create mode 100644 projects/ui/src/lib/components/po-progress/enums/po-progress-size.enum.ts diff --git a/projects/ui/src/lib/components/po-progress/enums/po-progress-size.enum.ts b/projects/ui/src/lib/components/po-progress/enums/po-progress-size.enum.ts new file mode 100644 index 0000000000..9fe71d11f5 --- /dev/null +++ b/projects/ui/src/lib/components/po-progress/enums/po-progress-size.enum.ts @@ -0,0 +1,12 @@ +/** + * @usedBy PoProgressComponent + * + * @description + * + * *Enum* `PoProgressSize` para o tamanho da altura da barra de progresso. + */ +export enum PoProgressSize { + medium = 'medium', + + large = 'large' +} diff --git a/projects/ui/src/lib/components/po-progress/index.ts b/projects/ui/src/lib/components/po-progress/index.ts index 49e4e51bf8..2b18f79afd 100644 --- a/projects/ui/src/lib/components/po-progress/index.ts +++ b/projects/ui/src/lib/components/po-progress/index.ts @@ -1,4 +1,5 @@ export * from './enums/po-progress-status.enum'; +export * from './enums/po-progress-size.enum'; export * from './po-progress.component'; export * from './po-progress.module'; diff --git a/projects/ui/src/lib/components/po-progress/po-progress-bar/po-progress-bar.component.html b/projects/ui/src/lib/components/po-progress/po-progress-bar/po-progress-bar.component.html index a61b053378..62d612b3b7 100644 --- a/projects/ui/src/lib/components/po-progress/po-progress-bar/po-progress-bar.component.html +++ b/projects/ui/src/lib/components/po-progress/po-progress-bar/po-progress-bar.component.html @@ -1,4 +1,16 @@ -
-
-
+
+
+
+
+ +
+
diff --git a/projects/ui/src/lib/components/po-progress/po-progress-bar/po-progress-bar.component.spec.ts b/projects/ui/src/lib/components/po-progress/po-progress-bar/po-progress-bar.component.spec.ts index 5d2570cfac..3bdb443dec 100644 --- a/projects/ui/src/lib/components/po-progress/po-progress-bar/po-progress-bar.component.spec.ts +++ b/projects/ui/src/lib/components/po-progress/po-progress-bar/po-progress-bar.component.spec.ts @@ -51,24 +51,24 @@ describe('PoProgressBarComponent:', () => { }); describe('Templates:', () => { - it('should contain the value of 0.25 in style transform scale if value is 25', () => { + it('should contain the value of -75% in style left if value is 25', () => { component.value = 25; fixture.detectChanges(); - const progressBar = nativeElement.querySelector('.po-progress-bar-primary'); + const progressBar = nativeElement.querySelector('.po-progress-bar-secondary'); - expect(progressBar.style.transform).toBe('scaleX(0.25)'); + expect(progressBar.style.left).toBe('-75%'); }); - it('should contain the value of 0 in style transform scale if value is 0', () => { + it('should contain the value of -100% in style left if value is 0', () => { component.value = 0; fixture.detectChanges(); - const progressBar = nativeElement.querySelector('.po-progress-bar-primary'); + const progressBar = nativeElement.querySelector('.po-progress-bar-secondary'); - expect(progressBar.style.transform).toBe('scaleX(0)'); + expect(progressBar.style.left).toBe('-100%'); }); }); }); diff --git a/projects/ui/src/lib/components/po-progress/po-progress-base.component.spec.ts b/projects/ui/src/lib/components/po-progress/po-progress-base.component.spec.ts index c8f5a0ac6a..5ee0a92721 100644 --- a/projects/ui/src/lib/components/po-progress/po-progress-base.component.spec.ts +++ b/projects/ui/src/lib/components/po-progress/po-progress-base.component.spec.ts @@ -34,6 +34,18 @@ describe('PoProgressBaseComponent:', () => { expectPropertiesValues(component, 'value', validValues, 0); }); + + it('should update property `p-size` with valid values', () => { + const validValues = ['large', 'medium']; + + expectPropertiesValues(component, 'size', validValues, validValues); + }); + + it('should update property `p-size` with large if has not valid values', () => { + const invalidValues = ['extrasmall', 'huge', 'extralarge']; + + expectPropertiesValues(component, 'size', invalidValues, 'large'); + }); }); describe('Methods:', () => { diff --git a/projects/ui/src/lib/components/po-progress/po-progress-base.component.ts b/projects/ui/src/lib/components/po-progress/po-progress-base.component.ts index f9a03adc24..4dd8f28642 100644 --- a/projects/ui/src/lib/components/po-progress/po-progress-base.component.ts +++ b/projects/ui/src/lib/components/po-progress/po-progress-base.component.ts @@ -1,8 +1,9 @@ -import { EventEmitter, Input, Output, Directive } from '@angular/core'; +import { EventEmitter, Input, Output, Directive, TemplateRef } from '@angular/core'; import { convertToBoolean, convertToInt } from '../../utils/util'; import { PoProgressStatus } from './enums/po-progress-status.enum'; +import { PoProgressSize } from './enums/po-progress-size.enum'; const poProgressMaxValue = 100; const poProgressMinValue = 0; @@ -34,7 +35,7 @@ export class PoProgressBaseComponent { * * Exemplo: `po-icon-ok`. */ - @Input('p-info-icon') infoIcon?: string; + @Input('p-info-icon') infoIcon?: string | TemplateRef; /** * @optional @@ -85,6 +86,7 @@ export class PoProgressBaseComponent { private _indeterminate?: boolean; private _value?: number = 0; + private _size: string = 'large'; /** * @optional @@ -129,6 +131,38 @@ export class PoProgressBaseComponent { return this._value; } + /** + * @optional + * + * @description + * + * Definição do tamanho da altura da barra de progresso. + * + * Valores válidos: + * - `medium`: tamanho médio + * - `large`: tamanho grande + * + * @default `large` + */ + @Input('p-size') set size(value: string) { + this._size = PoProgressSize[value] ? PoProgressSize[value] : PoProgressSize.large; + } + + get size(): string { + return this._size; + } + + /** + * @optional + * + * @description + * + * Ativa a exibição da porcentagem atual da barra de progresso. + * + * @default `false` + */ + @Input({ alias: 'p-show-percentage', transform: convertToBoolean }) showPercentage: boolean = false; + private isProgressRangeValue(value: number): boolean { return value >= poProgressMinValue && value <= poProgressMaxValue; } diff --git a/projects/ui/src/lib/components/po-progress/po-progress.component.html b/projects/ui/src/lib/components/po-progress/po-progress.component.html index ab90830227..3ea580b358 100644 --- a/projects/ui/src/lib/components/po-progress/po-progress.component.html +++ b/projects/ui/src/lib/components/po-progress/po-progress.component.html @@ -1,30 +1,40 @@
- - - -
- +
-
- - {{ info }} + + - +
+
+ + + {{ + info + }} +
+
+ {{ value }}% + - + +
diff --git a/projects/ui/src/lib/components/po-progress/po-progress.component.spec.ts b/projects/ui/src/lib/components/po-progress/po-progress.component.spec.ts index 10df907426..3cfeef2919 100644 --- a/projects/ui/src/lib/components/po-progress/po-progress.component.spec.ts +++ b/projects/ui/src/lib/components/po-progress/po-progress.component.spec.ts @@ -149,9 +149,9 @@ describe('PoProgressComponent:', () => { fixture.detectChanges(); - const infoIcon = nativeElement.querySelector('.po-progress-info-icon'); + const infoIcon = nativeElement.querySelector('.po-icon-agro-business'); - expect(infoIcon.classList).toContain('po-icon-agro-business'); + expect(infoIcon).toBeTruthy(); }); it('shouldn`t find `.po-progress-info-icon` if `infoIcon` is `undefined`', () => { @@ -216,12 +216,12 @@ describe('PoProgressComponent:', () => { expect(nativeElement.querySelector('.po-progress-default')).toBeTruthy(); }); - it('should contain `po-progress-bar-indeterminate` if `indeterminate` is `true`', () => { + it('should contain `po-progress-bar-indeterminate-track` if `indeterminate` is `true`', () => { component.indeterminate = true; fixture.detectChanges(); - expect(nativeElement.querySelector('.po-progress-bar-indeterminate')).toBeTruthy(); + expect(nativeElement.querySelector('.po-progress-bar-indeterminate-track')).toBeTruthy(); }); it('shouldn`t contain `po-progress-bar-indeterminate` if `indeterminate` is `false`', () => { @@ -299,7 +299,7 @@ describe('PoProgressComponent:', () => { expect(progressInfo).toBeTruthy(); }); - it('shouldn`t find `.po-progress-info` if `info`, `infoIcon`, `isAllowRetry` and `isAllowCancel` are falsy', () => { + it('shouldn`t find `.po-progress-info-text` if `info`, `infoIcon`, `isAllowRetry` and `isAllowCancel` are falsy', () => { component.info = undefined; component.infoIcon = undefined; component.retry.observers.length = 0; @@ -307,7 +307,7 @@ describe('PoProgressComponent:', () => { fixture.detectChanges(); - const progressInfo = nativeElement.querySelector('.po-progress-info'); + const progressInfo = nativeElement.querySelector('.po-progress-info-text'); expect(progressInfo).toBe(null); }); diff --git a/projects/ui/src/lib/components/po-progress/po-progress.component.ts b/projects/ui/src/lib/components/po-progress/po-progress.component.ts index e85b376467..572120762c 100644 --- a/projects/ui/src/lib/components/po-progress/po-progress.component.ts +++ b/projects/ui/src/lib/components/po-progress/po-progress.component.ts @@ -32,8 +32,8 @@ export class PoProgressComponent extends PoProgressBaseComponent { return !!this.cancel.observers.length && this.status !== PoProgressStatus.Success; } - get isAllowProgressInfo(): boolean { - return !!(this.info || this.infoIcon || this.isAllowCancel || this.isAllowRetry); + get isAllowInfoError(): boolean { + return !!(!this.infoIcon && this.info && this.status === PoProgressStatus.Error); } get isAllowRetry(): boolean { diff --git a/projects/ui/src/lib/components/po-progress/po-progress.module.ts b/projects/ui/src/lib/components/po-progress/po-progress.module.ts index fc775b074f..b64955277d 100644 --- a/projects/ui/src/lib/components/po-progress/po-progress.module.ts +++ b/projects/ui/src/lib/components/po-progress/po-progress.module.ts @@ -3,6 +3,9 @@ import { NgModule } from '@angular/core'; import { PoProgressBarComponent } from './po-progress-bar/po-progress-bar.component'; import { PoProgressComponent } from './po-progress.component'; +import { PoButtonModule } from '../po-button/po-button.module'; +import { PoIconModule } from '../po-icon/po-icon.module'; +import { PoLabelModule } from '../po-label/po-label.module'; /** * @description @@ -10,7 +13,7 @@ import { PoProgressComponent } from './po-progress.component'; * Módulo do componente `po-progress`. */ @NgModule({ - imports: [CommonModule], + imports: [CommonModule, PoButtonModule, PoIconModule, PoLabelModule], exports: [PoProgressComponent], declarations: [PoProgressBarComponent, PoProgressComponent] }) diff --git a/projects/ui/src/lib/components/po-progress/samples/sample-po-progress-labs/sample-po-progress-labs.component.html b/projects/ui/src/lib/components/po-progress/samples/sample-po-progress-labs/sample-po-progress-labs.component.html index 0ca28aef9a..9fbbf681c9 100644 --- a/projects/ui/src/lib/components/po-progress/samples/sample-po-progress-labs/sample-po-progress-labs.component.html +++ b/projects/ui/src/lib/components/po-progress/samples/sample-po-progress-labs/sample-po-progress-labs.component.html @@ -1,10 +1,12 @@ @@ -45,6 +47,9 @@ + + +
diff --git a/projects/ui/src/lib/components/po-progress/samples/sample-po-progress-labs/sample-po-progress-labs.component.ts b/projects/ui/src/lib/components/po-progress/samples/sample-po-progress-labs/sample-po-progress-labs.component.ts index 93d2b0510c..93dd015f24 100644 --- a/projects/ui/src/lib/components/po-progress/samples/sample-po-progress-labs/sample-po-progress-labs.component.ts +++ b/projects/ui/src/lib/components/po-progress/samples/sample-po-progress-labs/sample-po-progress-labs.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; -import { PoCheckboxGroupOption, PoProgressStatus, PoRadioGroupOption } from '@po-ui/ng-components'; +import { PoCheckboxGroupOption, PoProgressStatus, PoRadioGroupOption, PoProgressSize } from '@po-ui/ng-components'; @Component({ selector: 'sample-po-progress-labs', @@ -12,6 +12,7 @@ export class SamplePoProgressLabsComponent implements OnInit { infoIcon: string; properties: Array; status: PoProgressStatus; + size: PoProgressSize = PoProgressSize.large; text: string; value: number; @@ -22,7 +23,10 @@ export class SamplePoProgressLabsComponent implements OnInit { { label: 'po-icon-no-signal', value: 'po-icon-no-signal' } ]; - propertiesOptions: Array = [{ label: 'Indeterminate', value: 'indeterminate' }]; + propertiesOptions: Array = [ + { label: 'Indeterminate', value: 'indeterminate' }, + { label: 'Show percentage', value: 'showPercentage' } + ]; statusOptions: Array = [ { label: 'Default', value: PoProgressStatus.Default }, @@ -30,6 +34,11 @@ export class SamplePoProgressLabsComponent implements OnInit { { label: 'Error', value: PoProgressStatus.Error } ]; + sizeOptions: Array = [ + { label: 'Medium', value: PoProgressSize.medium }, + { label: 'Large', value: PoProgressSize.large } + ]; + ngOnInit() { this.restore(); } @@ -46,5 +55,6 @@ export class SamplePoProgressLabsComponent implements OnInit { this.status = undefined; this.text = undefined; this.value = undefined; + this.size = PoProgressSize.large; } } diff --git a/projects/ui/src/lib/components/po-progress/samples/sample-po-progress-publication/sample-po-progress-publication.component.html b/projects/ui/src/lib/components/po-progress/samples/sample-po-progress-publication/sample-po-progress-publication.component.html index 7eb59784f0..28ec3be716 100644 --- a/projects/ui/src/lib/components/po-progress/samples/sample-po-progress-publication/sample-po-progress-publication.component.html +++ b/projects/ui/src/lib/components/po-progress/samples/sample-po-progress-publication/sample-po-progress-publication.component.html @@ -4,7 +4,7 @@ - +