Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.

Commit 83a0bd4

Browse files
committed
wip: start bringing in the first component
setup Angular Material properly since ng add failed build errors due to angular/flex-layout#851
1 parent 2a07bb5 commit 83a0bd4

21 files changed

+260
-94
lines changed

angular.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@
139139
"sourceRoot": "projects/dev/src",
140140
"projectType": "library",
141141
"prefix": "dev",
142+
"schematics": {
143+
"@schematics/angular:component": {
144+
"styleext": "scss"
145+
}
146+
},
142147
"architect": {
143148
"build": {
144149
"builder": "@angular-devkit/build-ng-packagr:build",

package-lock.json

Lines changed: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121
"@angular/common": "~7.0.0-rc.0",
2222
"@angular/compiler": "~7.0.0-rc.0",
2323
"@angular/core": "~7.0.0-rc.0",
24-
"@angular/flex-layout": "^6.0.0-beta.18",
24+
"@angular/flex-layout": "github:angular/flex-layout-builds",
2525
"@angular/forms": "~7.0.0-rc.0",
2626
"@angular/http": "~7.0.0-rc.0",
2727
"@angular/material": "^7.0.0-rc.0",
2828
"@angular/platform-browser": "~7.0.0-rc.0",
2929
"@angular/platform-browser-dynamic": "~7.0.0-rc.0",
3030
"@angular/router": "~7.0.0-rc.0",
3131
"core-js": "^2.5.4",
32+
"hammerjs": "^2.0.8",
3233
"rxjs": "~6.3.3",
3334
"zone.js": "~0.8.26"
3435
},
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<mat-toolbar class="mat-elevation-z1">
2+
<button mat-button
3+
*ngFor="let button of namedButtons"
4+
[routerLink]="button.path"
5+
routerLinkActive #rla="routerLinkActive"
6+
[ngClass]="{'active': rla.isActive}">
7+
{{button.label}}
8+
</button>
9+
<button mat-icon-button
10+
*ngFor="let button of iconButtons"
11+
[routerLink]="button.path"
12+
routerLinkActive #rla="routerLinkActive"
13+
[ngClass]="{'active': rla.isActive}" [matTooltip]="button.label">
14+
<mat-icon>{{button.iconName}}</mat-icon>
15+
</button>
16+
<span fxFlex></span>
17+
<button mat-icon-button [matMenuTriggerFor]="overflowMenu" class="overflowMenu"
18+
*ngIf="overflowMenuItems.length">
19+
<mat-icon>more_vert</mat-icon>
20+
</button>
21+
<mat-menu #overflowMenu="matMenu" [overlapTrigger]="false">
22+
<button mat-menu-item color="primary"
23+
*ngFor="let item of overflowMenuItems"
24+
[routerLink]="item.path">
25+
<mat-icon>{{item.iconName}}</mat-icon>
26+
<span>{{item.label}}</span>
27+
</button>
28+
</mat-menu>
29+
</mat-toolbar>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@import '~@angular/material/theming';
2+
3+
// TODO support theming of components
4+
.mat-toolbar {
5+
padding-top: 2px;
6+
7+
button {
8+
opacity: 0.6;
9+
text-transform: uppercase;
10+
11+
&:hover,
12+
&:focus {
13+
background-color: map-get($mat-indigo, 50);
14+
}
15+
16+
&.active {
17+
color: map-get($mat-indigo, 500);
18+
opacity: 1;
19+
}
20+
21+
&.mat-icon-button {
22+
margin-right: 8px;
23+
}
24+
}
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { ButtonBarComponent } from './button-bar.component';
4+
5+
describe('ButtonBarComponent', () => {
6+
let component: ButtonBarComponent;
7+
let fixture: ComponentFixture<ButtonBarComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ ButtonBarComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(ButtonBarComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import {Component, OnInit, OnDestroy, Input} from '@angular/core';
2+
import {MediaChange, ObservableMedia} from '@angular/flex-layout';
3+
import {NavItem} from '../nav-item';
4+
import {Subscription} from 'rxjs';
5+
6+
@Component({
7+
selector: 'dev-button-bar',
8+
templateUrl: './button-bar.component.html',
9+
styleUrls: ['./button-bar.component.scss']
10+
})
11+
export class ButtonBarComponent implements OnInit, OnDestroy {
12+
@Input() navItems: NavItem[];
13+
watcher: Subscription;
14+
namedButtons: NavItem[] = [];
15+
iconButtons: NavItem[] = [];
16+
overflowMenuItems: NavItem[] = [];
17+
18+
constructor(public mediaService: ObservableMedia) {}
19+
20+
ngOnInit() {
21+
this.watcher = this.mediaService.subscribe((change: MediaChange) => {
22+
this.onMediaChange();
23+
});
24+
}
25+
26+
ngOnDestroy() {
27+
if (this.watcher) {
28+
this.watcher.unsubscribe();
29+
}
30+
}
31+
32+
onMediaChange() {
33+
const items = this.navItems.slice();
34+
this.namedButtons = [];
35+
this.iconButtons = [];
36+
this.overflowMenuItems = [];
37+
38+
if (this.mediaService.isActive('xs')) {
39+
this.iconButtons = this.iconButtons.concat(items.splice(0, 5));
40+
} else if (this.mediaService.isActive('sm')) {
41+
this.namedButtons = this.namedButtons.concat(items.splice(0, 6));
42+
} else if (this.mediaService.isActive('md')) {
43+
this.namedButtons = this.namedButtons.concat(items.splice(0, 8));
44+
} else if (this.mediaService.isActive('lg')) {
45+
this.namedButtons = this.namedButtons.concat(items.splice(0, 12));
46+
} else if (this.mediaService.isActive('xl')) {
47+
this.namedButtons = this.namedButtons.concat(items.splice(0, 16));
48+
}
49+
50+
if (items.length > 0) {
51+
this.overflowMenuItems = items;
52+
}
53+
}
54+
}

projects/dev/src/lib/dev.component.spec.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

projects/dev/src/lib/dev.component.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

projects/dev/src/lib/dev.module.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)