Skip to content

Commit

Permalink
fix(material/progress-spinner): remove dependency on legacy progress …
Browse files Browse the repository at this point in the history
…spinner (angular#25583)

Fixes that the non-legacy progress spinner was depending on the legacy version.
  • Loading branch information
crisbeto authored and Martin Forstner committed Sep 16, 2022
1 parent 97a25cc commit d5db014
Show file tree
Hide file tree
Showing 23 changed files with 132 additions and 162 deletions.
2 changes: 1 addition & 1 deletion src/components-examples/material/table/BUILD.bazel
Expand Up @@ -24,7 +24,7 @@ ng_module(
"//src/material/legacy-checkbox",
"//src/material/legacy-input",
"//src/material/legacy-paginator",
"//src/material/progress-spinner",
"//src/material/legacy-progress-spinner",
"//src/material/sort",
"//src/material/table",
"//src/material/table/testing",
Expand Down
1 change: 1 addition & 0 deletions src/material/legacy-progress-spinner/BUILD.bazel
Expand Up @@ -23,6 +23,7 @@ ng_module(
"//src/cdk/platform",
"//src/cdk/scrolling",
"//src/material/core",
"//src/material/progress-spinner",
"@npm//@angular/animations",
"@npm//@angular/common",
"@npm//@angular/core",
Expand Down
63 changes: 9 additions & 54 deletions src/material/legacy-progress-spinner/progress-spinner.ts
Expand Up @@ -15,7 +15,6 @@ import {
Component,
ElementRef,
Inject,
InjectionToken,
Input,
Optional,
ViewEncapsulation,
Expand All @@ -24,17 +23,15 @@ import {
OnDestroy,
NgZone,
} from '@angular/core';
import {CanColor, mixinColor, ThemePalette} from '@angular/material/core';
import {CanColor, mixinColor} from '@angular/material/core';
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
import {
MatProgressSpinnerDefaultOptions,
MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS,
ProgressSpinnerMode,
} from '@angular/material/progress-spinner';
import {Subscription} from 'rxjs';

/**
* Possible mode for a progress spinner.
* @deprecated Use `ProgressSpinnerMode` from `@angular/material/progress-spinner` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
* @breaking-change 17.0.0
*/
export type LegacyProgressSpinnerMode = 'determinate' | 'indeterminate';

/**
* Base reference size of the spinner.
* @docs-private
Expand All @@ -56,48 +53,6 @@ const _MatProgressSpinnerBase = mixinColor(
'primary',
);

/**
* Default `mat-progress-spinner` options that can be overridden.
* @deprecated Use `MatProgressSpinnerDefaultOptions` from `@angular/material/progress-spinner` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
* @breaking-change 17.0.0
*/
export interface MatLegacyProgressSpinnerDefaultOptions {
/** Default color of the spinner. */
color?: ThemePalette;
/** Diameter of the spinner. */
diameter?: number;
/** Width of the spinner's stroke. */
strokeWidth?: number;
/**
* Whether the animations should be force to be enabled, ignoring if the current environment is
* using NoopAnimationsModule.
*/
_forceAnimations?: boolean;
}

/**
* Injection token to be used to override the default options for `mat-progress-spinner`.
* @deprecated Use `MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS` from `@angular/material/progress-spinner` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
* @breaking-change 17.0.0
*/
export const MAT_LEGACY_PROGRESS_SPINNER_DEFAULT_OPTIONS =
new InjectionToken<MatLegacyProgressSpinnerDefaultOptions>(
'mat-progress-spinner-default-options',
{
providedIn: 'root',
factory: MAT_LEGACY_PROGRESS_SPINNER_DEFAULT_OPTIONS_FACTORY,
},
);

/**
* @docs-private
* @deprecated Use `MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS_FACTORY` from `@angular/material/progress-spinner` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
* @breaking-change 17.0.0
*/
export function MAT_LEGACY_PROGRESS_SPINNER_DEFAULT_OPTIONS_FACTORY(): MatLegacyProgressSpinnerDefaultOptions {
return {diameter: BASE_SIZE};
}

// .0001 percentage difference is necessary in order to avoid unwanted animation frames
// for example because the animation duration is 4 seconds, .1% accounts to 4ms
// which are enough to see the flicker described in
Expand Down Expand Up @@ -210,7 +165,7 @@ export class MatLegacyProgressSpinner
}

/** Mode of the progress circle */
@Input() mode: LegacyProgressSpinnerMode = 'determinate';
@Input() mode: ProgressSpinnerMode = 'determinate';

/** Value of the progress circle. */
@Input()
Expand All @@ -226,8 +181,8 @@ export class MatLegacyProgressSpinner
_platform: Platform,
@Optional() @Inject(DOCUMENT) private _document: any,
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode: string,
@Inject(MAT_LEGACY_PROGRESS_SPINNER_DEFAULT_OPTIONS)
defaults?: MatLegacyProgressSpinnerDefaultOptions,
@Inject(MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS)
defaults?: MatProgressSpinnerDefaultOptions,
/**
* @deprecated `changeDetectorRef`, `viewportRuler` and `ngZone`
* parameters to become required.
Expand Down
13 changes: 7 additions & 6 deletions src/material/legacy-progress-spinner/public-api.ts
Expand Up @@ -9,13 +9,14 @@
import {MatLegacyProgressSpinner} from './progress-spinner';

export {MatLegacyProgressSpinnerModule} from './progress-spinner-module';
export {MatLegacyProgressSpinner} from './progress-spinner';

export {
MatLegacyProgressSpinner,
MAT_LEGACY_PROGRESS_SPINNER_DEFAULT_OPTIONS,
LegacyProgressSpinnerMode,
MatLegacyProgressSpinnerDefaultOptions,
MAT_LEGACY_PROGRESS_SPINNER_DEFAULT_OPTIONS_FACTORY,
} from './progress-spinner';
MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS as MAT_LEGACY_PROGRESS_SPINNER_DEFAULT_OPTIONS,
MatProgressSpinnerDefaultOptions as MatLegacyProgressSpinnerDefaultOptions,
MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS_FACTORY as MAT_LEGACY_PROGRESS_SPINNER_DEFAULT_OPTIONS_FACTORY,
ProgressSpinnerMode as LegacyProgressSpinnerMode,
} from '@angular/material/progress-spinner';

/**
* @deprecated Import Progress Spinner instead. Note that the
Expand Down
20 changes: 3 additions & 17 deletions src/material/legacy-progress-spinner/testing/BUILD.bazel
Expand Up @@ -12,6 +12,7 @@ ts_library(
"//src/cdk/coercion",
"//src/cdk/testing",
"//src/material/legacy-progress-spinner",
"//src/material/progress-spinner/testing",
],
)

Expand All @@ -20,28 +21,13 @@ filegroup(
srcs = glob(["**/*.ts"]),
)

ng_test_library(
name = "harness_tests_lib",
srcs = ["shared.spec.ts"],
deps = [
":testing",
"//src/cdk/testing",
"//src/cdk/testing/testbed",
"//src/material/legacy-progress-spinner",
"@npm//@angular/platform-browser",
],
)

ng_test_library(
name = "unit_tests_lib",
srcs = glob(
["**/*.spec.ts"],
exclude = ["shared.spec.ts"],
),
srcs = glob(["**/*.spec.ts"]),
deps = [
":harness_tests_lib",
":testing",
"//src/material/legacy-progress-spinner",
"//src/material/progress-spinner/testing:harness_tests_lib",
],
)

Expand Down

This file was deleted.

@@ -1,7 +1,7 @@
import {MatLegacyProgressSpinnerModule} from '@angular/material/legacy-progress-spinner';
import {runHarnessTests} from '@angular/material/legacy-progress-spinner/testing/shared.spec';
import {runHarnessTests} from '@angular/material/progress-spinner/testing/shared.spec';
import {MatLegacyProgressSpinnerHarness} from './progress-spinner-harness';

describe('Non-MDC-based MatProgressSpinnerHarness', () => {
runHarnessTests(MatLegacyProgressSpinnerModule, MatLegacyProgressSpinnerHarness);
runHarnessTests(MatLegacyProgressSpinnerModule, MatLegacyProgressSpinnerHarness as any);
});
Expand Up @@ -9,7 +9,7 @@
import {coerceNumberProperty} from '@angular/cdk/coercion';
import {ComponentHarness, HarnessPredicate} from '@angular/cdk/testing';
import {LegacyProgressSpinnerMode} from '@angular/material/legacy-progress-spinner';
import {LegacyProgressSpinnerHarnessFilters} from './progress-spinner-harness-filters';
import {ProgressSpinnerHarnessFilters} from '@angular/material/progress-spinner/testing';

/**
* Harness for interacting with a standard mat-progress-spinner in tests.
Expand All @@ -27,7 +27,7 @@ export class MatLegacyProgressSpinnerHarness extends ComponentHarness {
* @return a `HarnessPredicate` configured with the given options.
*/
static with(
options: LegacyProgressSpinnerHarnessFilters = {},
options: ProgressSpinnerHarnessFilters = {},
): HarnessPredicate<MatLegacyProgressSpinnerHarness> {
return new HarnessPredicate(MatLegacyProgressSpinnerHarness, options);
}
Expand Down
2 changes: 1 addition & 1 deletion src/material/legacy-progress-spinner/testing/public-api.ts
Expand Up @@ -7,4 +7,4 @@
*/

export {MatLegacyProgressSpinnerHarness} from './progress-spinner-harness';
export {LegacyProgressSpinnerHarnessFilters} from './progress-spinner-harness-filters';
export {ProgressSpinnerHarnessFilters as LegacyProgressSpinnerHarnessFilters} from '@angular/material/progress-spinner/testing';
2 changes: 0 additions & 2 deletions src/material/progress-spinner/BUILD.bazel
Expand Up @@ -24,7 +24,6 @@ ng_module(
deps = [
"//src/cdk/platform",
"//src/material/core",
"//src/material/legacy-progress-spinner",
"@npm//@angular/common",
"@npm//@angular/core",
],
Expand Down Expand Up @@ -58,7 +57,6 @@ ng_test_library(
deps = [
":progress-spinner",
"//src/cdk/platform",
"//src/material/legacy-progress-spinner",
"@npm//@angular/common",
"@npm//@angular/platform-browser",
],
Expand Down
10 changes: 5 additions & 5 deletions src/material/progress-spinner/progress-spinner.spec.ts
@@ -1,9 +1,9 @@
import {waitForAsync, TestBed} from '@angular/core/testing';
import {MatProgressSpinner, MatProgressSpinnerModule} from '@angular/material/progress-spinner';
import {CommonModule} from '@angular/common';
import {By} from '@angular/platform-browser';
import {MAT_LEGACY_PROGRESS_SPINNER_DEFAULT_OPTIONS} from '@angular/material/legacy-progress-spinner';
import {Component, ElementRef, ViewChild, ViewEncapsulation} from '@angular/core';
import {MatProgressSpinnerModule} from './module';
import {MatProgressSpinner, MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS} from './progress-spinner';

describe('MDC-based MatProgressSpinner', () => {
beforeEach(waitForAsync(() => {
Expand Down Expand Up @@ -301,7 +301,7 @@ describe('MDC-based MatProgressSpinner', () => {
declarations: [BasicProgressSpinner],
providers: [
{
provide: MAT_LEGACY_PROGRESS_SPINNER_DEFAULT_OPTIONS,
provide: MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS,
useValue: {diameter: 23},
},
],
Expand All @@ -322,7 +322,7 @@ describe('MDC-based MatProgressSpinner', () => {
declarations: [BasicProgressSpinner],
providers: [
{
provide: MAT_LEGACY_PROGRESS_SPINNER_DEFAULT_OPTIONS,
provide: MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS,
useValue: {strokeWidth: 7},
},
],
Expand All @@ -343,7 +343,7 @@ describe('MDC-based MatProgressSpinner', () => {
declarations: [BasicProgressSpinner],
providers: [
{
provide: MAT_LEGACY_PROGRESS_SPINNER_DEFAULT_OPTIONS,
provide: MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS,
useValue: {color: 'warn'},
},
],
Expand Down
38 changes: 31 additions & 7 deletions src/material/progress-spinner/progress-spinner.ts
Expand Up @@ -11,17 +11,14 @@ import {
Component,
ElementRef,
Inject,
InjectionToken,
Input,
Optional,
ViewChild,
ViewEncapsulation,
} from '@angular/core';
import {CanColor, mixinColor} from '@angular/material/core';
import {CanColor, mixinColor, ThemePalette} from '@angular/material/core';
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
import {
MAT_LEGACY_PROGRESS_SPINNER_DEFAULT_OPTIONS,
MatLegacyProgressSpinnerDefaultOptions,
} from '@angular/material/legacy-progress-spinner';
import {coerceNumberProperty, NumberInput} from '@angular/cdk/coercion';

// Boilerplate for applying mixins to MatProgressBar.
Expand All @@ -35,6 +32,33 @@ const _MatProgressSpinnerBase = mixinColor(
/** Possible mode for a progress spinner. */
export type ProgressSpinnerMode = 'determinate' | 'indeterminate';

/** Default `mat-progress-spinner` options that can be overridden. */
export interface MatProgressSpinnerDefaultOptions {
/** Default color of the spinner. */
color?: ThemePalette;
/** Diameter of the spinner. */
diameter?: number;
/** Width of the spinner's stroke. */
strokeWidth?: number;
/**
* Whether the animations should be force to be enabled, ignoring if the current environment is
* using NoopAnimationsModule.
*/
_forceAnimations?: boolean;
}

/** Injection token to be used to override the default options for `mat-progress-spinner`. */
export const MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS =
new InjectionToken<MatProgressSpinnerDefaultOptions>('mat-progress-spinner-default-options', {
providedIn: 'root',
factory: MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS_FACTORY,
});

/** @docs-private */
export function MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS_FACTORY(): MatProgressSpinnerDefaultOptions {
return {diameter: BASE_SIZE};
}

/**
* Base reference size of the spinner.
*/
Expand Down Expand Up @@ -79,8 +103,8 @@ export class MatProgressSpinner extends _MatProgressSpinnerBase implements CanCo
constructor(
elementRef: ElementRef<HTMLElement>,
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode: string,
@Inject(MAT_LEGACY_PROGRESS_SPINNER_DEFAULT_OPTIONS)
defaults?: MatLegacyProgressSpinnerDefaultOptions,
@Inject(MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS)
defaults?: MatProgressSpinnerDefaultOptions,
) {
super(elementRef);
this._noopAnimations =
Expand Down
6 changes: 0 additions & 6 deletions src/material/progress-spinner/public-api.ts
Expand Up @@ -8,9 +8,3 @@

export * from './progress-spinner';
export * from './module';

export {
MAT_LEGACY_PROGRESS_SPINNER_DEFAULT_OPTIONS as MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS,
MatLegacyProgressSpinnerDefaultOptions as MatProgressSpinnerDefaultOptions,
MAT_LEGACY_PROGRESS_SPINNER_DEFAULT_OPTIONS_FACTORY as MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS_FACTORY,
} from '@angular/material/legacy-progress-spinner';
21 changes: 18 additions & 3 deletions src/material/progress-spinner/testing/BUILD.bazel
Expand Up @@ -11,7 +11,7 @@ ng_module(
deps = [
"//src/cdk/coercion",
"//src/cdk/testing",
"//src/material/legacy-progress-spinner/testing",
"//src/material/progress-spinner",
],
)

Expand All @@ -20,12 +20,27 @@ filegroup(
srcs = glob(["**/*.ts"]),
)

ng_test_library(
name = "harness_tests_lib",
srcs = ["shared.spec.ts"],
deps = [
":testing",
"//src/cdk/testing",
"//src/cdk/testing/testbed",
"//src/material/progress-spinner",
"@npm//@angular/platform-browser",
],
)

ng_test_library(
name = "unit_tests_lib",
srcs = glob(["**/*.spec.ts"]),
srcs = glob(
["**/*.spec.ts"],
exclude = ["shared.spec.ts"],
),
deps = [
":harness_tests_lib",
":testing",
"//src/material/legacy-progress-spinner/testing:harness_tests_lib",
"//src/material/progress-spinner",
],
)
Expand Down

0 comments on commit d5db014

Please sign in to comment.