Skip to content

Commit

Permalink
Foundation: Update Progress templates
Browse files Browse the repository at this point in the history
  • Loading branch information
bheston committed Sep 24, 2023
1 parent 6091f89 commit a75c91f
Show file tree
Hide file tree
Showing 14 changed files with 155 additions and 143 deletions.
11 changes: 9 additions & 2 deletions packages/web-components/fast-foundation/docs/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -2529,14 +2529,21 @@ export type PickerOptions = {
// @public
export function pickerTemplate<T extends FASTPicker>(options: PickerOptions): ElementViewTemplate<T>;

// @public (undocumented)
export const progressIndicatorTemplate: ViewTemplate<any, any>;

// @public
export type ProgressOptions = {
indeterminateIndicator1?: StaticallyComposableHTML<FASTProgress>;
indeterminateIndicator2?: StaticallyComposableHTML<FASTProgress>;
determinateIndicator?: StaticallyComposableHTML<FASTProgress>;
indeterminateIndicator?: StaticallyComposableHTML<FASTProgress>;
};

// @public (undocumented)
export const progressRingIndicatorTemplate: ViewTemplate<any, any>;

// @public
export type ProgressRingOptions = {
determinateIndicator?: StaticallyComposableHTML<FASTProgressRing>;
indeterminateIndicator?: StaticallyComposableHTML<FASTProgressRing>;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export { FASTProgressRing } from "./progress-ring.js";
export { ProgressRingOptions } from "./progress-ring.options.js";
export { progressRingTemplate } from "./progress-ring.template.js";
export {
progressRingIndicatorTemplate,
progressRingTemplate,
} from "./progress-ring.template.js";
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import type { FASTProgressRing } from "./progress-ring.js";
* @public
*/
export type ProgressRingOptions = {
determinateIndicator?: StaticallyComposableHTML<FASTProgressRing>;
indeterminateIndicator?: StaticallyComposableHTML<FASTProgressRing>;
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect, test } from "@playwright/test";
import type { Locator, Page } from "@playwright/test";
import { fixtureURL } from "../__test__/helpers.js";
import type { FASTProgressRing } from "./progress-ring.js";

test.describe("Progress ring", () => {
let page: Page;
Expand Down Expand Up @@ -61,15 +62,67 @@ test.describe("Progress ring", () => {
await expect(element).toHaveAttribute("aria-valuemax", "75");
});

test("should render an element with a `determinate` slot when a value is provided", async () => {
test("should render an element with a `determinate` class when a value is provided", async () => {
await root.evaluate(node => {
node.innerHTML = /* html */ `
<fast-progress-ring value="50"></fast-progress-ring>
`;
});

const progress = element.locator(".progress");
const progress = element.locator(".determinate");

await expect(progress).toHaveAttribute("slot", "determinate");
await expect(progress).toHaveCount(1);
});

test("should render an element with an `indeterminate` class when no value is provided", async () => {
await root.evaluate(node => {
node.innerHTML = /* html */ `
<fast-progress-ring></fast-progress-ring>
`;
});

const progress = element.locator(".indeterminate");

await expect(progress).toHaveCount(1);
});

test("should return the `percentComplete` property as a value between 0 and 100 when `min` and `max` are unset", async () => {
await page.setContent(/* html */ `
<fast-progress-ring value="50"></fast-progress-ring>
`);

await expect(element).toHaveJSProperty("percentComplete", 50);
});

test("should set the `percentComplete` property to match the current `value` in the range of `min` and `max`", async () => {
await page.setContent(/* html */ `
<fast-progress-ring value="0"></fast-progress-ring>
`);

await expect(element).toHaveJSProperty("percentComplete", 0);

await element.evaluate((node: FASTProgressRing) => {
node.value = 50;
});

await expect(element).toHaveJSProperty("percentComplete", 50);

await element.evaluate((node: FASTProgressRing) => {
node.value = 100;
});

await expect(element).toHaveJSProperty("percentComplete", 100);

await element.evaluate((node: FASTProgressRing) => {
node.max = 200;
});

await expect(element).toHaveJSProperty("percentComplete", 50);

await element.evaluate((node: FASTProgressRing) => {
node.min = 100;
});

await expect(element).toHaveJSProperty("percentComplete", 0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ import { staticallyCompose } from "../utilities/template-helpers.js";
import type { FASTProgressRing } from "./progress-ring.js";
import type { ProgressRingOptions } from "./progress-ring.options.js";

const progressSegments: number = 44;
/**
* @public
*/
export const progressRingIndicatorTemplate = html`
<svg viewBox="0 0 16 16" class="progress">
<circle class="background" part="background" cx="8px" cy="8px" r="7px"></circle>
<circle class="indicator" part="indicator" cx="8px" cy="8px" r="7px"></circle>
</svg>
`;

/**
* The template for the {@link @microsoft/fast-foundation#FASTProgressRing} component.
Expand All @@ -23,35 +31,22 @@ export function progressRingTemplate<T extends FASTProgressRing>(
${when(
x => typeof x.value === "number",
html<T>`
<svg
class="progress"
part="progress"
viewBox="0 0 16 16"
slot="determinate"
<span
class="determinate"
part="determinate"
style="--percent-complete: ${x => x.percentComplete}"
>
<circle
class="background"
part="background"
cx="8px"
cy="8px"
r="7px"
></circle>
<circle
class="determinate"
part="determinate"
style="stroke-dasharray: ${x =>
(progressSegments * x.percentComplete) /
100}px ${progressSegments}px"
cx="8px"
cy="8px"
r="7px"
></circle>
</svg>
<slot name="determinate">
${staticallyCompose(options.determinateIndicator)}
</slot>
</span>
`,
html<T>`
<slot name="indeterminate">
${staticallyCompose(options.indeterminateIndicator)}
</slot>
<span class="indeterminate" part="indeterminate">
<slot name="indeterminate">
${staticallyCompose(options.indeterminateIndicator)}
</slot>
</span>
`
)}
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import { FASTBaseProgress } from "../progress/base-progress.js";
* An circular Progress HTML Element.
* Implements the {@link https://www.w3.org/TR/wai-aria-1.1/#progressbar | ARIA progressbar }.
*
* @slot indeterminate - The slot for a custom indeterminate indicator
* @slot determinate - The slot for a custom determinate indicator
* @csspart progress - Represents the progress element
* @slot determinate - The slot for the determinate indicator
* @slot indeterminate - The slot for the indeterminate indicator
* @csspart determinate - The determinate indicator
* @csspart background - The background
* @csspart indeterminate - The indeterminate indicator
*
* @public
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { html } from "@microsoft/fast-element";
import { css } from "@microsoft/fast-element";
import { FASTProgressRing } from "../progress-ring.js";
import { progressRingTemplate } from "../progress-ring.template.js";
import {
progressRingIndicatorTemplate,
progressRingTemplate,
} from "../progress-ring.template.js";

const styles = css`
:host {
Expand All @@ -24,17 +26,22 @@ const styles = css`
stroke-width: 2px;
}
.determinate {
.determinate .indicator {
--progress-segments: 44;
stroke: var(--accent-foreground-rest);
fill: none;
stroke-dasharray: calc(
((var(--progress-segments) * var(--percent-complete)) / 100) * 1px
)
calc(var(--progress-segments) * 1px);
stroke-width: 2px;
stroke-linecap: round;
transform-origin: 50% 50%;
transform: rotate(-90deg);
transition: all 0.2s ease-in-out;
}
.indeterminate-indicator-1 {
.indeterminate .indicator {
stroke: var(--accent-foreground-rest);
fill: none;
stroke-width: 2px;
Expand Down Expand Up @@ -64,24 +71,8 @@ const styles = css`
FASTProgressRing.define({
name: "fast-progress-ring",
template: progressRingTemplate({
indeterminateIndicator: /* html */ html`
<svg class="progress" part="progress" viewBox="0 0 16 16">
<circle
class="background"
part="background"
cx="8px"
cy="8px"
r="7px"
></circle>
<circle
class="indeterminate-indicator-1"
part="indeterminate-indicator-1"
cx="8px"
cy="8px"
r="7px"
></circle>
</svg>
`,
determinateIndicator: progressRingIndicatorTemplate,
indeterminateIndicator: progressRingIndicatorTemplate,
}),
styles,
});
16 changes: 8 additions & 8 deletions packages/web-components/fast-foundation/src/progress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,17 @@ export const myProgressRing = ProgressRing.compose<ProgressRingOptions>({

#### CSS Parts

| Name | Description |
| --------------- | ------------------------------- |
| `progress` | Represents the progress element |
| `determinate` | The determinate indicator |
| `indeterminate` | The indeterminate indicator |
| Name | Description |
| --------------- | --------------------------- |
| `determinate` | The determinate indicator |
| `indeterminate` | The indeterminate indicator |

#### Slots

| Name | Description |
| --------------- | --------------------------------------------- |
| `indeterminate` | The slot for a custom indeterminate indicator |
| Name | Description |
| --------------- | ---------------------------------------- |
| `determinate` | The slot for the determinate indicator |
| `indeterminate` | The slot for the indeterminate indicator |

<hr/>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { FASTBaseProgress } from "./base-progress.js";
export { FASTProgress } from "./progress.js";
export { ProgressOptions } from "./progress.options.js";
export { progressTemplate } from "./progress.template.js";
export { progressIndicatorTemplate, progressTemplate } from "./progress.template.js";
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import type { FASTProgress } from "./progress.js";
* @public
*/
export type ProgressOptions = {
indeterminateIndicator1?: StaticallyComposableHTML<FASTProgress>;
indeterminateIndicator2?: StaticallyComposableHTML<FASTProgress>;
determinateIndicator?: StaticallyComposableHTML<FASTProgress>;
indeterminateIndicator?: StaticallyComposableHTML<FASTProgress>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect, test } from "@playwright/test";
import { fixtureURL } from "../__test__/helpers.js";
import type { FASTProgress } from "./progress.js";

test.describe("Progress ring", () => {
test.describe("Progress", () => {
let page: Page;
let element: Locator;
let root: Locator;
Expand Down Expand Up @@ -56,28 +56,28 @@ test.describe("Progress ring", () => {
await expect(element).toHaveAttribute("aria-valuemax", "50");
});

test("should render an element with a `determinate` slot when a value is provided", async () => {
test("should render an element with a `determinate` class when a value is provided", async () => {
await root.evaluate(node => {
node.innerHTML = /* html */ `
<fast-progress value="50"></fast-progress>
`;
});

const progress = element.locator(".progress");
const progress = element.locator(".determinate");

await expect(progress).toHaveAttribute("slot", "determinate");
await expect(progress).toHaveCount(1);
});

test("should render an element with an `indeterminate` slot when no value is provided", async () => {
test("should render an element with an `indeterminate` class when no value is provided", async () => {
await root.evaluate(node => {
node.innerHTML = /* html */ `
<fast-progress></fast-progress>
`;
});

const progress = element.locator(".progress");
const progress = element.locator(".indeterminate");

await expect(progress).toHaveAttribute("slot", "indeterminate");
await expect(progress).toHaveCount(1);
});

test("should return the `percentComplete` property as a value between 0 and 100 when `min` and `max` are unset", async () => {
Expand Down
Loading

0 comments on commit a75c91f

Please sign in to comment.