Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(progress, progress-ring): decouple from FAST Foundation (VIV-2251) #2052

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions libs/components/src/lib/progress-ring/progress-ring.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@ describe('vwc-progress-ring', () => {
await elementUpdated(element);
const percentWithSmallRange = element.percentComplete;

element.min = 0;
element.max = 0;
element.value = 0;
await elementUpdated(element);
const percentWithEmptyRange = element.percentComplete;

expect(percentWithBigRange).toEqual(25);
expect(percentWithSmallRange).toEqual(50);
expect(percentWithEmptyRange).toEqual(0);
});

it('should set the determinate div width to percentComplete', async function () {
Expand Down
2 changes: 1 addition & 1 deletion libs/components/src/lib/progress-ring/progress-ring.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseProgress } from '@microsoft/fast-foundation';
import { attr } from '@microsoft/fast-element';
import type { Connotation } from '../enums';
import { BaseProgress } from '../../shared/foundation/progress/base-progress';

export type ProgressRingConnotation =
| Connotation.Accent
Expand Down
7 changes: 7 additions & 0 deletions libs/components/src/lib/progress/progress.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,15 @@ describe('vwc-progress', () => {
await elementUpdated(element);
const percentWithSmallRange = element.percentComplete;

element.min = 0;
element.max = 0;
element.value = 0;
await elementUpdated(element);
const percentWithEmptyRange = element.percentComplete;

expect(percentWithBigRange).toEqual(25);
expect(percentWithSmallRange).toEqual(50);
expect(percentWithEmptyRange).toEqual(0);
});

it('should set the determinate div width to percentComplete', async function () {
Expand Down
2 changes: 1 addition & 1 deletion libs/components/src/lib/progress/progress.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseProgress } from '@microsoft/fast-foundation';
import { attr } from '@microsoft/fast-element';
import type { Connotation, ConnotationDecorative, Shape } from '../enums';
import { BaseProgress } from '../../shared/foundation/progress/base-progress';

export type ProgressConnotation =
| Connotation.Accent
Expand Down
103 changes: 103 additions & 0 deletions libs/components/src/shared/foundation/progress/base-progress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import {
attr,
nullableNumberConverter,
observable,
} from '@microsoft/fast-element';
import { FoundationElement } from '@microsoft/fast-foundation';

/**
* An Progress HTML Element.
* Implements the {@link https://www.w3.org/TR/wai-aria-1.1/#progressbar | ARIA progressbar }.
*
* @public
*/
export class BaseProgress extends FoundationElement {
/**
* The value of the progress
* @public
* @remarks
* HTML Attribute: value
*/
@attr({ converter: nullableNumberConverter })
// @ts-expect-error Type is incorrectly non-optional
value: number | null;
/**
* @internal
*/
valueChanged() {
if (this.$fastController.isConnected) {
this.updatePercentComplete();
}
}

/**
* The minimum value
* @public
* @remarks
* HTML Attribute: min
*/
@attr({ converter: nullableNumberConverter })
// @ts-expect-error Type is incorrectly non-optional
min: number;
/**
* @internal
*/
minChanged() {
if (this.$fastController.isConnected) {
this.updatePercentComplete();
}
}

/**
* The maximum value
* @public
* @remarks
* HTML Attribute: max
*/
@attr({ converter: nullableNumberConverter })
// @ts-expect-error Type is incorrectly non-optional
max: number;
/**
* @private
*/
maxChanged() {
if (this.$fastController.isConnected) {
this.updatePercentComplete();
}
}

/**
* Indicates the progress is paused
* @public
* @remarks
* HTML Attribute: paused
*/
@attr({ mode: 'boolean' })
// @ts-expect-error Type is incorrectly non-optional
paused: boolean;

/**
* Indicates progress in %
* @internal
*/
@observable
percentComplete = 0;

/**
* @internal
*/
override connectedCallback() {
super.connectedCallback();
this.updatePercentComplete();
}

private updatePercentComplete() {
const min = typeof this.min === 'number' ? this.min : 0;
const max = typeof this.max === 'number' ? this.max : 100;
const value = typeof this.value === 'number' ? this.value : 0;
const range = max - min;

this.percentComplete =
range === 0 ? 0 : Math.fround(((value - min) / range) * 100);
}
}
Loading