-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(snack-bar): initial commit for snack-bar (#64)
- Loading branch information
Showing
27 changed files
with
382 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/app/docs/components/snack-bar-demo/basic-snack-bar/basic-snack-bar.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<button ly-button (click)="sb.open()">Show snack-bar</button> | ||
|
||
<ng-template ly-snack-bar #sb="lySnackBar" (afterDismissed)="afterDismissed($event)"> | ||
<span>Message</span> | ||
<button ly-button color="accent" (click)="sb.dismiss()"> | ||
Dismiss | ||
</button> | ||
</ng-template> |
25 changes: 25 additions & 0 deletions
25
src/app/docs/components/snack-bar-demo/basic-snack-bar/basic-snack-bar.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { BasicSnackBarComponent } from './basic-snack-bar.component'; | ||
|
||
describe('BasicSnackBarComponent', () => { | ||
let component: BasicSnackBarComponent; | ||
let fixture: ComponentFixture<BasicSnackBarComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ BasicSnackBarComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(BasicSnackBarComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
src/app/docs/components/snack-bar-demo/basic-snack-bar/basic-snack-bar.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Component } from '@angular/core'; | ||
import { LySnackBarDismiss } from 'lib/snack-bar/snack-bar'; | ||
|
||
@Component({ | ||
selector: 'aui-basic-snack-bar', | ||
templateUrl: './basic-snack-bar.component.html' | ||
}) | ||
export class BasicSnackBarComponent { | ||
afterDismissed(e: LySnackBarDismiss) { | ||
console.log(e); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/app/docs/components/snack-bar-demo/basic-snack-bar/basic-snack-bar.module.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { BasicSnackBarModule } from './basic-snack-bar.module'; | ||
|
||
describe('BasicSnackBarModule', () => { | ||
let basicSnackBarModule: BasicSnackBarModule; | ||
|
||
beforeEach(() => { | ||
basicSnackBarModule = new BasicSnackBarModule(); | ||
}); | ||
|
||
it('should create an instance', () => { | ||
expect(basicSnackBarModule).toBeTruthy(); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
src/app/docs/components/snack-bar-demo/basic-snack-bar/basic-snack-bar.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { BasicSnackBarComponent } from './basic-snack-bar.component'; | ||
import { LyButtonModule } from '@alyle/ui/button'; | ||
import { LySnackBarModule } from '@alyle/ui/snack-bar'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
LyButtonModule, | ||
LySnackBarModule | ||
], | ||
exports: [BasicSnackBarComponent], | ||
declarations: [BasicSnackBarComponent] | ||
}) | ||
export class BasicSnackBarModule { } |
7 changes: 7 additions & 0 deletions
7
src/app/docs/components/snack-bar-demo/snack-bar-demo.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<p> | ||
Snackbars provide brief messages at the bottom of the screen. | ||
</p> | ||
<h2 [lyTyp]="'display1'" gutter>Basic SnackBar</h2> | ||
<demo-view path="docs/components/snack-bar-demo/basic-snack-bar"> | ||
<aui-basic-snack-bar></aui-basic-snack-bar> | ||
</demo-view> |
25 changes: 25 additions & 0 deletions
25
src/app/docs/components/snack-bar-demo/snack-bar-demo.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { SnackBarDemoComponent } from './snack-bar-demo.component'; | ||
|
||
describe('SnackBarDemoComponent', () => { | ||
let component: SnackBarDemoComponent; | ||
let fixture: ComponentFixture<SnackBarDemoComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ SnackBarDemoComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(SnackBarDemoComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
src/app/docs/components/snack-bar-demo/snack-bar-demo.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'aui-snack-bar-demo', | ||
templateUrl: './snack-bar-demo.component.html' | ||
}) | ||
export class SnackBarDemoComponent implements OnInit { | ||
|
||
constructor() { } | ||
|
||
ngOnInit() { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './public_api'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './snack-bar.module'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { EventEmitter } from '@angular/core'; | ||
import { Subject, Observable } from 'rxjs'; | ||
import { OverlayFromTemplateRef, LyTheme2 } from '@alyle/ui'; | ||
import { LySnackBarService } from './snack-bar.service'; | ||
import { LySnackBarDismiss } from './snack-bar'; | ||
|
||
const DEFAULT_DURATION = 6e3; | ||
/** @ignore */ | ||
const STYLE_PRIORITY = -2; | ||
|
||
export class LySnackBarRef { | ||
private _timer: any; | ||
private _dismissedByAction = false; | ||
|
||
/** Subject for notifying the user that the snack bar has been dismissed. */ | ||
private readonly _afterDismissed = new Subject<void>(); | ||
|
||
/** Gets an observable that is notified when the snack bar is finished closing. */ | ||
afterDismissed(): Observable<void> { | ||
return this._afterDismissed.asObservable(); | ||
} | ||
constructor( | ||
private _snackBarService: LySnackBarService, | ||
private _overlay: OverlayFromTemplateRef, | ||
private _afterDismissedEventEmitter: EventEmitter<LySnackBarDismiss>, | ||
duration: number, | ||
private _theme: LyTheme2 | ||
) { | ||
this._timer = setTimeout(() => { | ||
this.dismiss(); | ||
}, duration || DEFAULT_DURATION); | ||
} | ||
|
||
dismiss() { | ||
const snackBar = this._overlay; | ||
const timer = this._timer; | ||
this._afterDismissedEventEmitter.emit({dismissedByAction: this._dismissedByAction}); | ||
this._afterDismissed.next(); | ||
this._afterDismissed.complete(); | ||
if (snackBar) { | ||
if (timer) { | ||
// clear previous timer | ||
clearTimeout(timer); | ||
} | ||
this._theme.addStyle('SnackBar:close', ({ | ||
opacity: 0 | ||
}), snackBar.containerElement, undefined, STYLE_PRIORITY); | ||
setTimeout(() => { | ||
snackBar.destroy(); | ||
}, 350); | ||
this._snackBarService._currentSnackBar = null; | ||
this._overlay = null; | ||
} | ||
} | ||
dismissWithAction() { | ||
const snackBar = this._overlay; | ||
if (snackBar) { | ||
this._dismissedByAction = true; | ||
this.dismiss(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { LyOverlayModule } from '@alyle/ui'; | ||
import { LySnackBar } from './snack-bar'; | ||
|
||
@NgModule({ | ||
imports: [LyOverlayModule], | ||
declarations: [LySnackBar], | ||
exports: [LySnackBar] | ||
}) | ||
export class LySnackBarModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { LySnackBarRef } from './snack-bar-ref'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class LySnackBarService { | ||
_currentSnackBar: LySnackBarRef; | ||
} |
Oops, something went wrong.