diff --git a/packages/calcite-components/src/components.d.ts b/packages/calcite-components/src/components.d.ts index ec69dc49efc..7f7ed0d712d 100644 --- a/packages/calcite-components/src/components.d.ts +++ b/packages/calcite-components/src/components.d.ts @@ -3312,9 +3312,9 @@ export namespace Components { */ "text": string; /** - * Specifies the component type. Use `"indeterminate"` if finding actual progress value is impossible. + * Specifies the component type. Use `"indeterminate"` if finding actual progress value is impossible. Otherwise, use `"determinate"` to have the value indicate the progress or `"determinate-value"` to have the value label displayed along the progress. */ - "type": "indeterminate" | "determinate"; + "type": "indeterminate" | "determinate" | "determinate-value"; /** * The component's value. Valid only for `"determinate"` indicators. Percent complete of 100. */ @@ -11404,9 +11404,9 @@ declare namespace LocalJSX { */ "text"?: string; /** - * Specifies the component type. Use `"indeterminate"` if finding actual progress value is impossible. + * Specifies the component type. Use `"indeterminate"` if finding actual progress value is impossible. Otherwise, use `"determinate"` to have the value indicate the progress or `"determinate-value"` to have the value label displayed along the progress. */ - "type"?: "indeterminate" | "determinate"; + "type"?: "indeterminate" | "determinate" | "determinate-value"; /** * The component's value. Valid only for `"determinate"` indicators. Percent complete of 100. */ diff --git a/packages/calcite-components/src/components/loader/loader.scss b/packages/calcite-components/src/components/loader/loader.scss index c02812b22ef..d3cf60765f4 100644 --- a/packages/calcite-components/src/components/loader/loader.scss +++ b/packages/calcite-components/src/components/loader/loader.scss @@ -36,21 +36,24 @@ $loader-circumference: ($loader-scale - (2 * $stroke-width)) * 3.14159; } :host([scale="s"]) { - --calcite-loader-font-size: theme("fontSize.n2"); + --calcite-loader-font-size: var(--calcite-font-size--3); --calcite-loader-size: theme("spacing.8"); --calcite-loader-size-inline: theme("spacing.3"); + --calcite-internal-loader-value-line-height: 0.625rem; // 10px } :host([scale="m"]) { --calcite-loader-font-size: theme("fontSize.0"); --calcite-loader-size: theme("spacing.16"); --calcite-loader-size-inline: theme("spacing.4"); + --calcite-internal-loader-value-line-height: 1.375rem; // 22px } :host([scale="l"]) { --calcite-loader-font-size: theme("fontSize.2"); --calcite-loader-size: theme("spacing.24"); --calcite-loader-size-inline: theme("spacing.6"); + --calcite-internal-loader-value-line-height: 1.71875rem; // 27.5px } :host([no-padding]) { @@ -70,13 +73,11 @@ $loader-circumference: ($loader-scale - (2 * $stroke-width)) * 3.14159; } .loader__percentage { - @apply text-color-1 absolute block text-center; + @apply block text-center text-color-1; font-size: var(--calcite-loader-font-size); inline-size: var(--calcite-loader-size); - inset-inline-start: 50%; - margin-inline-start: calc(var(--calcite-loader-size) / 2 * -1); - line-height: 0.25; - transform: scale(1, 1); + line-height: var(--calcite-internal-loader-value-line-height); + align-self: center; } .loader__svgs { @@ -89,6 +90,7 @@ $loader-circumference: ($loader-scale - (2 * $stroke-width)) * 3.14159; animation-timing-function: linear; animation-duration: scaleDuration(--calcite-internal-animation-timing-slow, 6.66); animation-name: loader-clockwise; + display: flex; } .loader__svg { @@ -110,7 +112,8 @@ $loader-circumference: ($loader-scale - (2 * $stroke-width)) * 3.14159; } } -:host([type="determinate"]) { +:host([type="determinate"]), +:host([type="determinate-value"]) { @apply animate-none; stroke: var(--calcite-color-border-3); .loader__svgs { diff --git a/packages/calcite-components/src/components/loader/loader.stories.ts b/packages/calcite-components/src/components/loader/loader.stories.ts index 204b43e033e..92d50234438 100644 --- a/packages/calcite-components/src/components/loader/loader.stories.ts +++ b/packages/calcite-components/src/components/loader/loader.stories.ts @@ -40,6 +40,44 @@ export const inline_TestOnly = (): string => html` `; +export const determinate = (): string => html` + +

determinate

+
+

s

+ +

m

+ +

l

+ +
+
+

determinate-value

+
+

s

+ + +

m

+ + +

l

+ + +
+`; + export const customTheme_TestOnly = (): string => html` ))} + {isDeterminate &&
{this.formatValue()}
} {text &&
{text}
} - {isDeterminate &&
{value}
} ); } + private formatValue = (): string => { + if (this.type !== "determinate-value") { + return `${this.value}`; + } + + return this.formatter.format(this.value / 100); + }; + //-------------------------------------------------------------------------- // // Private Properties @@ -102,6 +121,16 @@ export class Loader { @Element() el: HTMLCalciteLoaderElement; + @State() effectiveLocale = ""; + + @Watch("effectiveLocale") + @Watch("type") + formatterPropsChange(): void { + this.updateFormatter(); + } + + private formatter: Intl.NumberFormat; + //-------------------------------------------------------------------------- // // Private Methods @@ -128,4 +157,17 @@ export class Loader { l: 20, }[scale]; } + + private updateFormatter(): void { + if ( + this.type !== "determinate-value" || + this.formatter?.resolvedOptions().locale === this.effectiveLocale + ) { + return; + } + + this.formatter = new Intl.NumberFormat(this.effectiveLocale, { + style: "percent", + }); + } }