Skip to content

Commit

Permalink
Merge pull request #5 from Dashbrd/add-search-component
Browse files Browse the repository at this point in the history
add search component
  • Loading branch information
ankeshdave authored Jan 1, 2019
2 parents 51eaa79 + 793f81e commit f985dad
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';
import { SwPeopleListComponent } from './sw-people-list/sw-people-list.component';
import { SwCharacterComponent } from './sw-character/sw-character.component';
import { CharacterSearchComponent } from './character-search/character-search.component';

@NgModule({
declarations: [
AppComponent,
HeaderComponent,
SwPeopleListComponent,
SwCharacterComponent
SwCharacterComponent,
CharacterSearchComponent
],
imports: [
BrowserModule,
Expand Down
3 changes: 3 additions & 0 deletions src/app/character-search/character-search.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="ui icon input">
<input type="text" placeholder="Search..." (input)="handleInput($event)" />
</div>
7 changes: 7 additions & 0 deletions src/app/character-search/character-search.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.input {
width: 300px;

input {
font-family: "Titillium Web", sans-serif;
}
}
25 changes: 25 additions & 0 deletions src/app/character-search/character-search.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 { CharacterSearchComponent } from './character-search.component';

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

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

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

it('should create', () => {
expect(component).toBeTruthy();
});
});
22 changes: 22 additions & 0 deletions src/app/character-search/character-search.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Component, EventEmitter, OnInit, Output } from '@angular/core';

@Component({
selector: 'app-character-search',
templateUrl: './character-search.component.html',
styleUrls: ['./character-search.component.scss']
})
export class CharacterSearchComponent implements OnInit {

@Output() search = new EventEmitter<string>();

constructor() { }

ngOnInit() {
}


public handleInput(event: any) {
this.search.emit(event.target.value);
}

}
1 change: 1 addition & 0 deletions src/app/sw-people-list/sw-people-list.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<app-character-search (search)="filterData($event)"></app-character-search>
<table class="ui selectable celled table">
<thead>
<tr>
Expand Down
12 changes: 12 additions & 0 deletions src/app/sw-people-list/sw-people-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,16 @@ export class SwPeopleListComponent implements OnInit {

}

/**
* filterData
*/
public filterData(event: string) {
this.swCharacters = this.swCharacters.filter((character: StarWarsCharacter) => {
if (character.name.includes(event)) {
return true;
}
return false;
});
}

}

0 comments on commit f985dad

Please sign in to comment.