Skip to content

Commit

Permalink
fix(grid-list): hide overflow on tiles (angular#1299)
Browse files Browse the repository at this point in the history
  • Loading branch information
kara authored and josephperrott committed Sep 23, 2016
1 parent d3d9f73 commit e6cdd55
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 71 deletions.
12 changes: 7 additions & 5 deletions src/demo-app/snack-bar/snack-bar-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ <h1>SnackBar demo</h1>
<div>
<div>Message: <md-input type="text" [(ngModel)]="message"></md-input></div>
<div>
<md-checkbox [(ngModel)]="action">Show button</md-checkbox>
<md-input type="text" class="button-label-input"
placeholder="Snack bar action label"
[disabled]="!action"
[(ngModel)]="actionButtonLabel"></md-input>
<md-checkbox [(ngModel)]="action">
<p *ngIf="!action">Show button on snack bar</p>
<md-input type="text" class="button-label-input"
*ngIf="action"
placeholder="Snack bar action label"
[(ngModel)]="actionButtonLabel"></md-input>
</md-checkbox>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/demo-app/snack-bar/snack-bar-demo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Component, ViewContainerRef} from '@angular/core';
import {MdSnackBar, MdSnackBarConfig} from '@angular2-material/snack-bar';
import {MdSnackBar, MdSnackBarConfig} from '@angular/material';

@Component({
moduleId: module.id,
Expand Down
1 change: 1 addition & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export * from './select/index';
export * from './sidenav/index';
export * from './slider/index';
export * from './slide-toggle/index';
export * from './snack-bar/index';
export * from './tabs/index';
export * from './toolbar/index';
export * from './tooltip/index';
2 changes: 1 addition & 1 deletion src/lib/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {MdIconModule} from './icon/index';
import {MdProgressCircleModule} from './progress-circle/index';
import {MdProgressBarModule} from './progress-bar/index';
import {MdInputModule} from './input/index';
import {MdSnackBarModule} from '@angular2-material/snack-bar';
import {MdSnackBarModule} from './snack-bar/snack-bar';
import {MdTabsModule} from './tabs/index';
import {MdToolbarModule} from './toolbar/index';
import {MdTooltipModule} from './tooltip/index';
Expand Down
38 changes: 38 additions & 0 deletions src/lib/snack-bar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# MdSnackBar
`MdSnackBar` is a service, which opens snack bar notifications in the view.

### Methods

| Name | Description |
| --- | --- |
| `open(message: string,<br> actionLabel: string, config: MdSnackBarConfig): MdSnackBarRef<SimpleSnackBar>` | Creates and opens a simple snack bar noticiation matching material spec. |
| `openFromComponent(component: ComponentType<T>, config: MdSnackBarConfig): MdSnackBarRef<T>` | Creates and opens a snack bar noticiation with a custom component as content. |

### Config

| Key | Description |
| --- | --- |
| `viewContainerRef: ViewContainerRef` | The view container ref to attach the snack bar to. |
| `role: AriaLivePoliteness = 'assertive'` | The politeness level to announce the snack bar with. |
| `announcementMessage: string` | The message to announce with the snack bar. |


### Example
The service can be injected in a component.
```ts
@Component({
selector: 'my-component'
providers: [MdSnackBar]
})
export class MyComponent {

constructor(snackBar: MdSnackBar
viewContainerRef: ViewContainerRef) {}

failedAttempt() {
config = new MdSnackBarConfig(this.viewContainerRef);
this.snackBar.open('It didn\'t quite work!', 'Try Again', config);
}

}
```
12 changes: 0 additions & 12 deletions src/lib/snack-bar/base-snack-bar.ts

This file was deleted.

29 changes: 0 additions & 29 deletions src/lib/snack-bar/package.json

This file was deleted.

4 changes: 2 additions & 2 deletions src/lib/snack-bar/simple-snack-bar.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
md-simple-snackbar {
display: flex;
justify-content: space-between;
display: flex;
justify-content: space-between;
}

.md-simple-snackbar-message {
Expand Down
16 changes: 14 additions & 2 deletions src/lib/snack-bar/simple-snack-bar.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
import {Component} from '@angular/core';
import {BaseSnackBarContent} from './base-snack-bar';
import {MdSnackBarRef} from './snack-bar-ref';


/**
* A component used to open as the default snack bar, matching material spec.
* This should only be used internally by the snack bar service.
*/
@Component({
moduleId: module.id,
selector: 'simple-snack-bar',
templateUrl: 'simple-snack-bar.html',
styleUrls: ['simple-snack-bar.css'],
})
export class SimpleSnackBar extends BaseSnackBarContent<SimpleSnackBar> {
export class SimpleSnackBar {
/** The message to be shown in the snack bar. */
message: string;

/** The label for the button in the snack bar. */
action: string;

/** The instance of the component making up the content of the snack bar. */
snackBarRef: MdSnackBarRef<SimpleSnackBar>;

/** Dismisses the snack bar. */
dismiss(): void {
this.snackBarRef.dismiss();
}

/** If the action button should be shown. */
get hasAction(): boolean { return !!this.action; }
}
10 changes: 6 additions & 4 deletions src/lib/snack-bar/snack-bar-config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {ViewContainerRef} from '@angular/core';
import {AriaLivePoliteness} from '../core';


export type SnackBarRole = 'alert' | 'polite';

export class MdSnackBarConfig {
/** The aria-role of the snack bar. */
role: SnackBarRole = 'alert';
/** The politeness level for the MdAriaLiveAnnouncer announcement. */
politeness: AriaLivePoliteness = 'assertive';

/** Message to be announced by the MdAriaLiveAnnouncer */
announcementMessage: string;

/** The view container to place the overlay for the snack bar into. */
viewContainerRef: ViewContainerRef;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/snack-bar/snack-bar-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ComponentPortal,
TemplatePortal,
PortalHostDirective
} from '@angular2-material/core';
} from '../core';
import {MdSnackBarConfig} from './snack-bar-config';
import {MdSnackBarContentAlreadyAttached} from './snack-bar-errors';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/snack-bar/snack-bar-errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {MdError} from '@angular2-material/core';
import {MdError} from '../core';


export class MdSnackBarContentAlreadyAttached extends MdError {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/snack-bar/snack-bar-ref.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {OverlayRef} from '@angular2-material/core';
import {OverlayRef} from '../core';
import {Observable} from 'rxjs/Observable';
import {Subject} from 'rxjs/Subject';

Expand All @@ -10,15 +10,15 @@ import {Subject} from 'rxjs/Subject';
*/
export class MdSnackBarRef<T> {
/** The instance of the component making up the content of the snack bar. */
readonly instance: T|any;
readonly instance: T;

/** Subject for notifying the user that the snack bar has closed. */
private _afterClosed: Subject<any> = new Subject();

/** If the snack bar is active. */
private _isActive: boolean = true;

constructor(instance: T|any, private _overlayRef: OverlayRef) {
constructor(instance: T, private _overlayRef: OverlayRef) {
// Sets the readonly instance of the snack bar content component.
this.instance = instance;
this.afterDismissed().subscribe(null, null, () => { this._isActive = false; });
Expand Down
22 changes: 13 additions & 9 deletions src/lib/snack-bar/snack-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import {
ComponentRef,
} from '@angular/core';
import {
Overlay,
OverlayState,
OverlayRef,
ComponentType,
ComponentPortal,
Overlay,
OverlayModule,
OverlayRef,
OverlayState,
PortalModule,
OVERLAY_PROVIDERS,
} from '@angular2-material/core';
MdLiveAnnouncer,
} from '../core';
import {CommonModule} from '@angular/common';
import {MdSnackBarConfig} from './snack-bar-config';
import {MdSnackBarRef} from './snack-bar-ref';
Expand All @@ -35,7 +36,8 @@ export class MdSnackBar {
/** A reference to the current snack bar in the view. */
private _snackBarRef: MdSnackBarRef<any>;

constructor(private _overlay: Overlay) {}
constructor(private _overlay: Overlay,
private _live: MdLiveAnnouncer) {}

/**
* Creates and dispatches a snack bar with a custom component for the content, removing any
Expand All @@ -48,8 +50,9 @@ export class MdSnackBar {
}
let overlayRef = this._createOverlay();
let snackBarContainer = this._attachSnackBarContainer(overlayRef, config);

return this._attachSnackbarContent(component, snackBarContainer, overlayRef);
let mdSnackBarRef = this._attachSnackbarContent(component, snackBarContainer, overlayRef);
this._live.announce(config.announcementMessage, config.politeness);
return mdSnackBarRef;
}


Expand All @@ -58,7 +61,9 @@ export class MdSnackBar {
*/
open(message: string, actionLabel: string,
config: MdSnackBarConfig): MdSnackBarRef<SimpleSnackBar> {
config.announcementMessage = message;
let simpleSnackBarRef = this.openFromComponent(SimpleSnackBar, config);
simpleSnackBarRef.instance.snackBarRef = simpleSnackBarRef;
simpleSnackBarRef.instance.message = message;
simpleSnackBarRef.instance.action = actionLabel;
return simpleSnackBarRef;
Expand Down Expand Up @@ -87,7 +92,6 @@ export class MdSnackBar {
let portal = new ComponentPortal(component);
let contentRef = container.attachComponentPortal(portal);
let snackBarRef = <MdSnackBarRef<T>> new MdSnackBarRef(contentRef.instance, overlayRef);
snackBarRef.instance.snackBarRef = snackBarRef;

this._snackBarRef = snackBarRef;
return snackBarRef;
Expand Down Expand Up @@ -118,7 +122,7 @@ export class MdSnackBarModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: MdSnackBarModule,
providers: [MdSnackBar, OVERLAY_PROVIDERS]
providers: [MdSnackBar, OVERLAY_PROVIDERS, MdLiveAnnouncer]
};
}
}
2 changes: 1 addition & 1 deletion src/lib/system-config-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ System.config({
defaultExtension: 'js'
}
}
});
});

0 comments on commit e6cdd55

Please sign in to comment.