diff --git a/client/src/app/posts/post-form/post-form.component.html b/client/src/app/posts/post-form/post-form.component.html index bbe7faa0d67fc82b46d62ecab24386b9c0a1e992..e89803521b22e8a339b97868c51233890838d3f4 100644 --- a/client/src/app/posts/post-form/post-form.component.html +++ b/client/src/app/posts/post-form/post-form.component.html @@ -1,22 +1,18 @@ <h3>Lag annonse</h3> -<label for="title">Tittel</label> -<input id="title" [(ngModel)]="title" (blur)="checkForm()"> +<app-text-input [(inputModel)]="title" label="Tittel" (blur)="checkForm()"></app-text-input> -<label for="description">Beskrivelse</label> -<input id="description" [(ngModel)]="description" (blur)="checkForm()"> +<app-text-input [(inputModel)]="description" label="Beskrivelse" (blur)="checkForm()"></app-text-input> -<label for="price">Pris</label> -<input type="number" id="price" [(ngModel)]="price" (blur)="checkForm()"> +<app-number-input [(inputModel)]="price" label="Pris" (blur)="checkForm()"></app-number-input> -<label for="category">Kategori</label> -<select id="category" [(ngModel)]="categoryid" (change)="checkForm()" > +<app-select [(inputModel)]="categoryid" (change)="checkForm()" label="Kategori"> <option value="0" selected>Velg kategori</option> <option value="1">Antikviteter og Kunst</option> <option value="2">Dyr og Utstyr</option> <option value="3">Elektronikk og Hvitevarer</option> -</select> +</app-select> <p>{{statusMessage}}</p> -<button (click)="publishPost()">Publiser</button> \ No newline at end of file +<app-button (click)="publishPost()" text="Publiser"></app-button> \ No newline at end of file diff --git a/client/src/app/shared/button/button.component.html b/client/src/app/shared/button/button.component.html new file mode 100644 index 0000000000000000000000000000000000000000..e9923aa14c1888b601d72e264f828fe50b25bcdd --- /dev/null +++ b/client/src/app/shared/button/button.component.html @@ -0,0 +1 @@ +<button>{{text}}</button> \ No newline at end of file diff --git a/client/src/app/shared/button/button.component.scss b/client/src/app/shared/button/button.component.scss new file mode 100644 index 0000000000000000000000000000000000000000..2b4a21691f5cafa5567332acbf906bd2c7ef3e96 --- /dev/null +++ b/client/src/app/shared/button/button.component.scss @@ -0,0 +1,3 @@ +button{ + padding: 5px; +} \ No newline at end of file diff --git a/client/src/app/shared/button/button.component.spec.ts b/client/src/app/shared/button/button.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..534a5bace070a9697ef6a711b5ef0ea5e4ed3044 --- /dev/null +++ b/client/src/app/shared/button/button.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ButtonComponent } from './button.component'; + +describe('ButtonComponent', () => { + let component: ButtonComponent; + let fixture: ComponentFixture<ButtonComponent>; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ ButtonComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(ButtonComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/client/src/app/shared/button/button.component.ts b/client/src/app/shared/button/button.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..605e843429c308bf9d6376e96b188b082580bcc7 --- /dev/null +++ b/client/src/app/shared/button/button.component.ts @@ -0,0 +1,15 @@ +import { Component, EventEmitter, Input, Output } from '@angular/core'; + +@Component({ + selector: 'app-button', + templateUrl: './button.component.html', + styleUrls: ['./button.component.scss'] +}) +export class ButtonComponent { + + @Input() + text: string; + + constructor() { } + +} diff --git a/client/src/app/shared/number-input/number-input.component.html b/client/src/app/shared/number-input/number-input.component.html new file mode 100644 index 0000000000000000000000000000000000000000..f8ce8b67272283b12e63b800ad8c9adedba48fe9 --- /dev/null +++ b/client/src/app/shared/number-input/number-input.component.html @@ -0,0 +1,12 @@ +<label> + {{label}} + + <input + type="number" + [placeholder]="placeholder" + [(ngModel)]="inputModel" + (ngModelChange)="inputModelChange.emit(inputModel)" + (change)="change.emit($event)" + (focus)="focus.emit($event)" + (blur)="blur.emit($event)"> +</label> \ No newline at end of file diff --git a/client/src/app/shared/number-input/number-input.component.scss b/client/src/app/shared/number-input/number-input.component.scss new file mode 100644 index 0000000000000000000000000000000000000000..00cdc2a928d04283ff39dc2652060db7868d0e76 --- /dev/null +++ b/client/src/app/shared/number-input/number-input.component.scss @@ -0,0 +1,3 @@ +input{ + padding: 5px; +} \ No newline at end of file diff --git a/client/src/app/shared/number-input/number-input.component.spec.ts b/client/src/app/shared/number-input/number-input.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..2ff4b9f58e39fd3382d19ef53f1a2e00d68d8806 --- /dev/null +++ b/client/src/app/shared/number-input/number-input.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { NumberInputComponent } from './number-input.component'; + +describe('NumberInputComponent', () => { + let component: NumberInputComponent; + let fixture: ComponentFixture<NumberInputComponent>; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ NumberInputComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(NumberInputComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/client/src/app/shared/number-input/number-input.component.ts b/client/src/app/shared/number-input/number-input.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..7552012c3161631122fd63086d2b894d156a2c50 --- /dev/null +++ b/client/src/app/shared/number-input/number-input.component.ts @@ -0,0 +1,33 @@ +import { Component, EventEmitter, Input, Output } from '@angular/core'; + +@Component({ + selector: 'app-number-input', + templateUrl: './number-input.component.html', + styleUrls: ['./number-input.component.scss'] +}) +export class NumberInputComponent { + + @Input() + label: string = ""; + + @Input() + inputModel: number; + + @Input() + placeholder: string = ""; + + @Output() + inputModelChange = new EventEmitter<number>(); + + @Output() + change = new EventEmitter(); + + @Output() + focus = new EventEmitter(); + + @Output() + blur = new EventEmitter(); + + constructor() { } + +} diff --git a/client/src/app/shared/select/select.component.html b/client/src/app/shared/select/select.component.html new file mode 100644 index 0000000000000000000000000000000000000000..e7e4e7f86b22bf7eda4ff7658b280319b5732faf --- /dev/null +++ b/client/src/app/shared/select/select.component.html @@ -0,0 +1,13 @@ +<label> + {{label}} + + <select + [(ngModel)]="inputModel" + (ngModelChange)="inputModelChange.emit($event)" + (change)="change.emit($event)" + (focus)="focus.emit($event)" + (blur)="blur.emit($event)"> + + <ng-content></ng-content> + </select> +</label> \ No newline at end of file diff --git a/client/src/app/shared/select/select.component.scss b/client/src/app/shared/select/select.component.scss new file mode 100644 index 0000000000000000000000000000000000000000..ffd6836a1cd0aa70df1d79d3954db1353fb96358 --- /dev/null +++ b/client/src/app/shared/select/select.component.scss @@ -0,0 +1,3 @@ +select{ + padding: 5px; +} \ No newline at end of file diff --git a/client/src/app/shared/select/select.component.spec.ts b/client/src/app/shared/select/select.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..2fb4207eb6dd5656d0ae4555b2ae7dbec7b18249 --- /dev/null +++ b/client/src/app/shared/select/select.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { SelectComponent } from './select.component'; + +describe('SelectComponent', () => { + let component: SelectComponent; + let fixture: ComponentFixture<SelectComponent>; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ SelectComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(SelectComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/client/src/app/shared/select/select.component.ts b/client/src/app/shared/select/select.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..81e1d4b76487d922f1a8e89a08ac637aed69db77 --- /dev/null +++ b/client/src/app/shared/select/select.component.ts @@ -0,0 +1,33 @@ +import { Component, EventEmitter, Input, Output } from '@angular/core'; + +@Component({ + selector: 'app-select', + templateUrl: './select.component.html', + styleUrls: ['./select.component.scss'] +}) +export class SelectComponent { + + @Input() + label: string = ""; + + @Input() + inputModel: any; + + @Input() + placeholder: string = ""; + + @Output() + inputModelChange = new EventEmitter<any>(); + + @Output() + change = new EventEmitter(); + + @Output() + focus = new EventEmitter(); + + @Output() + blur = new EventEmitter(); + + constructor() { } + +} diff --git a/client/src/app/shared/shared.module.ts b/client/src/app/shared/shared.module.ts index cfbb9dbe6b4e5a43e9a0a7f0754cc0d3a68b71ea..8459044413a154cba6617960c61140ff610119a9 100644 --- a/client/src/app/shared/shared.module.ts +++ b/client/src/app/shared/shared.module.ts @@ -1,14 +1,28 @@ import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { TextInputComponent } from './text-input/text-input.component'; - +import { FormsModule } from '@angular/forms'; +import { NumberInputComponent } from './number-input/number-input.component'; +import { ButtonComponent } from './button/button.component'; +import { SelectComponent } from './select/select.component'; @NgModule({ - declarations: [TextInputComponent], - exports: [TextInputComponent], + declarations: [ + TextInputComponent, + NumberInputComponent, + ButtonComponent, + SelectComponent + ], + exports: [ + TextInputComponent, + NumberInputComponent, + ButtonComponent, + SelectComponent + ], imports: [ - CommonModule + CommonModule, + FormsModule ] }) export class SharedModule { } diff --git a/client/src/app/shared/text-input/text-input.component.html b/client/src/app/shared/text-input/text-input.component.html index 75c9ae08b200c227f8678d9dc0b77b925037f4eb..52b28fdbbc7203ad4112161373da422493c40812 100644 --- a/client/src/app/shared/text-input/text-input.component.html +++ b/client/src/app/shared/text-input/text-input.component.html @@ -1,2 +1,12 @@ -<label for="textField">{{label}}</label> -<input type="text" id="textField"> \ No newline at end of file +<label> + {{label}} + + <input + type="text" + [placeholder]="placeholder" + [(ngModel)]="inputModel" + (ngModelChange)="inputModelChange.emit(inputModel)" + (change)="change.emit($event)" + (focus)="focus.emit($event)" + (blur)="blur.emit($event)"> +</label> \ No newline at end of file diff --git a/client/src/app/shared/text-input/text-input.component.scss b/client/src/app/shared/text-input/text-input.component.scss index e8b11aacb8b616c3ad2b1a8ddb323ed57dc144e8..00cdc2a928d04283ff39dc2652060db7868d0e76 100644 --- a/client/src/app/shared/text-input/text-input.component.scss +++ b/client/src/app/shared/text-input/text-input.component.scss @@ -1,3 +1,3 @@ -#textField{ +input{ padding: 5px; } \ No newline at end of file diff --git a/client/src/app/shared/text-input/text-input.component.ts b/client/src/app/shared/text-input/text-input.component.ts index 57eb5e853274233b17b71c554f610877f6185c6f..91d87eda8cfd55ced747f08e947a7a4f069b46d6 100644 --- a/client/src/app/shared/text-input/text-input.component.ts +++ b/client/src/app/shared/text-input/text-input.component.ts @@ -1,5 +1,4 @@ -import { Component, Input, OnInit, Output } from '@angular/core'; -import { ControlValueAccessor } from '@angular/forms'; +import { Component, EventEmitter, Input, Output } from '@angular/core'; @Component({ selector: 'app-text-input', @@ -11,6 +10,24 @@ export class TextInputComponent { @Input() label: string = ""; + @Input() + inputModel: string; + + @Input() + placeholder: string = ""; + + @Output() + inputModelChange = new EventEmitter<string>(); + + @Output() + change = new EventEmitter(); + + @Output() + focus = new EventEmitter(); + + @Output() + blur = new EventEmitter(); + constructor() { } }