fix(overlay): rename OverlayState to OverlayConfig (#6972)

BREAKING CHANGE: OverlayState has been renamed to OverlayConfig
This commit is contained in:
Jeremy Elbourn
2017-09-20 16:05:04 -07:00
committed by GitHub
parent a944f6e0f2
commit 1cfce8d9ab
17 changed files with 62 additions and 70 deletions
@@ -12,11 +12,8 @@ import {ScrollStrategy} from './scroll/scroll-strategy';
import {NoopScrollStrategy} from './scroll/noop-scroll-strategy';
/**
* OverlayState is a bag of values for either the initial configuration or current state of an
* overlay.
*/
export class OverlayState {
/** OverlayConfig captures the initial configuration used when opening an overlay. */
export class OverlayConfig {
/** Strategy with which to position the overlay. */
positionStrategy?: PositionStrategy;
@@ -53,14 +50,9 @@ export class OverlayState {
/** The direction of the text in the overlay panel. */
direction?: Direction = 'ltr';
constructor(state?: OverlayState) {
constructor(state?: OverlayConfig) {
if (state) {
Object.keys(state).forEach(key => this[key] = state[key]);
}
}
// TODO(jelbourn): configuration still to add
// - focus trap
// - disable pointer events
// - z-index
}
+3 -3
View File
@@ -28,7 +28,7 @@ import {ESCAPE} from '@angular/cdk/keycodes';
import {TemplatePortal} from '@angular/cdk/portal';
import {Overlay} from './overlay';
import {OverlayRef} from './overlay-ref';
import {OverlayState} from './overlay-state';
import {OverlayConfig} from './overlay-config';
import {
// This import is only used to define a generic type. The current TypeScript version incorrectly
// considers such imports as unused (https://github.com/Microsoft/TypeScript/issues/14953)
@@ -271,9 +271,9 @@ export class ConnectedOverlayDirective implements OnDestroy, OnChanges {
}
/** Builds the overlay config based on the directive's inputs */
private _buildConfig(): OverlayState {
private _buildConfig(): OverlayConfig {
const positionStrategy = this._position = this._createPositionStrategy();
const overlayConfig = new OverlayState({
const overlayConfig = new OverlayConfig({
positionStrategy,
scrollStrategy: this.scrollStrategy,
hasBackdrop: this.hasBackdrop
+3 -3
View File
@@ -8,7 +8,7 @@
import {NgZone} from '@angular/core';
import {PortalHost, Portal} from '@angular/cdk/portal';
import {OverlayState} from './overlay-state';
import {OverlayConfig} from './overlay-config';
import {Observable} from 'rxjs/Observable';
import {Subject} from 'rxjs/Subject';
@@ -26,7 +26,7 @@ export class OverlayRef implements PortalHost {
constructor(
private _portalHost: PortalHost,
private _pane: HTMLElement,
private _state: OverlayState,
private _state: OverlayConfig,
private _ngZone: NgZone) {
if (_state.scrollStrategy) {
@@ -154,7 +154,7 @@ export class OverlayRef implements PortalHost {
/**
* Gets the current state config of the overlay.
*/
getState(): OverlayState {
getState(): OverlayConfig {
return this._state;
}
+13 -13
View File
@@ -11,7 +11,7 @@ import {
OverlayContainer,
OverlayModule,
OverlayRef,
OverlayState,
OverlayConfig,
PositionStrategy,
ScrollStrategy,
} from './index';
@@ -133,7 +133,7 @@ describe('Overlay', () => {
});
it('should set the direction', () => {
const state = new OverlayState({direction: 'rtl'});
const state = new OverlayConfig({direction: 'rtl'});
overlay.create(state).attach(componentPortal);
@@ -152,7 +152,7 @@ describe('Overlay', () => {
});
it('should emit the attachment event after everything is added to the DOM', () => {
let state = new OverlayState({hasBackdrop: true});
let state = new OverlayConfig({hasBackdrop: true});
let overlayRef = overlay.create(state);
overlayRef.attachments().subscribe(() => {
@@ -220,10 +220,10 @@ describe('Overlay', () => {
});
describe('positioning', () => {
let state: OverlayState;
let state: OverlayConfig;
beforeEach(() => {
state = new OverlayState();
state = new OverlayConfig();
});
it('should apply the positioning strategy', () => {
@@ -236,10 +236,10 @@ describe('Overlay', () => {
});
describe('size', () => {
let state: OverlayState;
let state: OverlayConfig;
beforeEach(() => {
state = new OverlayState();
state = new OverlayConfig();
});
it('should apply the width set in the config', () => {
@@ -320,10 +320,10 @@ describe('Overlay', () => {
});
describe('backdrop', () => {
let config: OverlayState;
let config: OverlayConfig;
beforeEach(() => {
config = new OverlayState();
config = new OverlayConfig();
config.hasBackdrop = true;
});
@@ -411,7 +411,7 @@ describe('Overlay', () => {
describe('panelClass', () => {
it('should apply a custom overlay pane class', () => {
const config = new OverlayState({panelClass: 'custom-panel-class'});
const config = new OverlayConfig({panelClass: 'custom-panel-class'});
overlay.create(config).attach(componentPortal);
viewContainerFixture.detectChanges();
@@ -421,7 +421,7 @@ describe('Overlay', () => {
});
it('should be able to apply multiple classes', () => {
const config = new OverlayState({panelClass: ['custom-class-one', 'custom-class-two']});
const config = new OverlayConfig({panelClass: ['custom-class-one', 'custom-class-two']});
overlay.create(config).attach(componentPortal);
viewContainerFixture.detectChanges();
@@ -435,12 +435,12 @@ describe('Overlay', () => {
describe('scroll strategy', () => {
let fakeScrollStrategy: FakeScrollStrategy;
let config: OverlayState;
let config: OverlayConfig;
let overlayRef: OverlayRef;
beforeEach(() => {
fakeScrollStrategy = new FakeScrollStrategy();
config = new OverlayState({scrollStrategy: fakeScrollStrategy});
config = new OverlayConfig({scrollStrategy: fakeScrollStrategy});
overlayRef = overlay.create(config);
});
+3 -3
View File
@@ -14,7 +14,7 @@ import {
NgZone,
} from '@angular/core';
import {DomPortalHost} from '@angular/cdk/portal';
import {OverlayState} from './overlay-state';
import {OverlayConfig} from './overlay-config';
import {OverlayRef} from './overlay-ref';
import {OverlayPositionBuilder} from './position/overlay-position-builder';
import {OverlayContainer} from './overlay-container';
@@ -25,7 +25,7 @@ import {ScrollStrategyOptions} from './scroll/index';
let nextUniqueId = 0;
/** The default state for newly created overlays. */
let defaultState = new OverlayState();
let defaultState = new OverlayConfig();
/**
@@ -51,7 +51,7 @@ export class Overlay {
* @param state State to apply to the overlay.
* @returns Reference to the created overlay.
*/
create(state: OverlayState = defaultState): OverlayRef {
create(state: OverlayConfig = defaultState): OverlayRef {
const pane = this._createPaneElement();
const portalHost = this._createPortalHost(pane);
return new OverlayRef(portalHost, pane, state, this._ngZone);
+1 -1
View File
@@ -40,7 +40,7 @@ export {Overlay} from './overlay';
export {OverlayContainer} from './overlay-container';
export {FullscreenOverlayContainer} from './fullscreen-overlay-container';
export {OverlayRef} from './overlay-ref';
export {OverlayState} from './overlay-state';
export {OverlayConfig} from './overlay-config';
export {ConnectedOverlayDirective, OverlayOrigin} from './overlay-directives';
export {ViewportRuler} from '@angular/cdk/scrolling';
export {ComponentType} from '@angular/cdk/portal';
@@ -3,7 +3,7 @@ import {async, inject, TestBed} from '@angular/core/testing';
import {ComponentPortal, PortalModule} from '@angular/cdk/portal';
import {Platform} from '@angular/cdk/platform';
import {ViewportRuler} from '@angular/cdk/scrolling';
import {Overlay, OverlayContainer, OverlayModule, OverlayRef, OverlayState} from '../index';
import {Overlay, OverlayContainer, OverlayModule, OverlayRef, OverlayConfig} from '../index';
describe('BlockScrollStrategy', () => {
@@ -23,9 +23,9 @@ describe('BlockScrollStrategy', () => {
}));
beforeEach(inject([Overlay, ViewportRuler], (overlay: Overlay, viewportRuler: ViewportRuler) => {
let overlayState = new OverlayState({scrollStrategy: overlay.scrollStrategies.block()});
let overlayConfig = new OverlayConfig({scrollStrategy: overlay.scrollStrategies.block()});
overlayRef = overlay.create(overlayState);
overlayRef = overlay.create(overlayConfig);
componentPortal = new ComponentPortal(FocacciaMsg);
viewport = viewportRuler;
@@ -5,7 +5,7 @@ import {ComponentPortal, PortalModule} from '@angular/cdk/portal';
import {ScrollDispatcher} from '@angular/cdk/scrolling';
import {
Overlay,
OverlayState,
OverlayConfig,
OverlayRef,
OverlayModule,
OverlayContainer,
@@ -33,8 +33,8 @@ describe('CloseScrollStrategy', () => {
}));
beforeEach(inject([Overlay], (overlay: Overlay) => {
let overlayState = new OverlayState({scrollStrategy: overlay.scrollStrategies.close()});
overlayRef = overlay.create(overlayState);
let overlayConfig = new OverlayConfig({scrollStrategy: overlay.scrollStrategies.close()});
overlayRef = overlay.create(overlayConfig);
componentPortal = new ComponentPortal(MozarellaMsg);
}));
@@ -7,7 +7,7 @@ import {
OverlayContainer,
OverlayModule,
OverlayRef,
OverlayState,
OverlayConfig,
ScrollDispatcher,
} from '../index';
@@ -33,8 +33,8 @@ describe('RepositionScrollStrategy', () => {
}));
beforeEach(inject([Overlay], (overlay: Overlay) => {
let overlayState = new OverlayState({scrollStrategy: overlay.scrollStrategies.reposition()});
overlayRef = overlay.create(overlayState);
let overlayConfig = new OverlayConfig({scrollStrategy: overlay.scrollStrategies.reposition()});
overlayRef = overlay.create(overlayConfig);
componentPortal = new ComponentPortal(PastaMsg);
}));
+5 -5
View File
@@ -7,15 +7,15 @@ recalculate the position, close the overlay, block scrolling, etc.
## Usage
To associate an overlay with a scroll strategy, you have to pass in a function, that returns a
scroll strategy, to the `OverlayState`. By default, all overlays will use the `noop` strategy which
scroll strategy, to the `OverlayConfig`. By default, all overlays will use the `noop` strategy which
doesn't do anything. The other available strategies are `reposition`, `block` and `close`:
```ts
let overlayState = new OverlayState({
let overlayConfig = new OverlayConfig({
scrollStrategy: overlay.scrollStrategies.block()
});
this._overlay.create(overlayState).attach(yourPortal);
this._overlay.create(overlayConfig).attach(yourPortal);
```
## Creating a custom scroll strategy
@@ -35,6 +35,6 @@ export class CustomScrollStrategy implements ScrollStrategy {
// your implementation
}
overlayState.scrollStrategy = new CustomScrollStrategy();
this._overlay.create(overlayState).attach(yourPortal);
overlayConfig.scrollStrategy = new CustomScrollStrategy();
this._overlay.create(overlayConfig).attach(yourPortal);
```
+6 -6
View File
@@ -1,4 +1,4 @@
import {Overlay, OverlayOrigin, OverlayState} from '@angular/cdk/overlay';
import {Overlay, OverlayOrigin, OverlayConfig} from '@angular/cdk/overlay';
import {
ComponentPortal,
// This import is only used to define a generic type. The current TypeScript version incorrectly
@@ -38,7 +38,7 @@ export class OverlayDemo {
constructor(public overlay: Overlay, public viewContainerRef: ViewContainerRef) { }
openRotiniPanel() {
let config = new OverlayState();
let config = new OverlayConfig();
config.positionStrategy = this.overlay.position()
.global()
@@ -52,7 +52,7 @@ export class OverlayDemo {
}
openFusilliPanel() {
let config = new OverlayState();
let config = new OverlayConfig();
config.positionStrategy = this.overlay.position()
.global()
@@ -73,7 +73,7 @@ export class OverlayDemo {
{originX: 'start', originY: 'bottom'},
{overlayX: 'start', overlayY: 'top'} );
let config = new OverlayState({positionStrategy: strategy});
let config = new OverlayConfig({positionStrategy: strategy});
let overlayRef = this.overlay.create(config);
overlayRef.attach(new ComponentPortal(SpagettiPanel, this.viewContainerRef));
@@ -86,14 +86,14 @@ export class OverlayDemo {
{originX: 'start', originY: 'bottom'},
{overlayX: 'end', overlayY: 'top'} );
let config = new OverlayState({positionStrategy: strategy});
let config = new OverlayConfig({positionStrategy: strategy});
let overlayRef = this.overlay.create(config);
overlayRef.attach(this.tortelliniTemplate);
}
openPanelWithBackdrop() {
let config = new OverlayState({
let config = new OverlayConfig({
hasBackdrop: true,
backdropClass: 'cdk-overlay-transparent-backdrop',
positionStrategy: this.overlay.position().global().centerHorizontally()
+3 -3
View File
@@ -12,7 +12,7 @@ import {
ConnectedPositionStrategy,
Overlay,
OverlayRef,
OverlayState,
OverlayConfig,
PositionStrategy,
RepositionScrollStrategy,
ScrollStrategy,
@@ -464,8 +464,8 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
this._panelOpen = true;
}
private _getOverlayConfig(): OverlayState {
return new OverlayState({
private _getOverlayConfig(): OverlayConfig {
return new OverlayConfig({
positionStrategy: this._getOverlayPosition(),
scrollStrategy: this._scrollStrategy(),
width: this._getHostWidth(),
+2 -2
View File
@@ -12,7 +12,7 @@ import {ESCAPE} from '@angular/cdk/keycodes';
import {
Overlay,
OverlayRef,
OverlayState,
OverlayConfig,
PositionStrategy,
RepositionScrollStrategy,
ScrollStrategy,
@@ -331,7 +331,7 @@ export class MdDatepicker<D> implements OnDestroy {
/** Create the popup. */
private _createPopup(): void {
const overlayState = new OverlayState({
const overlayState = new OverlayConfig({
positionStrategy: this._createPopupPositionStrategy(),
hasBackdrop: true,
backdropClass: 'md-overlay-transparent-backdrop',
+3 -3
View File
@@ -11,7 +11,7 @@ import {
BlockScrollStrategy,
Overlay,
OverlayRef,
OverlayState,
OverlayConfig,
ScrollStrategy,
} from '@angular/cdk/overlay';
import {ComponentPortal, ComponentType, TemplatePortal} from '@angular/cdk/portal';
@@ -181,8 +181,8 @@ export class MdDialog {
* @param dialogConfig The dialog configuration.
* @returns The overlay configuration.
*/
private _getOverlayState(dialogConfig: MdDialogConfig): OverlayState {
const state = new OverlayState({
private _getOverlayState(dialogConfig: MdDialogConfig): OverlayConfig {
const state = new OverlayConfig({
positionStrategy: this._overlay.position().global(),
scrollStrategy: this._scrollStrategy(),
panelClass: dialogConfig.panelClass,
+4 -4
View File
@@ -14,7 +14,7 @@ import {
HorizontalConnectionPos,
Overlay,
OverlayRef,
OverlayState,
OverlayConfig,
RepositionScrollStrategy,
ScrollStrategy,
VerticalConnectionPos,
@@ -317,10 +317,10 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
/**
* This method builds the configuration object needed to create the overlay, the OverlayState.
* @returns OverlayState
* @returns OverlayConfig
*/
private _getOverlayConfig(): OverlayState {
return new OverlayState({
private _getOverlayConfig(): OverlayConfig {
return new OverlayConfig({
positionStrategy: this._getPosition(),
hasBackdrop: !this.triggersSubmenu(),
backdropClass: 'cdk-overlay-transparent-backdrop',
+2 -2
View File
@@ -7,7 +7,7 @@
*/
import {ComponentRef, Injectable, Injector, Optional, SkipSelf } from '@angular/core';
import {Overlay, OverlayRef, OverlayState} from '@angular/cdk/overlay';
import {Overlay, OverlayRef, OverlayConfig} from '@angular/cdk/overlay';
import {ComponentPortal, ComponentType} from '@angular/cdk/portal';
import {LiveAnnouncer} from '@angular/cdk/a11y';
import {PortalInjector} from '@angular/material/core';
@@ -153,7 +153,7 @@ export class MdSnackBar {
* @param config The user-specified snack bar config.
*/
private _createOverlay(config: MdSnackBarConfig): OverlayRef {
const state = new OverlayState();
const state = new OverlayConfig();
state.direction = config.direction;
let positionStrategy = this._overlay.position().global();
+2 -2
View File
@@ -16,7 +16,7 @@ import {
Overlay,
OverlayConnectionPosition,
OverlayRef,
OverlayState,
OverlayConfig,
RepositionScrollStrategy,
ScrollStrategy,
} from '@angular/cdk/overlay';
@@ -309,7 +309,7 @@ export class MdTooltip implements OnDestroy {
}
});
const config = new OverlayState({
const config = new OverlayConfig({
direction: this._dir ? this._dir.value : 'ltr',
positionStrategy: strategy,
panelClass: TOOLTIP_PANEL_CLASS,