Skip to content

Commit bb60a83

Browse files
committed
deprecate the string animation durations in favor of numbers
1 parent 230dbf1 commit bb60a83

File tree

10 files changed

+73
-29
lines changed

10 files changed

+73
-29
lines changed

src/material/dialog/dialog-animations.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
* Default parameters for the animation for backwards compatibility.
2222
* @docs-private
2323
*/
24-
export const defaultParams = {
24+
export const _defaultParams = {
2525
params: {enterAnimationDuration: '150ms', exitAnimationDuration: '75ms'},
2626
};
2727

@@ -48,15 +48,15 @@ export const matDialogAnimations: {
4848
),
4949
query('@*', animateChild(), {optional: true}),
5050
]),
51-
defaultParams,
51+
_defaultParams,
5252
),
5353
transition(
5454
'* => void, * => exit',
5555
group([
5656
animate('{{exitAnimationDuration}} cubic-bezier(0.4, 0.0, 0.2, 1)', style({opacity: 0})),
5757
query('@*', animateChild(), {optional: true}),
5858
]),
59-
defaultParams,
59+
_defaultParams,
6060
),
6161
]),
6262
};

src/material/dialog/dialog-config.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import {ViewContainerRef, ComponentFactoryResolver, Injector} from '@angular/core';
1010
import {Direction} from '@angular/cdk/bidi';
1111
import {ScrollStrategy} from '@angular/cdk/overlay';
12-
import {defaultParams} from './dialog-animations';
12+
import {_defaultParams} from './dialog-animations';
1313

1414
/** Options for where to set focus to automatically on dialog open */
1515
export type AutoFocusTarget = 'dialog' | 'first-tabbable' | 'first-heading';
@@ -133,11 +133,19 @@ export class MatDialogConfig<D = any> {
133133
/** Alternate `ComponentFactoryResolver` to use when resolving the associated component. */
134134
componentFactoryResolver?: ComponentFactoryResolver;
135135

136-
/** Duration of the enter animation. Has to be a valid CSS value (e.g. 100ms). */
137-
enterAnimationDuration?: string = defaultParams.params.enterAnimationDuration;
136+
/**
137+
* Duration of the enter animation in ms.
138+
* Should be a number, string type is deprecated.
139+
* @breaking-change 17.0.0 Remove string signature.
140+
*/
141+
enterAnimationDuration?: string | number;
138142

139-
/** Duration of the exit animation. Has to be a valid CSS value (e.g. 50ms). */
140-
exitAnimationDuration?: string = defaultParams.params.exitAnimationDuration;
143+
/**
144+
* Duration of the exit animation in ms.
145+
* Should be a number, string type is deprecated.
146+
* @breaking-change 17.0.0 Remove string signature.
147+
*/
148+
exitAnimationDuration?: string | number;
141149

142150
// TODO(jelbourn): add configuration for lifecycle hooks, ARIA labelling.
143151
}

src/material/dialog/dialog-container.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,24 @@ export abstract class _MatDialogContainerBase extends CdkDialogContainer<MatDial
8888

8989
const TRANSITION_DURATION_PROPERTY = '--mat-dialog-transition-duration';
9090

91-
function parseCssTime(time: string | undefined): number | null {
91+
/**
92+
* Converts a CSS time string to a number in ms. If the given time is already a
93+
* number, it is assumed to be in ms.
94+
*/
95+
function parseCssTime(time: string | number | undefined): number | null {
9296
if (time == null) {
9397
return null;
9498
}
99+
if (typeof time === 'number') {
100+
return time;
101+
}
95102
if (time.endsWith('ms')) {
96103
return coerceNumberProperty(time.substring(0, time.length - 2));
97-
} else if (time.endsWith('s')) {
104+
}
105+
if (time.endsWith('s')) {
98106
return coerceNumberProperty(time.substring(0, time.length - 1)) * 1000;
99-
} else if (time === '0') {
107+
}
108+
if (time === '0') {
100109
return 0;
101110
}
102111
return null; // anything else is invalid.

src/material/dialog/public-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ export * from './dialog-ref';
1212
export * from './dialog-content-directives';
1313
export * from './dialog-container';
1414
export * from './module';
15-
export {matDialogAnimations} from './dialog-animations';
15+
export {matDialogAnimations, _defaultParams} from './dialog-animations';
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {MatDialogConfig, _defaultParams} from '@angular/material/dialog';
10+
11+
export class MatLegacyDialogConfig extends MatDialogConfig {
12+
/** Duration of the enter animation. Has to be a valid CSS value (e.g. 100ms). */
13+
override enterAnimationDuration?: string = _defaultParams.params.enterAnimationDuration;
14+
15+
/** Duration of the exit animation. Has to be a valid CSS value (e.g. 50ms). */
16+
override exitAnimationDuration?: string = _defaultParams.params.exitAnimationDuration;
17+
}

src/material/legacy-dialog/dialog-container.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@ import {
2121
ViewEncapsulation,
2222
} from '@angular/core';
2323
import {defaultParams} from './dialog-animations';
24-
import {
25-
_MatDialogContainerBase,
26-
MatDialogConfig,
27-
matDialogAnimations,
28-
} from '@angular/material/dialog';
24+
import {MatLegacyDialogConfig} from './dialog-config';
25+
import {_MatDialogContainerBase, matDialogAnimations} from '@angular/material/dialog';
2926

3027
/**
3128
* Internal component that wraps user-provided dialog content.
@@ -90,7 +87,7 @@ export class MatLegacyDialogContainer extends _MatDialogContainerBase {
9087
elementRef: ElementRef,
9188
focusTrapFactory: FocusTrapFactory,
9289
@Optional() @Inject(DOCUMENT) document: any,
93-
dialogConfig: MatDialogConfig,
90+
dialogConfig: MatLegacyDialogConfig,
9491
checker: InteractivityChecker,
9592
ngZone: NgZone,
9693
overlayRef: OverlayRef,

src/material/legacy-dialog/dialog.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ import {Location} from '@angular/common';
1111
import {Inject, Injectable, InjectionToken, Injector, Optional, SkipSelf} from '@angular/core';
1212
import {MatLegacyDialogContainer} from './dialog-container';
1313
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
14-
import {_MatDialogBase, MatDialogConfig} from '@angular/material/dialog';
14+
import {_MatDialogBase} from '@angular/material/dialog';
1515
import {MatLegacyDialogRef} from './dialog-ref';
16+
import {MatLegacyDialogConfig} from './dialog-config';
1617

1718
/** Injection token that can be used to access the data that was passed in to a dialog. */
1819
export const MAT_LEGACY_DIALOG_DATA = new InjectionToken<any>('MatDialogData');
1920

2021
/** Injection token that can be used to specify default dialog options. */
21-
export const MAT_LEGACY_DIALOG_DEFAULT_OPTIONS = new InjectionToken<MatDialogConfig>(
22+
export const MAT_LEGACY_DIALOG_DEFAULT_OPTIONS = new InjectionToken<MatLegacyDialogConfig>(
2223
'mat-dialog-default-options',
2324
);
2425

@@ -54,7 +55,7 @@ export class MatLegacyDialog extends _MatDialogBase<MatLegacyDialogContainer> {
5455
* @breaking-change 10.0.0
5556
*/
5657
@Optional() _location: Location,
57-
@Optional() @Inject(MAT_LEGACY_DIALOG_DEFAULT_OPTIONS) defaultOptions: MatDialogConfig,
58+
@Optional() @Inject(MAT_LEGACY_DIALOG_DEFAULT_OPTIONS) defaultOptions: MatLegacyDialogConfig,
5859
@Inject(MAT_LEGACY_DIALOG_SCROLL_STRATEGY) scrollStrategy: any,
5960
@Optional() @SkipSelf() parentDialog: MatLegacyDialog,
6061
/**

src/material/legacy-dialog/public-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ export * from './dialog';
1111
export * from './dialog-container';
1212
export * from './dialog-content-directives';
1313
export * from './dialog-ref';
14+
export * from './dialog-config';
1415
export {
1516
_MatDialogBase as _MatLegacyDialogBase,
1617
_MatDialogContainerBase as _MatLegacyDialogContainerBase,
1718
AutoFocusTarget as LegacyAutoFocusTarget,
1819
DialogRole as LegacyDialogRole,
1920
DialogPosition as LegacyDialogPosition,
20-
MatDialogConfig as MatLegacyDialogConfig,
2121
_closeDialogVia as _closeLegacyDialogVia,
2222
MatDialogState as MatLegacyDialogState,
2323
matDialogAnimations as matLegacyDialogAnimations,

tools/public_api_guard/material/dialog.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ export type AutoFocusTarget = 'dialog' | 'first-tabbable' | 'first-heading';
4545
// @public
4646
export function _closeDialogVia<R>(ref: MatDialogRef<R>, interactionType: FocusOrigin, result?: R): void;
4747

48+
// @public
49+
export const _defaultParams: {
50+
params: {
51+
enterAnimationDuration: string;
52+
exitAnimationDuration: string;
53+
};
54+
};
55+
4856
// @public
4957
export interface DialogPosition {
5058
bottom?: string;
@@ -163,8 +171,8 @@ export class MatDialogConfig<D = any> {
163171
delayFocusTrap?: boolean;
164172
direction?: Direction;
165173
disableClose?: boolean;
166-
enterAnimationDuration?: string;
167-
exitAnimationDuration?: string;
174+
enterAnimationDuration?: string | number;
175+
exitAnimationDuration?: string | number;
168176
hasBackdrop?: boolean;
169177
height?: string;
170178
id?: string;

tools/public_api_guard/material/legacy-dialog.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import { DialogPosition as LegacyDialogPosition } from '@angular/material/dialog
2323
import { DialogRole as LegacyDialogRole } from '@angular/material/dialog';
2424
import { Location as Location_2 } from '@angular/common';
2525
import { MAT_DIALOG_SCROLL_STRATEGY_FACTORY as MAT_LEGACY_DIALOG_SCROLL_STRATEGY_FACTORY } from '@angular/material/dialog';
26+
import { MatDialogConfig } from '@angular/material/dialog';
2627
import { MatDialogRef } from '@angular/material/dialog';
2728
import { matDialogAnimations as matLegacyDialogAnimations } from '@angular/material/dialog';
2829
import { _MatDialogBase as _MatLegacyDialogBase } from '@angular/material/dialog';
29-
import { MatDialogConfig as MatLegacyDialogConfig } from '@angular/material/dialog';
3030
import { _MatDialogContainerBase as _MatLegacyDialogContainerBase } from '@angular/material/dialog';
3131
import { MatDialogState as MatLegacyDialogState } from '@angular/material/dialog';
3232
import { NgZone } from '@angular/core';
@@ -50,7 +50,7 @@ export { LegacyDialogRole }
5050
export const MAT_LEGACY_DIALOG_DATA: InjectionToken<any>;
5151

5252
// @public
53-
export const MAT_LEGACY_DIALOG_DEFAULT_OPTIONS: InjectionToken<MatLegacyDialogConfig<any>>;
53+
export const MAT_LEGACY_DIALOG_DEFAULT_OPTIONS: InjectionToken<MatLegacyDialogConfig>;
5454

5555
// @public
5656
export const MAT_LEGACY_DIALOG_SCROLL_STRATEGY: InjectionToken<() => ScrollStrategy>;
@@ -115,7 +115,11 @@ export class MatLegacyDialogClose implements OnInit, OnChanges {
115115
static ɵfac: i0.ɵɵFactoryDeclaration<MatLegacyDialogClose, [{ optional: true; }, null, null]>;
116116
}
117117

118-
export { MatLegacyDialogConfig }
118+
// @public (undocumented)
119+
export class MatLegacyDialogConfig extends MatDialogConfig {
120+
enterAnimationDuration?: string;
121+
exitAnimationDuration?: string;
122+
}
119123

120124
// @public
121125
export class MatLegacyDialogContainer extends _MatLegacyDialogContainerBase {
@@ -124,8 +128,8 @@ export class MatLegacyDialogContainer extends _MatLegacyDialogContainerBase {
124128
_getAnimationState(): {
125129
value: "void" | "enter" | "exit";
126130
params: {
127-
enterAnimationDuration: string;
128-
exitAnimationDuration: string;
131+
enterAnimationDuration: string | number;
132+
exitAnimationDuration: string | number;
129133
};
130134
};
131135
_onAnimationDone({ toState, totalTime }: AnimationEvent_2): void;

0 commit comments

Comments
 (0)