Skip to content

Commit 1cfce8d

Browse files
authored
fix(overlay): rename OverlayState to OverlayConfig (#6972)
BREAKING CHANGE: OverlayState has been renamed to OverlayConfig
1 parent a944f6e commit 1cfce8d

17 files changed

+62
-70
lines changed

src/cdk/overlay/overlay-state.ts renamed to src/cdk/overlay/overlay-config.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ import {ScrollStrategy} from './scroll/scroll-strategy';
1212
import {NoopScrollStrategy} from './scroll/noop-scroll-strategy';
1313

1414

15-
/**
16-
* OverlayState is a bag of values for either the initial configuration or current state of an
17-
* overlay.
18-
*/
19-
export class OverlayState {
15+
/** OverlayConfig captures the initial configuration used when opening an overlay. */
16+
export class OverlayConfig {
2017
/** Strategy with which to position the overlay. */
2118
positionStrategy?: PositionStrategy;
2219

@@ -53,14 +50,9 @@ export class OverlayState {
5350
/** The direction of the text in the overlay panel. */
5451
direction?: Direction = 'ltr';
5552

56-
constructor(state?: OverlayState) {
53+
constructor(state?: OverlayConfig) {
5754
if (state) {
5855
Object.keys(state).forEach(key => this[key] = state[key]);
5956
}
6057
}
61-
62-
// TODO(jelbourn): configuration still to add
63-
// - focus trap
64-
// - disable pointer events
65-
// - z-index
6658
}

src/cdk/overlay/overlay-directives.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {ESCAPE} from '@angular/cdk/keycodes';
2828
import {TemplatePortal} from '@angular/cdk/portal';
2929
import {Overlay} from './overlay';
3030
import {OverlayRef} from './overlay-ref';
31-
import {OverlayState} from './overlay-state';
31+
import {OverlayConfig} from './overlay-config';
3232
import {
3333
// This import is only used to define a generic type. The current TypeScript version incorrectly
3434
// considers such imports as unused (https://github.com/Microsoft/TypeScript/issues/14953)
@@ -271,9 +271,9 @@ export class ConnectedOverlayDirective implements OnDestroy, OnChanges {
271271
}
272272

273273
/** Builds the overlay config based on the directive's inputs */
274-
private _buildConfig(): OverlayState {
274+
private _buildConfig(): OverlayConfig {
275275
const positionStrategy = this._position = this._createPositionStrategy();
276-
const overlayConfig = new OverlayState({
276+
const overlayConfig = new OverlayConfig({
277277
positionStrategy,
278278
scrollStrategy: this.scrollStrategy,
279279
hasBackdrop: this.hasBackdrop

src/cdk/overlay/overlay-ref.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {NgZone} from '@angular/core';
1010
import {PortalHost, Portal} from '@angular/cdk/portal';
11-
import {OverlayState} from './overlay-state';
11+
import {OverlayConfig} from './overlay-config';
1212
import {Observable} from 'rxjs/Observable';
1313
import {Subject} from 'rxjs/Subject';
1414

@@ -26,7 +26,7 @@ export class OverlayRef implements PortalHost {
2626
constructor(
2727
private _portalHost: PortalHost,
2828
private _pane: HTMLElement,
29-
private _state: OverlayState,
29+
private _state: OverlayConfig,
3030
private _ngZone: NgZone) {
3131

3232
if (_state.scrollStrategy) {
@@ -154,7 +154,7 @@ export class OverlayRef implements PortalHost {
154154
/**
155155
* Gets the current state config of the overlay.
156156
*/
157-
getState(): OverlayState {
157+
getState(): OverlayConfig {
158158
return this._state;
159159
}
160160

src/cdk/overlay/overlay.spec.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
OverlayContainer,
1212
OverlayModule,
1313
OverlayRef,
14-
OverlayState,
14+
OverlayConfig,
1515
PositionStrategy,
1616
ScrollStrategy,
1717
} from './index';
@@ -133,7 +133,7 @@ describe('Overlay', () => {
133133
});
134134

135135
it('should set the direction', () => {
136-
const state = new OverlayState({direction: 'rtl'});
136+
const state = new OverlayConfig({direction: 'rtl'});
137137

138138
overlay.create(state).attach(componentPortal);
139139

@@ -152,7 +152,7 @@ describe('Overlay', () => {
152152
});
153153

154154
it('should emit the attachment event after everything is added to the DOM', () => {
155-
let state = new OverlayState({hasBackdrop: true});
155+
let state = new OverlayConfig({hasBackdrop: true});
156156
let overlayRef = overlay.create(state);
157157

158158
overlayRef.attachments().subscribe(() => {
@@ -220,10 +220,10 @@ describe('Overlay', () => {
220220
});
221221

222222
describe('positioning', () => {
223-
let state: OverlayState;
223+
let state: OverlayConfig;
224224

225225
beforeEach(() => {
226-
state = new OverlayState();
226+
state = new OverlayConfig();
227227
});
228228

229229
it('should apply the positioning strategy', () => {
@@ -236,10 +236,10 @@ describe('Overlay', () => {
236236
});
237237

238238
describe('size', () => {
239-
let state: OverlayState;
239+
let state: OverlayConfig;
240240

241241
beforeEach(() => {
242-
state = new OverlayState();
242+
state = new OverlayConfig();
243243
});
244244

245245
it('should apply the width set in the config', () => {
@@ -320,10 +320,10 @@ describe('Overlay', () => {
320320
});
321321

322322
describe('backdrop', () => {
323-
let config: OverlayState;
323+
let config: OverlayConfig;
324324

325325
beforeEach(() => {
326-
config = new OverlayState();
326+
config = new OverlayConfig();
327327
config.hasBackdrop = true;
328328
});
329329

@@ -411,7 +411,7 @@ describe('Overlay', () => {
411411

412412
describe('panelClass', () => {
413413
it('should apply a custom overlay pane class', () => {
414-
const config = new OverlayState({panelClass: 'custom-panel-class'});
414+
const config = new OverlayConfig({panelClass: 'custom-panel-class'});
415415

416416
overlay.create(config).attach(componentPortal);
417417
viewContainerFixture.detectChanges();
@@ -421,7 +421,7 @@ describe('Overlay', () => {
421421
});
422422

423423
it('should be able to apply multiple classes', () => {
424-
const config = new OverlayState({panelClass: ['custom-class-one', 'custom-class-two']});
424+
const config = new OverlayConfig({panelClass: ['custom-class-one', 'custom-class-two']});
425425

426426
overlay.create(config).attach(componentPortal);
427427
viewContainerFixture.detectChanges();
@@ -435,12 +435,12 @@ describe('Overlay', () => {
435435

436436
describe('scroll strategy', () => {
437437
let fakeScrollStrategy: FakeScrollStrategy;
438-
let config: OverlayState;
438+
let config: OverlayConfig;
439439
let overlayRef: OverlayRef;
440440

441441
beforeEach(() => {
442442
fakeScrollStrategy = new FakeScrollStrategy();
443-
config = new OverlayState({scrollStrategy: fakeScrollStrategy});
443+
config = new OverlayConfig({scrollStrategy: fakeScrollStrategy});
444444
overlayRef = overlay.create(config);
445445
});
446446

src/cdk/overlay/overlay.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
NgZone,
1515
} from '@angular/core';
1616
import {DomPortalHost} from '@angular/cdk/portal';
17-
import {OverlayState} from './overlay-state';
17+
import {OverlayConfig} from './overlay-config';
1818
import {OverlayRef} from './overlay-ref';
1919
import {OverlayPositionBuilder} from './position/overlay-position-builder';
2020
import {OverlayContainer} from './overlay-container';
@@ -25,7 +25,7 @@ import {ScrollStrategyOptions} from './scroll/index';
2525
let nextUniqueId = 0;
2626

2727
/** The default state for newly created overlays. */
28-
let defaultState = new OverlayState();
28+
let defaultState = new OverlayConfig();
2929

3030

3131
/**
@@ -51,7 +51,7 @@ export class Overlay {
5151
* @param state State to apply to the overlay.
5252
* @returns Reference to the created overlay.
5353
*/
54-
create(state: OverlayState = defaultState): OverlayRef {
54+
create(state: OverlayConfig = defaultState): OverlayRef {
5555
const pane = this._createPaneElement();
5656
const portalHost = this._createPortalHost(pane);
5757
return new OverlayRef(portalHost, pane, state, this._ngZone);

src/cdk/overlay/public_api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export {Overlay} from './overlay';
4040
export {OverlayContainer} from './overlay-container';
4141
export {FullscreenOverlayContainer} from './fullscreen-overlay-container';
4242
export {OverlayRef} from './overlay-ref';
43-
export {OverlayState} from './overlay-state';
43+
export {OverlayConfig} from './overlay-config';
4444
export {ConnectedOverlayDirective, OverlayOrigin} from './overlay-directives';
4545
export {ViewportRuler} from '@angular/cdk/scrolling';
4646
export {ComponentType} from '@angular/cdk/portal';

src/cdk/overlay/scroll/block-scroll-strategy.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {async, inject, TestBed} from '@angular/core/testing';
33
import {ComponentPortal, PortalModule} from '@angular/cdk/portal';
44
import {Platform} from '@angular/cdk/platform';
55
import {ViewportRuler} from '@angular/cdk/scrolling';
6-
import {Overlay, OverlayContainer, OverlayModule, OverlayRef, OverlayState} from '../index';
6+
import {Overlay, OverlayContainer, OverlayModule, OverlayRef, OverlayConfig} from '../index';
77

88

99
describe('BlockScrollStrategy', () => {
@@ -23,9 +23,9 @@ describe('BlockScrollStrategy', () => {
2323
}));
2424

2525
beforeEach(inject([Overlay, ViewportRuler], (overlay: Overlay, viewportRuler: ViewportRuler) => {
26-
let overlayState = new OverlayState({scrollStrategy: overlay.scrollStrategies.block()});
26+
let overlayConfig = new OverlayConfig({scrollStrategy: overlay.scrollStrategies.block()});
2727

28-
overlayRef = overlay.create(overlayState);
28+
overlayRef = overlay.create(overlayConfig);
2929
componentPortal = new ComponentPortal(FocacciaMsg);
3030

3131
viewport = viewportRuler;

src/cdk/overlay/scroll/close-scroll-strategy.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {ComponentPortal, PortalModule} from '@angular/cdk/portal';
55
import {ScrollDispatcher} from '@angular/cdk/scrolling';
66
import {
77
Overlay,
8-
OverlayState,
8+
OverlayConfig,
99
OverlayRef,
1010
OverlayModule,
1111
OverlayContainer,
@@ -33,8 +33,8 @@ describe('CloseScrollStrategy', () => {
3333
}));
3434

3535
beforeEach(inject([Overlay], (overlay: Overlay) => {
36-
let overlayState = new OverlayState({scrollStrategy: overlay.scrollStrategies.close()});
37-
overlayRef = overlay.create(overlayState);
36+
let overlayConfig = new OverlayConfig({scrollStrategy: overlay.scrollStrategies.close()});
37+
overlayRef = overlay.create(overlayConfig);
3838
componentPortal = new ComponentPortal(MozarellaMsg);
3939
}));
4040

src/cdk/overlay/scroll/reposition-scroll-strategy.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
OverlayContainer,
88
OverlayModule,
99
OverlayRef,
10-
OverlayState,
10+
OverlayConfig,
1111
ScrollDispatcher,
1212
} from '../index';
1313

@@ -33,8 +33,8 @@ describe('RepositionScrollStrategy', () => {
3333
}));
3434

3535
beforeEach(inject([Overlay], (overlay: Overlay) => {
36-
let overlayState = new OverlayState({scrollStrategy: overlay.scrollStrategies.reposition()});
37-
overlayRef = overlay.create(overlayState);
36+
let overlayConfig = new OverlayConfig({scrollStrategy: overlay.scrollStrategies.reposition()});
37+
overlayRef = overlay.create(overlayConfig);
3838
componentPortal = new ComponentPortal(PastaMsg);
3939
}));
4040

src/cdk/overlay/scroll/scroll-strategy.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ recalculate the position, close the overlay, block scrolling, etc.
77

88
## Usage
99
To associate an overlay with a scroll strategy, you have to pass in a function, that returns a
10-
scroll strategy, to the `OverlayState`. By default, all overlays will use the `noop` strategy which
10+
scroll strategy, to the `OverlayConfig`. By default, all overlays will use the `noop` strategy which
1111
doesn't do anything. The other available strategies are `reposition`, `block` and `close`:
1212

1313
```ts
14-
let overlayState = new OverlayState({
14+
let overlayConfig = new OverlayConfig({
1515
scrollStrategy: overlay.scrollStrategies.block()
1616
});
1717

18-
this._overlay.create(overlayState).attach(yourPortal);
18+
this._overlay.create(overlayConfig).attach(yourPortal);
1919
```
2020

2121
## Creating a custom scroll strategy
@@ -35,6 +35,6 @@ export class CustomScrollStrategy implements ScrollStrategy {
3535
// your implementation
3636
}
3737

38-
overlayState.scrollStrategy = new CustomScrollStrategy();
39-
this._overlay.create(overlayState).attach(yourPortal);
38+
overlayConfig.scrollStrategy = new CustomScrollStrategy();
39+
this._overlay.create(overlayConfig).attach(yourPortal);
4040
```

src/demo-app/overlay/overlay-demo.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Overlay, OverlayOrigin, OverlayState} from '@angular/cdk/overlay';
1+
import {Overlay, OverlayOrigin, OverlayConfig} from '@angular/cdk/overlay';
22
import {
33
ComponentPortal,
44
// This import is only used to define a generic type. The current TypeScript version incorrectly
@@ -38,7 +38,7 @@ export class OverlayDemo {
3838
constructor(public overlay: Overlay, public viewContainerRef: ViewContainerRef) { }
3939

4040
openRotiniPanel() {
41-
let config = new OverlayState();
41+
let config = new OverlayConfig();
4242

4343
config.positionStrategy = this.overlay.position()
4444
.global()
@@ -52,7 +52,7 @@ export class OverlayDemo {
5252
}
5353

5454
openFusilliPanel() {
55-
let config = new OverlayState();
55+
let config = new OverlayConfig();
5656

5757
config.positionStrategy = this.overlay.position()
5858
.global()
@@ -73,7 +73,7 @@ export class OverlayDemo {
7373
{originX: 'start', originY: 'bottom'},
7474
{overlayX: 'start', overlayY: 'top'} );
7575

76-
let config = new OverlayState({positionStrategy: strategy});
76+
let config = new OverlayConfig({positionStrategy: strategy});
7777
let overlayRef = this.overlay.create(config);
7878

7979
overlayRef.attach(new ComponentPortal(SpagettiPanel, this.viewContainerRef));
@@ -86,14 +86,14 @@ export class OverlayDemo {
8686
{originX: 'start', originY: 'bottom'},
8787
{overlayX: 'end', overlayY: 'top'} );
8888

89-
let config = new OverlayState({positionStrategy: strategy});
89+
let config = new OverlayConfig({positionStrategy: strategy});
9090
let overlayRef = this.overlay.create(config);
9191

9292
overlayRef.attach(this.tortelliniTemplate);
9393
}
9494

9595
openPanelWithBackdrop() {
96-
let config = new OverlayState({
96+
let config = new OverlayConfig({
9797
hasBackdrop: true,
9898
backdropClass: 'cdk-overlay-transparent-backdrop',
9999
positionStrategy: this.overlay.position().global().centerHorizontally()

src/lib/autocomplete/autocomplete-trigger.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
ConnectedPositionStrategy,
1313
Overlay,
1414
OverlayRef,
15-
OverlayState,
15+
OverlayConfig,
1616
PositionStrategy,
1717
RepositionScrollStrategy,
1818
ScrollStrategy,
@@ -464,8 +464,8 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
464464
this._panelOpen = true;
465465
}
466466

467-
private _getOverlayConfig(): OverlayState {
468-
return new OverlayState({
467+
private _getOverlayConfig(): OverlayConfig {
468+
return new OverlayConfig({
469469
positionStrategy: this._getOverlayPosition(),
470470
scrollStrategy: this._scrollStrategy(),
471471
width: this._getHostWidth(),

src/lib/datepicker/datepicker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {ESCAPE} from '@angular/cdk/keycodes';
1212
import {
1313
Overlay,
1414
OverlayRef,
15-
OverlayState,
15+
OverlayConfig,
1616
PositionStrategy,
1717
RepositionScrollStrategy,
1818
ScrollStrategy,
@@ -331,7 +331,7 @@ export class MdDatepicker<D> implements OnDestroy {
331331

332332
/** Create the popup. */
333333
private _createPopup(): void {
334-
const overlayState = new OverlayState({
334+
const overlayState = new OverlayConfig({
335335
positionStrategy: this._createPopupPositionStrategy(),
336336
hasBackdrop: true,
337337
backdropClass: 'md-overlay-transparent-backdrop',

0 commit comments

Comments
 (0)