9
9
import { Directionality } from '@angular/cdk/bidi' ;
10
10
import { Overlay , OverlayConfig , OverlayRef } from '@angular/cdk/overlay' ;
11
11
import { ComponentPortal , ComponentType , PortalInjector , TemplatePortal } from '@angular/cdk/portal' ;
12
- import { ComponentRef , Injectable , Injector , Optional , SkipSelf , TemplateRef } from '@angular/core' ;
12
+ import {
13
+ ComponentRef ,
14
+ Injectable ,
15
+ Injector ,
16
+ Optional ,
17
+ SkipSelf ,
18
+ TemplateRef ,
19
+ InjectionToken ,
20
+ Inject ,
21
+ } from '@angular/core' ;
13
22
import { Location } from '@angular/common' ;
14
23
import { of as observableOf } from 'rxjs' ;
15
24
import { MAT_BOTTOM_SHEET_DATA , MatBottomSheetConfig } from './bottom-sheet-config' ;
@@ -18,6 +27,10 @@ import {MatBottomSheetModule} from './bottom-sheet-module';
18
27
import { MatBottomSheetRef } from './bottom-sheet-ref' ;
19
28
20
29
30
+ /** Injection token that can be used to specify default bottom sheet options. */
31
+ export const MAT_BOTTOM_SHEET_DEFAULT_OPTIONS =
32
+ new InjectionToken < MatBottomSheetConfig > ( 'mat-bottom-sheet-default-options' ) ;
33
+
21
34
/**
22
35
* Service to trigger Material Design bottom sheets.
23
36
*/
@@ -43,7 +56,9 @@ export class MatBottomSheet {
43
56
private _overlay : Overlay ,
44
57
private _injector : Injector ,
45
58
@Optional ( ) @SkipSelf ( ) private _parentBottomSheet : MatBottomSheet ,
46
- @Optional ( ) private _location ?: Location ) { }
59
+ @Optional ( ) private _location ?: Location ,
60
+ @Optional ( ) @Inject ( MAT_BOTTOM_SHEET_DEFAULT_OPTIONS )
61
+ private _defaultOptions ?: MatBottomSheetConfig ) { }
47
62
48
63
open < T , D = any , R = any > ( component : ComponentType < T > ,
49
64
config ?: MatBottomSheetConfig < D > ) : MatBottomSheetRef < T , R > ;
@@ -53,7 +68,8 @@ export class MatBottomSheet {
53
68
open < T , D = any , R = any > ( componentOrTemplateRef : ComponentType < T > | TemplateRef < T > ,
54
69
config ?: MatBottomSheetConfig < D > ) : MatBottomSheetRef < T , R > {
55
70
56
- const _config = _applyConfigDefaults ( config ) ;
71
+ const _config =
72
+ _applyConfigDefaults ( this . _defaultOptions || new MatBottomSheetConfig ( ) , config ) ;
57
73
const overlayRef = this . _createOverlay ( _config ) ;
58
74
const container = this . _attachContainer ( overlayRef , _config ) ;
59
75
const ref = new MatBottomSheetRef < T , R > ( container , overlayRef , this . _location ) ;
@@ -171,9 +187,11 @@ export class MatBottomSheet {
171
187
172
188
/**
173
189
* Applies default options to the bottom sheet config.
190
+ * @param defaults Object containing the default values to which to fall back.
174
191
* @param config The configuration to which the defaults will be applied.
175
192
* @returns The new configuration object with defaults applied.
176
193
*/
177
- function _applyConfigDefaults ( config ?: MatBottomSheetConfig ) : MatBottomSheetConfig {
178
- return { ...new MatBottomSheetConfig ( ) , ...config } ;
194
+ function _applyConfigDefaults ( defaults : MatBottomSheetConfig ,
195
+ config ?: MatBottomSheetConfig ) : MatBottomSheetConfig {
196
+ return { ...defaults , ...config } ;
179
197
}
0 commit comments