-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(dialog): add backdrop #1041
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,51 @@ | ||
import {PortalHost, Portal} from '../portal/portal'; | ||
import {OverlayState} from './overlay-state'; | ||
import {Observable} from 'rxjs/Observable'; | ||
import {Subject} from 'rxjs/Subject'; | ||
|
||
|
||
/** | ||
* Reference to an overlay that has been created with the Overlay service. | ||
* Used to manipulate or dispose of said overlay. | ||
*/ | ||
export class OverlayRef implements PortalHost { | ||
private _backdropElement: HTMLElement = null; | ||
private _backdropClick: Subject<any> = new Subject(); | ||
|
||
constructor( | ||
private _portalHost: PortalHost, | ||
private _pane: HTMLElement, | ||
private _state: OverlayState) { } | ||
|
||
attach(portal: Portal<any>): any { | ||
if (this._state.hasBackdrop) { | ||
this._attachBackdrop(); | ||
} | ||
|
||
let attachResult = this._portalHost.attach(portal); | ||
this.updatePosition(); | ||
|
||
return attachResult; | ||
} | ||
|
||
detach(): Promise<any> { | ||
this._detatchBackdrop(); | ||
return this._portalHost.detach(); | ||
} | ||
|
||
dispose(): void { | ||
this._detatchBackdrop(); | ||
this._portalHost.dispose(); | ||
} | ||
|
||
hasAttached(): boolean { | ||
return this._portalHost.hasAttached(); | ||
} | ||
|
||
backdropClick(): Observable<void> { | ||
return this._backdropClick.asObservable(); | ||
} | ||
|
||
/** Gets the current state config of the overlay. */ | ||
getState() { | ||
return this._state; | ||
|
@@ -42,5 +58,40 @@ export class OverlayRef implements PortalHost { | |
} | ||
} | ||
|
||
// TODO(jelbourn): add additional methods for manipulating the overlay. | ||
/** Attaches a backdrop for this overlay. */ | ||
private _attachBackdrop() { | ||
this._backdropElement = document.createElement('div'); | ||
this._backdropElement.classList.add('md-overlay-backdrop'); | ||
this._pane.parentElement.appendChild(this._backdropElement); | ||
|
||
// Forward backdrop clicks that that the consumer of the overlay can perform whatever | ||
// action desired when such a click occurs (usually closing the overlay). | ||
this._backdropElement.addEventListener('click', () => { | ||
this._backdropClick.next(null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it intentionally to not pass the DOM event to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to keep any DOM stuff out of public-facing APIs for now (keeping potential running on web-workers in mind). |
||
}); | ||
|
||
// Add class to fade-in the backdrop after one frame. | ||
requestAnimationFrame(() => { | ||
this._backdropElement.classList.add('md-overlay-backdrop-showing'); | ||
}); | ||
} | ||
|
||
/** Detaches the backdrop (if any) associated with the overlay. */ | ||
private _detatchBackdrop(): void { | ||
let backdropToDetach = this._backdropElement; | ||
|
||
if (backdropToDetach) { | ||
backdropToDetach.classList.remove('md-overlay-backdrop-showing'); | ||
backdropToDetach.addEventListener('transitionend', () => { | ||
backdropToDetach.parentNode.removeChild(backdropToDetach); | ||
|
||
// It is possible that a new portal has been attached to this overlay since we started | ||
// removing the backdrop. If that is the case, only clear our the backdrop reference if it | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
// is still the same instance that we started to remove. | ||
if (this._backdropElement == backdropToDetach) { | ||
this._backdropElement = null; | ||
} | ||
}); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
@import 'variables'; | ||
@import 'palette'; | ||
|
||
$md-backdrop-color: md-color($md-grey, 900); | ||
|
||
// TODO(jelbourn): change from the `md` prefix to something else for everything in the toolkit. | ||
|
||
@import 'variables'; | ||
|
@@ -14,12 +19,35 @@ | |
left: 0; | ||
height: 100%; | ||
width: 100%; | ||
|
||
z-index: 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be a sass variable too? |
||
} | ||
|
||
/** A single overlay pane. */ | ||
.md-overlay-pane { | ||
position: absolute; | ||
pointer-events: auto; | ||
box-sizing: border-box; | ||
z-index: $z-index-overlay; | ||
z-index: $md-z-index-overlay; | ||
} | ||
|
||
.md-overlay-backdrop { | ||
position: absolute; | ||
top: 0; | ||
bottom: 0; | ||
left: 0; | ||
right: 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we use the |
||
|
||
z-index: $md-z-index-overlay-backdrop; | ||
pointer-events: auto; | ||
|
||
// TODO(jelbourn): figure out if there are actually spec'ed colors for both light and dark | ||
// themes here. Currently using the values from Angular Material 1. | ||
transition: opacity $swift-ease-out-duration $swift-ease-out-timing-function; | ||
background: $md-backdrop-color; | ||
opacity: 0; | ||
} | ||
|
||
.md-overlay-backdrop.md-overlay-backdrop-showing { | ||
opacity: 0.48; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that that
->such that