-
Couldn't load subscription status.
- Fork 6.8k
feat(): add toolbar component #146
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
Changes from all 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 |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # MdToolbar | ||
| `MdToolbar` is a vertical aligned bar, which can hold the application title or actions. | ||
|
|
||
| ### Screenshots | ||
|  | ||
|
|
||
| ## `<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"> | ||
| <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> | ||
| ``` | ||
|
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. It would be good to add a screenshot immediately after this example to show the result. 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. 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 | ||
|  | ||
| 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> |
| 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); | ||
| } | ||
|
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. This primary/accent/warn section looks like it could possibly be refactored into a function that accepts the palette as an arg 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. 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; | ||
| } | ||
|
|
||
| } | ||
| 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; | ||
| } |
| 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; | ||
| } | ||
|
|
||
| } |
| 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> |
| 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; | ||
| } | ||
|
|
||
| } |
| 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 { | ||
|
|
||
| } |
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.
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.