Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions src/components/toolbar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# MdToolbar
`MdToolbar` is a vertical aligned bar, which can hold the application title or actions.

### Screenshots
![Preview](https://cloud.githubusercontent.com/assets/4987015/13727769/6d952c78-e900-11e5-890a-ccfd46996812.png)

## `<md-toolbar>`
### Bound Properties

| Name | Type | Description |
| --- | --- | --- |
| `color` | `"primary" | "accent" | "warn"` | The color palette for the toolbar |

### Notes
The `md-toolbar` component will use by default the background palette.

### Examples
A basic toolbar would have the following markup.
```html
<md-toolbar [color]="myColor">
<span>My Application Title</span>
</md-toolbar>
```

Toolbars can also have multiple rows.<br/>
Multiple rows inside of a `md-toolbar` can be added by appending as many as needed `<md-toolbar-row>` elements.

```html
<md-toolbar [color]="myColor">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start off with a simple example of the toolbar with just a single row (most common case), and then say something like "The toolbar also supports multiple rows" with the second example.

<span>First Row</span>

<md-toolbar-row>
<span>Second Row</span>
</md-toolbar-row>

<md-toolbar-row>
<span>Third Row</span>
</md-toolbar-row>
</md-toolbar>
```

### Alignment
The alingment inside of a toolbar row can be easily done by using the flexbox layout.<br/>
For example, the following markup aligns the items on the `right`.

Custom HTML
```html
<md-toolbar color="primary">
<span>Application Title</span>

<!-- This fills the remaining space of the current row -->
<span class="example-fill-remaining-space"></span>

<span>Right Aligned Text</span>
</md-toolbar>
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add a screenshot immediately after this example to show the result.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would be a good idea.


Custom SCSS
```scss
.example-fill-remaining-space {
// This fills the remaining space, by using flexbox.
// Every toolbar row uses a flexbox row layout.
flex: 1 1 auto;
}
```

Output
![image](https://cloud.githubusercontent.com/assets/4987015/13730760/0864894e-e959-11e5-9312-7f3cb990d80a.png)
6 changes: 6 additions & 0 deletions src/components/toolbar/toolbar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="md-toolbar-layout">
<md-toolbar-row>
<ng-content></ng-content>
</md-toolbar-row>
<ng-content select="md-toolbar-row"></ng-content>
</div>
57 changes: 57 additions & 0 deletions src/components/toolbar/toolbar.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
@import "variables";
@import "mixins";
@import "default-theme"; //TODO: remove that soon.

$md-toolbar-min-height: 64px !default;
$md-toolbar-font-size: 20px !default;
$md-toolbar-padding: 16px !default;

@mixin toolbar-theme($palette) {
background: md-color($palette);
color: md-color($palette, default-contrast);
}

:host {
display: flex;
box-sizing: border-box;

width: 100%;
min-height: $md-toolbar-min-height;

// Font Styling
font-size: $md-toolbar-font-size;
font-weight: 400;
font-family: $md-font-family;

padding: 0 $md-toolbar-padding;

flex-direction: column;

background: md-color($md-background, app-bar);
color: md-color($md-foreground, text);

&.md-primary {
@include toolbar-theme($md-primary);
}

&.md-accent {
@include toolbar-theme($md-accent);
}

&.md-warn {
@include toolbar-theme($md-warn);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This primary/accent/warn section looks like it could possibly be refactored into a function that accepts the palette as an arg

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, a mixin would be helpful, so in the future we don't need to change every property.


md-toolbar-row {
display: flex;
box-sizing: border-box;

width: 100%;
height: $md-toolbar-min-height;

// Flexbox Vertical Alignment
flex-direction: row;
align-items: center;
}

}
64 changes: 64 additions & 0 deletions src/components/toolbar/toolbar.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {Component} from 'angular2/core';
import {
inject,
TestComponentBuilder
} from 'angular2/testing';

import {
it,
iit,
describe,
ddescribe,
expect,
beforeEach,
} from '../../core/facade/testing';
import {By} from 'angular2/platform/browser';
import {MdToolbar} from './toolbar';

export function main() {
describe('MdToolbar', () => {
let builder: TestComponentBuilder;

beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
builder = tcb;
}));

it('should apply class based on color attribute', (done: () => void) => {
return builder.createAsync(TestApp).then((fixture) => {
let testComponent = fixture.debugElement.componentInstance;
let toolbarDebugElement = fixture.debugElement.query(By.css('md-toolbar'));

testComponent.toolbarColor = 'primary';
fixture.detectChanges();

expect(toolbarDebugElement.nativeElement.classList.contains('md-primary')).toBe(true);

testComponent.toolbarColor = 'accent';
fixture.detectChanges();

expect(toolbarDebugElement.nativeElement.classList.contains('md-accent')).toBe(true);

testComponent.toolbarColor = 'warn';
fixture.detectChanges();

expect(toolbarDebugElement.nativeElement.classList.contains('md-warn')).toBe(true);

done();
});
});

});
}

@Component({
selector: 'test-app',
template: `
<md-toolbar [color]="toolbarColor">
<span>Test Toolbar</span>
</md-toolbar>
`,
directives: [MdToolbar]
})
class TestApp {
toolbarColor: string;
}
42 changes: 42 additions & 0 deletions src/components/toolbar/toolbar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
Component,
ChangeDetectionStrategy,
Input
} from 'angular2/core';
import {Renderer} from 'angular2/core';
import {ElementRef} from 'angular2/core';

@Component({
selector: 'md-toolbar',
templateUrl: './components/toolbar/toolbar.html',
styleUrls: ['./components/toolbar/toolbar.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MdToolbar {

private _color: string;

constructor(private elementRef: ElementRef, private renderer: Renderer) { }

@Input()
get color(): string {
return this._color;
}

set color(value: string) {
this._updateColor(value);
}

_updateColor(newColor: string) {
if (this._color != null && this._color != '') {
this.renderer.setElementClass(this.elementRef.nativeElement, `md-${newColor}`, false);
}

if (newColor != null && newColor != '') {
this.renderer.setElementClass(this.elementRef.nativeElement, `md-${newColor}`, true);
}

this._color = newColor;
}

}
1 change: 1 addition & 0 deletions src/demo-app/demo-app.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ <h1>Angular Material2 Demos</h1>
<li><a [routerLink]="['ProgressCircleDemo']">Progress Circle demo</a></li>
<li><a [routerLink]="['PortalDemo']">Portal demo</a></li>
<li><a [routerLink]="['CheckboxDemo']">Checkbox demo</a></li>
<li><a [routerLink]="['ToolbarDemo']">Toolbar demo</a></li>
</ul>
<button md-raised-button (click)="root.dir = (root.dir == 'rtl' ? 'ltr' : 'rtl')">
{{root.dir.toUpperCase()}}
Expand Down
4 changes: 3 additions & 1 deletion src/demo-app/demo-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {CheckboxDemo} from './checkbox/checkbox-demo';
import {Dir} from '../core/rtl/dir';
import {MdButton} from '../components/button/button';
import {PortalDemo} from './portal/portal-demo';
import {ToolbarDemo} from './toolbar/toolbar-demo';


@Component({
Expand All @@ -31,6 +32,7 @@ export class Home {}
new Route({path: '/sidenav', name: 'SidenavDemo', component: SidenavDemo}),
new Route({path: '/progress-circle', name: 'ProgressCircleDemo', component: ProgressCircleDemo}),
new Route({path: '/portal', name: 'PortalDemo', component: PortalDemo}),
new Route({path: '/checkbox', name: 'CheckboxDemo', component: CheckboxDemo})
new Route({path: '/checkbox', name: 'CheckboxDemo', component: CheckboxDemo}),
new Route({path: '/toolbar', name: 'ToolbarDemo', component: ToolbarDemo}),
])
export class DemoApp { }
68 changes: 68 additions & 0 deletions src/demo-app/toolbar/toolbar-demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<div class="demo-toolbar">

<p>
<md-toolbar>
<i class="material-icons demo-toolbar-icon">menu</i>
<span>Default Toolbar</span>

<span class="demo-fill-remaining"></span>

<i class="material-icons">code</i>
</md-toolbar>
</p>

<p>
<md-toolbar color="primary">
<i class="material-icons demo-toolbar-icon">menu</i>
<span>Primary Toolbar</span>

<span class="demo-fill-remaining"></span>

<i class="material-icons">code</i>
</md-toolbar>
</p>

<p>
<md-toolbar color="accent">
<i class="material-icons demo-toolbar-icon">menu</i>
<span>Accent Toolbar</span>

<span class="demo-fill-remaining"></span>

<i class="material-icons">code</i>
</md-toolbar>
</p>

<p>
<md-toolbar color="accent">
<span>Custom Toolbar</span>
<md-toolbar-row>
<span>Second Line</span>
</md-toolbar-row>
</md-toolbar>
</p>

<p>
<md-toolbar color="primary">
<span>Custom Toolbar</span>

<md-toolbar-row>
<span>Second Line</span>

<span class="demo-fill-remaining"></span>

<i class="material-icons demo-toolbar-icon">verified_user</i>
</md-toolbar-row>

<md-toolbar-row>
<span>Third Line</span>

<span class="demo-fill-remaining"></span>

<i class="material-icons demo-toolbar-icon">favorite</i>
<i class="material-icons demo-toolbar-icon">delete</i>
</md-toolbar-row>
</md-toolbar>
</p>

</div>
12 changes: 12 additions & 0 deletions src/demo-app/toolbar/toolbar-demo.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.demo-toolbar {
padding: 6px;

.demo-toolbar-icon {
padding: 0 14px 0 14px;
}

.demo-fill-remaining {
flex: 1 1 auto;
}

}
12 changes: 12 additions & 0 deletions src/demo-app/toolbar/toolbar-demo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {Component} from 'angular2/core';
import {MdToolbar} from '../../components/toolbar/toolbar';

@Component({
selector: 'toolbar-demo',
templateUrl: 'demo-app/toolbar/toolbar-demo.html',
styleUrls: ['demo-app/toolbar/toolbar-demo.css'],
directives: [MdToolbar]
})
export class ToolbarDemo {

}