Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Commit

Permalink
Merge branch 'feature/new-setup' of https://github.com/fivethree-team…
Browse files Browse the repository at this point in the history
…/component-library into feature/new-setup

# Conflicts:
#	projects/core/src/lib/fivethree.core.module.ts
  • Loading branch information
garygrossgarten committed Oct 10, 2018
2 parents cbf5ae0 + e83b17d commit a515a55
Show file tree
Hide file tree
Showing 15 changed files with 246 additions and 3 deletions.
1 change: 1 addition & 0 deletions projects/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"@angular/animations": "^6.1.9",
"@angular/common": "^6.1.9",
"@angular/core": "^6.1.9",
"@angular/forms": "^6.1.9",
"@angular/router": "~6.1.9",
"@ionic/angular": "4.0.0-beta.12"
}
Expand Down
5 changes: 5 additions & 0 deletions projects/core/src/lib/fivethree.core.module.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { FormsModule } from '@angular/forms';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { IonicModule } from '@ionic/angular';
Expand All @@ -10,14 +11,17 @@ import { RouterItemComponent } from './router-item/router-item.component';
import { CenterDirective } from './center/center.directive';
import { CollapsableMenuDirective } from './collapsable-menu/collapsable-menu.directive';
import { CollapsableMenuButtonComponent } from './collapsable-menu/collapsable-menu-button/collapsable-menu-button.component';
import { PasswordComponent } from './password/password.component';

@NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule
],
declarations: [
ExpandableComponent,
PasswordComponent,
StepperComponent,
StepComponent,
StepHeaderComponent,
Expand All @@ -29,6 +33,7 @@ import { CollapsableMenuButtonComponent } from './collapsable-menu/collapsable-m
],
exports: [
ExpandableComponent,
PasswordComponent,
StepperComponent,
StepComponent,
StepHeaderComponent,
Expand Down
1 change: 1 addition & 0 deletions projects/core/src/lib/password/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# fiv-password
5 changes: 5 additions & 0 deletions projects/core/src/lib/password/password.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ion-item>
<ion-label *ngIf="placeholder" [position]="position">{{ placeholder }}</ion-label>
<ion-input [type]="show ? 'text' : 'password'" [(ngModel)]="value" [clearOnEdit]="clearOnEdit"></ion-input>
<ion-icon slot="end" [name]="show ? hideIcon : showIcon" (click)="toggleShowPassword()"></ion-icon>
</ion-item>
Empty file.
25 changes: 25 additions & 0 deletions projects/core/src/lib/password/password.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 { PasswordComponent } from './password.component';

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

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

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

it('should create', () => {
expect(component).toBeTruthy();
});
});
76 changes: 76 additions & 0 deletions projects/core/src/lib/password/password.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { Component, OnInit, Input, forwardRef } from '@angular/core';
import { NG_VALUE_ACCESSOR, ControlValueAccessor, Validator, ValidationErrors, AbstractControl, NG_VALIDATORS } from '@angular/forms';

export const CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR: any = {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => PasswordComponent),
multi: true
};

export const CUSTOM_INPUT_VALIDATOR = {
provide: NG_VALIDATORS,
useExisting: forwardRef(() => PasswordComponent),
multi: true,
};

@Component({
selector: 'fiv-password',
templateUrl: './password.component.html',
styleUrls: ['./password.component.scss'],
providers: [
CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR,
CUSTOM_INPUT_VALIDATOR
],
})
export class PasswordComponent implements ControlValueAccessor, OnInit, Validator {

@Input() hideIcon = 'eye-off';
@Input() placeholder: string;
@Input() position: 'floating' | 'inline' | 'fixed' | 'stacked' = 'floating';
@Input() show: boolean;
@Input() showIcon = 'eye';
@Input() clearOnEdit = false;

private innerValue: any = '';
private onTouchedCallback: () => {};
private onChangeCallback: (_: any) => {};

constructor() { }

ngOnInit() {
}

toggleShowPassword() {
this.show = !this.show;
}

get value(): any {
return this.innerValue;
}

set value(v: any) {
if (v !== this.innerValue) {
this.innerValue = v;
this.onChangeCallback(v);
}
}

writeValue(value: any) {
if (value !== this.innerValue) {
this.innerValue = value;
}
}

registerOnChange(fn: any) {
this.onChangeCallback = fn;
}

registerOnTouched(fn: any) {
this.onTouchedCallback = fn;
}

validate(control: AbstractControl): ValidationErrors {
return null;
}

}
2 changes: 0 additions & 2 deletions projects/core/src/lib/router-item/router-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export class RouterItemComponent implements OnInit {
@HostBinding('class.active') get activeClass() {
const isActive = (this.routeActive && this.router.url.startsWith(this.pageUrl))
|| this.active;
console.log(isActive, this.active, this.router, this.pageUrl);
return isActive;
}

Expand All @@ -52,7 +51,6 @@ export class RouterItemComponent implements OnInit {
}

hasShape(): boolean {
console.log(this.shape);
return this.shape === 'line'
|| this.shape === 'dot';
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const routes: Routes = [
path: 'components',
loadChildren: './components/components.module#ComponentsPageModule'
},
{ path: 'loading', loadChildren: './loading/loading.module#LoadingPageModule' }
{ path: 'loading', loadChildren: './loading/loading.module#LoadingPageModule' },
{ path: 'password', loadChildren: './password/password.module#PasswordPageModule' }
];

@NgModule({
Expand Down
5 changes: 5 additions & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export class AppComponent {
url: '/components',
icon: 'home'
},
{
title: 'Password Item',
url: '/password',
icon: 'key'
},
{
title: 'Loading',
url: '/loading',
Expand Down
29 changes: 29 additions & 0 deletions src/app/password/password.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { FivethreeCoreModule } from 'core';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { Routes, RouterModule } from '@angular/router';

import { IonicModule } from '@ionic/angular';

import { PasswordPage } from './password.page';

const routes: Routes = [
{
path: '',
component: PasswordPage
}
];

@NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule,
FivethreeCoreModule,
ReactiveFormsModule,
RouterModule.forChild(routes)
],
declarations: [PasswordPage]
})
export class PasswordPageModule {}
36 changes: 36 additions & 0 deletions src/app/password/password.page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<ion-header>
<ion-toolbar>
<ion-title>password</ion-title>
</ion-toolbar>
</ion-header>

<ion-content padding>

<ion-item-divider>Default Password</ion-item-divider>
<fiv-password></fiv-password>

<ion-item-divider>Password with placeholder</ion-item-divider>
<fiv-password placeholder="Password"></fiv-password>

<ion-item-divider>Password with placeholder and inline position</ion-item-divider>
<fiv-password placeholder="Password" position="inline"></fiv-password>

<ion-item-divider>Show password</ion-item-divider>
<fiv-password [show]="true"></fiv-password>

<ion-item-divider>Password with any show and hide icons</ion-item-divider>
<fiv-password showIcon="ice-cream" hideIcon="leaf"></fiv-password>

<ion-item-divider>Password in form</ion-item-divider>
<form [formGroup]="loginForm" (ngSubmit)="onSubmit()">
<ion-item>
<ion-label position="floating">E-Mail</ion-label>
<ion-input formControlName="email" type="text"></ion-input>
</ion-item>
<fiv-password placeholder="Password" formControlName="password"></fiv-password>
<ion-button block color="primary" type="submit" [disabled]="loginForm.invalid">
Login
</ion-button>
</form>

</ion-content>
Empty file.
27 changes: 27 additions & 0 deletions src/app/password/password.page.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { PasswordPage } from './password.page';

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

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ PasswordPage ],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
.compileComponents();
}));

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

it('should create', () => {
expect(component).toBeTruthy();
});
});
34 changes: 34 additions & 0 deletions src/app/password/password.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators, AbstractControl } from '@angular/forms';

@Component({
selector: 'app-password',
templateUrl: './password.page.html',
styleUrls: ['./password.page.scss'],
})
export class PasswordPage implements OnInit {

loginForm: FormGroup;

constructor(public formBuilder: FormBuilder) { }

ngOnInit() {
this.setupForm();
}

setupForm() {
this.loginForm = this.formBuilder.group({
email: ['', [Validators.email, Validators.required]],
password: ['', [Validators.minLength(6), Validators.required]],
});
}

get email(): AbstractControl {
return this.loginForm.get('email');
}

onSubmit() {
console.log(this.loginForm.value);
}

}

0 comments on commit a515a55

Please sign in to comment.