Skip to content

Commit

Permalink
feat(code): add prettier code formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
adailtonribeiro committed May 6, 2018
1 parent 5bc452c commit 0665722
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 76 deletions.
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package.json
package-lock.json
.git/
.idea/
dist/
node_modules/
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"printWidth": 140,
"singleQuote": true,
"useTabs": false,
"tabWidth": 2,
"semi": true,
"arrowParens": "avoid",
"bracketSpacing": false
}
77 changes: 77 additions & 0 deletions package-lock.json

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

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"ngc": "ngc",
"build": "npm run ngc",
"publishPackage": "npm run build && npm publish",
"prettier": "prettier --write src/**",
"pretty-quick": "pretty-quick",
"precommit": "pretty-quick --staged",
"commitmsg": "commitlint -e $GIT_PARAMS",
"release": "standard-version"
},
Expand Down Expand Up @@ -39,6 +42,8 @@
"@commitlint/config-angular": "^6.1.3",
"husky": "^0.14.3",
"ionic-angular": "^3.9.2",
"prettier": "^1.12.1",
"pretty-quick": "^1.4.1",
"rxjs": "5.5.2",
"standard-version": "^4.3.0",
"typescript": "^2.6.2",
Expand Down
109 changes: 53 additions & 56 deletions src/ar-error-message-component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Component, ElementRef, Input, OnDestroy, OnInit} from '@angular/core';
import {trigger, state, transition, style, animate} from "@angular/animations";
import {Events} from "ionic-angular";
import {trigger, state, transition, style, animate} from '@angular/animations';
import {Events} from 'ionic-angular';

const HTML_TEMPLATE = `<div [@fadeIn] [@fadeOut]="fadeOutEffect" class="ar-error-message">
<p [ngStyle]="{'display':fadeOutEffect == 'hidden' ? 'none' : 'block' }">{{message}}</p>
Expand All @@ -20,68 +20,65 @@ const CSS_STYLE = `
}`;

@Component({
selector: 'ar-error-message',
template: HTML_TEMPLATE,
styles: [CSS_STYLE],
animations: [
trigger('fadeIn', [
state('void', style({opacity: '0'})),
state('*', style({opacity: '1'})),
transition('void <=> *', animate('750ms ease-in'))
]),
trigger('fadeOut', [
//state('*', style({'min-height': '40px'})),
state('hidden', style({'min-height': '0'})),
transition('* => *', animate('500ms ease-in'))
])
]
selector: 'ar-error-message',
template: HTML_TEMPLATE,
styles: [CSS_STYLE],
animations: [
trigger('fadeIn', [
state('void', style({opacity: '0'})),
state('*', style({opacity: '1'})),
transition('void <=> *', animate('750ms ease-in'))
]),
trigger('fadeOut', [
//state('*', style({'min-height': '40px'})),
state('hidden', style({'min-height': '0'})),
transition('* => *', animate('500ms ease-in'))
])
]
})
export class ArErrorMessageComponent implements OnInit, OnDestroy {
autoHide: boolean = false;
fadeOutEffect: string;
@Input('autoScroll') autoScroll: boolean = true;
@Input('message') message: string = '';

autoHide: boolean = false;
fadeOutEffect: string;
@Input('autoScroll') autoScroll: boolean = true;
@Input('message') message: string = '';

@Input('autoHide') set setAutoHide(autoHide) {
this.autoHide = autoHide;
if (autoHide) {
this.triggerHideComponent();
}
};

constructor(public elRef: ElementRef, public events: Events) {
@Input('autoHide')
set setAutoHide(autoHide) {
this.autoHide = autoHide;
if (autoHide) {
this.triggerHideComponent();
}
}

ngOnInit() {
if (this.autoScroll) {
this.scrollToComponent();
}
this.events.subscribe('form-submit-failed', () => {
if (this.autoScroll) {
this.scrollToComponent();
}
if (this.autoHide) {
this.fadeOutEffect = 'void';
this.triggerHideComponent();
}
});

}
constructor(public elRef: ElementRef, public events: Events) {}

ngOnDestroy() {
this.events.unsubscribe('form-submit-failed');
ngOnInit() {
if (this.autoScroll) {
this.scrollToComponent();
}
this.events.subscribe('form-submit-failed', () => {
if (this.autoScroll) {
this.scrollToComponent();
}
if (this.autoHide) {
this.fadeOutEffect = 'void';
this.triggerHideComponent();
}
});
}

triggerHideComponent() {
setTimeout(() => {
this.fadeOutEffect = 'hidden';
//this.message = '';
}, 5000);
}
ngOnDestroy() {
this.events.unsubscribe('form-submit-failed');
}

scrollToComponent() {
this.elRef.nativeElement.scrollIntoView({behavior: "smooth"});
}
triggerHideComponent() {
setTimeout(() => {
this.fadeOutEffect = 'hidden';
//this.message = '';
}, 5000);
}

scrollToComponent() {
this.elRef.nativeElement.scrollIntoView({behavior: 'smooth'});
}
}
36 changes: 17 additions & 19 deletions src/ar-error-message.module.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import {NgModule, ModuleWithProviders} from '@angular/core';
import {ArErrorMessageComponent} from "./ar-error-message-component";
import {IonicModule} from "ionic-angular";
import {ArErrorMessageComponent} from './ar-error-message-component';
import {IonicModule} from 'ionic-angular';

@NgModule({
imports: [
IonicModule
],
declarations: [
// declare all components that your module uses
ArErrorMessageComponent
],
exports: [
// export the component(s) that you want others to be able to use
ArErrorMessageComponent
]
imports: [IonicModule],
declarations: [
// declare all components that your module uses
ArErrorMessageComponent
],
exports: [
// export the component(s) that you want others to be able to use
ArErrorMessageComponent
]
})
export class ArErrorMessageModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: ArErrorMessageModule
};
}
}
static forRoot(): ModuleWithProviders {
return {
ngModule: ArErrorMessageModule
};
}
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './ar-error-message.module';
export * from './ar-error-message-component';
export * from './ar-error-message-component';

0 comments on commit 0665722

Please sign in to comment.