Skip to content

Commit

Permalink
wip: start bringing in the first component
Browse files Browse the repository at this point in the history
setup Angular Material properly since ng add failed
build errors due to angular/flex-layout#851
  • Loading branch information
Splaktar committed Oct 8, 2018
1 parent 2a07bb5 commit 83a0bd4
Show file tree
Hide file tree
Showing 21 changed files with 260 additions and 94 deletions.
5 changes: 5 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@
"sourceRoot": "projects/dev/src",
"projectType": "library",
"prefix": "dev",
"schematics": {
"@schematics/angular:component": {
"styleext": "scss"
}
},
"architect": {
"build": {
"builder": "@angular-devkit/build-ng-packagr:build",
Expand Down
10 changes: 7 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
"@angular/common": "~7.0.0-rc.0",
"@angular/compiler": "~7.0.0-rc.0",
"@angular/core": "~7.0.0-rc.0",
"@angular/flex-layout": "^6.0.0-beta.18",
"@angular/flex-layout": "github:angular/flex-layout-builds",
"@angular/forms": "~7.0.0-rc.0",
"@angular/http": "~7.0.0-rc.0",
"@angular/material": "^7.0.0-rc.0",
"@angular/platform-browser": "~7.0.0-rc.0",
"@angular/platform-browser-dynamic": "~7.0.0-rc.0",
"@angular/router": "~7.0.0-rc.0",
"core-js": "^2.5.4",
"hammerjs": "^2.0.8",
"rxjs": "~6.3.3",
"zone.js": "~0.8.26"
},
Expand Down
29 changes: 29 additions & 0 deletions projects/dev/src/lib/button-bar/button-bar.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<mat-toolbar class="mat-elevation-z1">
<button mat-button
*ngFor="let button of namedButtons"
[routerLink]="button.path"
routerLinkActive #rla="routerLinkActive"
[ngClass]="{'active': rla.isActive}">
{{button.label}}
</button>
<button mat-icon-button
*ngFor="let button of iconButtons"
[routerLink]="button.path"
routerLinkActive #rla="routerLinkActive"
[ngClass]="{'active': rla.isActive}" [matTooltip]="button.label">
<mat-icon>{{button.iconName}}</mat-icon>
</button>
<span fxFlex></span>
<button mat-icon-button [matMenuTriggerFor]="overflowMenu" class="overflowMenu"
*ngIf="overflowMenuItems.length">
<mat-icon>more_vert</mat-icon>
</button>
<mat-menu #overflowMenu="matMenu" [overlapTrigger]="false">
<button mat-menu-item color="primary"
*ngFor="let item of overflowMenuItems"
[routerLink]="item.path">
<mat-icon>{{item.iconName}}</mat-icon>
<span>{{item.label}}</span>
</button>
</mat-menu>
</mat-toolbar>
25 changes: 25 additions & 0 deletions projects/dev/src/lib/button-bar/button-bar.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@import '~@angular/material/theming';

// TODO support theming of components
.mat-toolbar {
padding-top: 2px;

button {
opacity: 0.6;
text-transform: uppercase;

&:hover,
&:focus {
background-color: map-get($mat-indigo, 50);
}

&.active {
color: map-get($mat-indigo, 500);
opacity: 1;
}

&.mat-icon-button {
margin-right: 8px;
}
}
}
25 changes: 25 additions & 0 deletions projects/dev/src/lib/button-bar/button-bar.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { ButtonBarComponent } from './button-bar.component';

describe('ButtonBarComponent', () => {
let component: ButtonBarComponent;
let fixture: ComponentFixture<ButtonBarComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ButtonBarComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(ButtonBarComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
54 changes: 54 additions & 0 deletions projects/dev/src/lib/button-bar/button-bar.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {Component, OnInit, OnDestroy, Input} from '@angular/core';
import {MediaChange, ObservableMedia} from '@angular/flex-layout';
import {NavItem} from '../nav-item';
import {Subscription} from 'rxjs';

@Component({
selector: 'dev-button-bar',
templateUrl: './button-bar.component.html',
styleUrls: ['./button-bar.component.scss']
})
export class ButtonBarComponent implements OnInit, OnDestroy {
@Input() navItems: NavItem[];
watcher: Subscription;
namedButtons: NavItem[] = [];
iconButtons: NavItem[] = [];
overflowMenuItems: NavItem[] = [];

constructor(public mediaService: ObservableMedia) {}

ngOnInit() {
this.watcher = this.mediaService.subscribe((change: MediaChange) => {
this.onMediaChange();
});
}

ngOnDestroy() {
if (this.watcher) {
this.watcher.unsubscribe();
}
}

onMediaChange() {
const items = this.navItems.slice();
this.namedButtons = [];
this.iconButtons = [];
this.overflowMenuItems = [];

if (this.mediaService.isActive('xs')) {
this.iconButtons = this.iconButtons.concat(items.splice(0, 5));
} else if (this.mediaService.isActive('sm')) {
this.namedButtons = this.namedButtons.concat(items.splice(0, 6));
} else if (this.mediaService.isActive('md')) {
this.namedButtons = this.namedButtons.concat(items.splice(0, 8));
} else if (this.mediaService.isActive('lg')) {
this.namedButtons = this.namedButtons.concat(items.splice(0, 12));
} else if (this.mediaService.isActive('xl')) {
this.namedButtons = this.namedButtons.concat(items.splice(0, 16));
}

if (items.length > 0) {
this.overflowMenuItems = items;
}
}
}
25 changes: 0 additions & 25 deletions projects/dev/src/lib/dev.component.spec.ts

This file was deleted.

20 changes: 0 additions & 20 deletions projects/dev/src/lib/dev.component.ts

This file was deleted.

10 changes: 0 additions & 10 deletions projects/dev/src/lib/dev.module.ts

This file was deleted.

12 changes: 0 additions & 12 deletions projects/dev/src/lib/dev.service.spec.ts

This file was deleted.

10 changes: 0 additions & 10 deletions projects/dev/src/lib/dev.service.ts

This file was deleted.

35 changes: 35 additions & 0 deletions projects/dev/src/lib/devintent.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import {FlexLayoutModule} from '@angular/flex-layout';
import {MatButtonModule, MatIconModule, MatMenuModule, MatToolbarModule, MatTooltipModule} from '@angular/material';
import {RouterModule} from '@angular/router';
import {ButtonBarComponent} from './button-bar/button-bar.component';

@NgModule({
imports: [
CommonModule,
MatIconModule,
MatMenuModule,
MatButtonModule,
MatToolbarModule,
MatTooltipModule,
FlexLayoutModule,
RouterModule
],
declarations: [
ButtonBarComponent
],
exports: [
ButtonBarComponent,
CommonModule,
MatIconModule,
MatMenuModule,
MatButtonModule,
MatToolbarModule,
MatTooltipModule,
FlexLayoutModule,
RouterModule
]
})
export class DevintentModule {
}
5 changes: 5 additions & 0 deletions projects/dev/src/lib/nav-item.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface NavItem {
label: string;
path: string;
iconName: string;
}
11 changes: 5 additions & 6 deletions projects/dev/src/public_api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
* Public API Surface of dev
/**
* Public API Surface of Library
*/

export * from './lib/dev.service';
export * from './lib/dev.component';
export * from './lib/dev.module';
export * from './lib/devintent.module';
export * from './lib/button-bar/button-bar.component';
export * from './lib/nav-item';
2 changes: 1 addition & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<dev-dev></dev-dev>
<dev-button-bar [navItems]="navItems"></dev-button-bar>
20 changes: 19 additions & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
import {Component} from '@angular/core';
import {NavItem} from '../../projects/dev/src/lib/nav-item';

@Component({
selector: 'dev-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'dev-demo';
navItems: NavItem[];

constructor() {
this.navItems = [
{label: 'Hot Tub', path: 'first', iconName: 'hot_tub'},
{label: 'Beach', path: 'second', iconName: 'beach_access'},
{label: 'Gym', path: 'third', iconName: 'fitness_center'},
{label: 'Children', path: 'fake', iconName: 'child_friendly'},
{label: 'Child Care', path: 'fake', iconName: 'child_care'},
{label: 'Golf', path: 'fake', iconName: 'golf_course'},
{label: 'Spa', path: 'fake', iconName: 'spa'},
{label: 'Pool', path: 'fake', iconName: 'pool'},
{label: 'Service', path: 'fake', iconName: 'room_service'},
{label: 'Casino', path: 'fake', iconName: 'casino'},
{label: 'Business', path: 'fake', iconName: 'business_center'},
{label: 'Coffee', path: 'fake', iconName: 'free_breakfast'}
];
}
}
14 changes: 10 additions & 4 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import {NgModule} from '@angular/core';
import {FlexLayoutModule} from '@angular/flex-layout';
import {ReactiveFormsModule} from '@angular/forms';
import {BrowserModule} from '@angular/platform-browser';
import {DevComponent} from '../../projects/dev/src/lib/dev.component';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {DevintentModule} from '../../projects/dev/src/lib/devintent.module';

import {AppComponent} from './app.component';

@NgModule({
declarations: [
AppComponent,
DevComponent
AppComponent
],
imports: [
BrowserModule
BrowserModule,
BrowserAnimationsModule,
FlexLayoutModule,
ReactiveFormsModule,
DevintentModule
],
providers: [],
bootstrap: [AppComponent]
Expand Down
Loading

0 comments on commit 83a0bd4

Please sign in to comment.