Skip to content
This repository has been archived by the owner on Oct 7, 2020. It is now read-only.

Commit

Permalink
refactor: Library improvements + refactoring (#329)
Browse files Browse the repository at this point in the history
Closes #328
  • Loading branch information
trimox authored Oct 30, 2017
1 parent 8dd1470 commit d7f516c
Show file tree
Hide file tree
Showing 111 changed files with 1,256 additions and 1,387 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"lint": "npm run lint:ts && npm run lint:css",
"lint:ts": "tslint 'src/**/*.ts test/**/*.ts'",
"lint:css": "stylelint src/**/*.scss --config .stylelint-config.yaml",
"fix:css": "stylelint --fix src/**/*.scss --config .stylelint-config.yaml",
"test": "npm run test:unit",
"test:unit": "karma start --single-run",
"test:watch": "karma start --auto-watch",
Expand Down
5 changes: 3 additions & 2 deletions src/demo-app/components/buttons/fab-demo/fab-demo.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Component, ViewChild } from '@angular/core';

import { MdcFabComponent } from '../../../../lib/public_api';
// import { MdcFab } from '@angular-mdc/web';
import { MdcFab } from '../../../../lib/public_api';

@Component({
selector: 'fab-demo',
templateUrl: './fab-demo.html'
})
export class FabDemo {
@ViewChild('fab') fab: MdcFabComponent;
@ViewChild('fab') fab: MdcFab;
isMini: boolean = false;
isExited: boolean = false;
isRippleDisabled: boolean = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { Component } from '@angular/core';
})
export class IconToggleDemo {
isOn: boolean = false;
isDisabled: boolean;
isPrimary: boolean;
isAccent: boolean;
isDarkTheme: boolean;
isDisabled: boolean = false;
isPrimary: boolean = false;
isAccent: boolean = false;
isDarkTheme: boolean = false;
}
13 changes: 7 additions & 6 deletions src/demo-app/components/dialog-demo/dialog-demo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Component, ViewChild } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';

import { MdcDialogComponent, MdcTextfield } from '../../../lib/public_api';
// import { MdcDialog, MdcTextfield } from '@angular-mdc/web';
import { MdcDialog, MdcTextfield } from '../../../lib/public_api';

@Component({
selector: 'dialog-demo',
Expand All @@ -11,11 +12,11 @@ export class DialogDemo {
userForm: FormGroup;

@ViewChild('input') input: MdcTextfield;
@ViewChild('dialog') dialog: MdcDialogComponent;
@ViewChild('dialogscroll') dialogScroll: MdcDialogComponent;
@ViewChild('dialogalert') dialogAlert: MdcDialogComponent;
@ViewChild('dialoggmail') dialogGmail: MdcDialogComponent;
@ViewChild('dialogform') dialogForm: MdcDialogComponent;
@ViewChild('dialog') dialog: MdcDialog;
@ViewChild('dialogscroll') dialogScroll: MdcDialog;
@ViewChild('dialogalert') dialogAlert: MdcDialog;
@ViewChild('dialoggmail') dialogGmail: MdcDialog;
@ViewChild('dialogform') dialogForm: MdcDialog;

ngOnInit() {
this.userForm = new FormGroup({
Expand Down
287 changes: 146 additions & 141 deletions src/demo-app/components/drawer-demo/drawer-demo.html

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions src/demo-app/components/drawer-demo/drawer-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ import {
ViewChild
} from '@angular/core';

import {
MdcTemporaryDrawerComponent,
MdcPersistentDrawerComponent
} from '../../../lib/public_api';
// import { MdcTemporaryDrawer, MdcPersistentDrawer } from '@angular-mdc/web';
import { MdcTemporaryDrawer, MdcPersistentDrawer } from '../../../lib/public_api';

@Component({
selector: 'drawer-demo',
templateUrl: './drawer-demo.html'
})
export class DrawerDemo {
@ViewChild('temporary') temporaryDrawer: MdcTemporaryDrawerComponent;
@ViewChild('persistent') persistentDrawer: MdcPersistentDrawerComponent;
@ViewChild('temporary') temporaryDrawer: MdcTemporaryDrawer;
@ViewChild('persistent') persistentDrawer: MdcPersistentDrawer;

handleTemporary() {
this.temporaryDrawer.open();
Expand Down
1 change: 0 additions & 1 deletion src/demo-app/components/snackbar-demo/snackbar-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ <h1 mdc-typography-display1>Snackbar</h1>
@Component({
selector: 'snackbar-demo',
templateUrl: './snackbar-demo.component.html',
providers: [MdcSnackbar],
})
export class SnackbarDemoComponent {
message = 'Message deleted';
Expand Down
2 changes: 1 addition & 1 deletion src/demo-app/components/snackbar-demo/snackbar-demo.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Component } from '@angular/core';

// import { MdcSnackbar } from '@angular-mdc/web';
import { MdcSnackbar } from '../../../lib/public_api';

@Component({
selector: 'snackbar-demo',
templateUrl: './snackbar-demo.html',
providers: [MdcSnackbar],
})
export class SnackbarDemo {
message = 'Message deleted';
Expand Down
43 changes: 7 additions & 36 deletions src/demo-app/docs/getting-started.html
Original file line number Diff line number Diff line change
@@ -1,43 +1,16 @@
<div class="mdc-padding">
<h1 id="angularmdcgettingstarted">Angular MDC - Getting started</h1>

<ul>
<li><a href="#step1">Step 1 - Install Angular MDC</a></li>

<li><a href="#step2">Step 2 - Import Components</a></li>

<li><a href="#step3">Step 3 - Import Theme</a></li>

<li><a href="#step4">Step 4 - Include Material Design Icons</a></li>

<li><a href="#step5">Step 5 - Include Roboto Font</a></li>
</ul>

<h2 id="usingangularcli">Using Angular CLI?</h2>

<p>If you intend to use Angular CLI, please reference <a href="https://github.com/trimox/angular-mdc-web/blob/master/docs/guide-angular-cli.md">Angular CLI - Getting Started guide</a>.</p>

<h2 id="anamestep1astep1installangularmdc"><a name="step1"></a> Step 1: Install Angular MDC</h2>

<pre><code>npm i @angular-mdc/web
</code></pre>
<pre>npm i @angular-mdc/web</pre>

<h2 id="anamestep2astep2importcomponents"><a name="step2"></a> Step 2: Import Components</h2>

<h3 id="allcomponents">All components</h3>

<pre><![CDATA[import { MaterialModule } from '@angular-mdc/web';

@NgModule({
...
imports: [MaterialModule],
...
})
export class ExampleModule { }
]]></pre>

<h3 id="orindividualcomponents">Or individual components</h3>

Add an import of MdcCoreModule to provide ripple, typography, and elevation functionality. Now just import the NgModule for each component you want to use.
<pre><![CDATA[import {
MdcCoreModule, // required
MdcFabModule,
Expand All @@ -61,25 +34,23 @@ <h2 id="anamestep3astep3importangularmdctheme"><a name="step3"></a> Step 3: Impo

<p>Import the Angular MDC theme into your project Sass:</p>

<pre><code class="sass language-sass">$mdc-theme-primary: #1565c0; // change primary color example
<pre>$mdc-theme-primary: #1565c0; // change primary color example
$mdc-theme-secondary: #388e3c; // change secondary color example

@import "~@angular-mdc/theme/material";
</code></pre>
</pre>

<h2 id="anamestep4astep4includematerialdesignicons"><a name="step4"></a> Step 4: Include Material Design Icons</h2>

<p>Add the <a href="https://material.io/icons/">Material Design Icons</a> collection to your <code>index.html</code>.</p>

<pre><code class="html language-html">&lt;link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"&gt;
</code></pre>
<pre>&lt;link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"&gt;</pre>

<h2 id="anamestep5astep5includerobotofont"><a name="step5"></a> Step 5: Include Roboto Font</h2>

<p>Add the Roboto font with 300, 400 and 500 weights to your <code>index.html</code>.</p>

<pre><code class="html language-html">&lt;link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet"&gt;
</code></pre>
<pre>&lt;link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet"&gt;</pre>

<h3 id="alldone">All done!</h3>
<h3 id="alldone">All set!</h3>
</div>
2 changes: 1 addition & 1 deletion src/demo-app/home/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h2 mdc-typography-display2 mdc-typography-adjust-margin fxShow fxHide.xs="true"
<button fxFlexOffset="25px" [raised]="true" [secondary]="true" mdc-button [routerLink]="['getting-started']">Get Started</button>
</mdc-card>
<div mdc-typography-caption fxFlexOffset="40px" fxLayout="column" fxLayoutAlign="center center">
<span>angular-mdc-web v0.5.5</span>
<span>angular-mdc-web v0.5.6</span>
<span>material-components-web v0.23.0</span>
</div>
</div>
3 changes: 1 addition & 2 deletions src/demo-app/home/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
selector: 'home',
templateUrl: './home.html'
})
export class Home {
}
export class Home { }
3 changes: 1 addition & 2 deletions src/demo-app/navigation/app-toolbar.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Component, ViewChild } from '@angular/core';

import { navigationLinks } from './index';
import { MdcTemporaryDrawerComponent } from '../../lib/public_api';

@Component({
selector: 'app-toolbar',
Expand All @@ -10,7 +9,7 @@ import { MdcTemporaryDrawerComponent } from '../../lib/public_api';
export class AppToolbar {
navLinks = navigationLinks;
isFixed: boolean = true;
@ViewChild('drawer') drawer: MdcTemporaryDrawerComponent;
@ViewChild('drawer') drawer: any;

toggleDrawer() {
this.drawer.open();
Expand Down
37 changes: 19 additions & 18 deletions src/lib/button/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
HostListener,
Input,
Renderer2,
ViewEncapsulation
ViewEncapsulation,
} from '@angular/core';
import { MdcIcon } from '../icon/icon';
import { MdcRipple } from '../core/ripple/ripple.service';
Expand All @@ -21,12 +21,13 @@ import {
selector: 'button[mdc-button], a[mdc-button]',
template: '<ng-content></ng-content>',
host: {
'[attr.aria-disabled]': 'disabled.toString()',
'[attr.aria-disabled]': 'disabled.toString()'
},
providers: [MdcRipple],
encapsulation: ViewEncapsulation.None,
})
export class MdcButton implements AfterViewInit {
private disabled_: boolean = false;
private _disabled: boolean = false;

@Input() raised: boolean = false;
@Input() primary: boolean = false;
Expand All @@ -36,18 +37,18 @@ export class MdcButton implements AfterViewInit {
@Input() unelevated: boolean = false;
@Input() stroked: boolean = false;
@Input()
get disabled(): boolean { return this.disabled_; }
set disabled(value) {
this.disabled_ = toBoolean(value);
if (this.disabled_) {
get disabled(): boolean { return this._disabled; }
set disabled(value: boolean) {
this._disabled = toBoolean(value);
if (this._disabled) {
this.renderer.setAttribute(this.elementRef.nativeElement, "disabled", 'true');
} else {
this.renderer.removeAttribute(this.elementRef.nativeElement, "disabled");
}
}
@Input()
get disableRipple(): boolean { return this.ripple.disabled; }
set disableRipple(value) {
set disableRipple(value: boolean) {
this.ripple.disabled = toBoolean(value);
}
@HostBinding('tabindex') get tabindex(): number {
Expand Down Expand Up @@ -76,13 +77,13 @@ export class MdcButton implements AfterViewInit {
return this.stroked ? 'mdc-button--stroked' : '';
}
@HostListener('click', ['$event']) onclick(evt: Event) {
this.handleClick_(evt);
this._onClick(evt);
}
@HostListener('keypress', ['$event']) onkeypress(evt: KeyboardEvent) {
this.handleKeyPress_(evt);
this._onKeyPress(evt);
}
@HostListener('blur', ['$event']) blur(evt: FocusEvent) {
this.handleBlur_(evt);
this._onBlur(evt);
}
@ContentChild(MdcIcon) buttonIcon: MdcIcon;

Expand All @@ -91,7 +92,7 @@ export class MdcButton implements AfterViewInit {
public elementRef: ElementRef,
public ripple: MdcRipple) { }

ngAfterViewInit() {
ngAfterViewInit(): void {
if (this.buttonIcon) {
this.renderer.addClass(this.buttonIcon.elementRef.nativeElement, 'mdc-button__icon');
}
Expand All @@ -100,25 +101,25 @@ export class MdcButton implements AfterViewInit {
}
}

private handleClick_(event: Event) {
private _onClick(event: Event): void {
// A disabled button shouldn't apply any actions
if (this.disabled) {
event.preventDefault();
event.stopImmediatePropagation();
}
}

private handleKeyPress_(keyboardEvent: KeyboardEvent) {
let keyCode = keyboardEvent.keyCode;
if (keyCode == KeyCodes.ENTER || isSpaceKey(keyboardEvent)) {
private _onKeyPress(event: KeyboardEvent): void {
let keyCode = event.keyCode;
if (keyCode == KeyCodes.ENTER || isSpaceKey(event)) {
this.ripple.active = true;
if (keyCode != KeyCodes.ENTER) {
keyboardEvent.preventDefault();
event.preventDefault();
}
}
}

private handleBlur_(focusEvent: FocusEvent) {
private _onBlur(event: FocusEvent): void {
this.ripple.active = false;
}
}
2 changes: 2 additions & 0 deletions src/lib/button/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { NgModule } from '@angular/core';

import { MdcIconModule } from '../icon/index';
import { MdcRippleModule } from '../core/ripple/index';
import { MdcButton } from './button';

@NgModule({
imports: [
MdcIconModule,
MdcRippleModule,
],
exports: [
MdcIconModule,
Expand Down
Loading

0 comments on commit d7f516c

Please sign in to comment.