-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(navbar): Add basic searchbar component to site.
- Loading branch information
Showing
9 changed files
with
140 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './navbar'; | ||
export * from './searchbar'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './searchbar'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<div class="search-input-container"> | ||
<input | ||
placeholder="Search" | ||
type="text" | ||
(focus)="toggleIsExpanded(true)" | ||
(blur)="toggleIsExpanded(false)" | ||
(keyup.enter)="navigate($event.target.value.toLowerCase())" | ||
[mdAutocomplete]="auto" | ||
[formControl]="searchControl"> | ||
</div> | ||
|
||
<md-autocomplete #auto="mdAutocomplete"> | ||
<md-option *ngFor="let item of filteredSuggestions | async" [value]="item.name"> | ||
{{item.name}} | ||
</md-option> | ||
</md-autocomplete> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
$input-bg: #85D9E2; | ||
|
||
@mixin color-placeholder() { | ||
-webkit-font-smoothing: antialiased; | ||
color: white; | ||
} | ||
|
||
:host { | ||
position: relative; | ||
flex: 2; | ||
|
||
* { | ||
box-sizing: border-box; | ||
} | ||
|
||
&.expanded .search-input-container { | ||
width: 100%; | ||
} | ||
|
||
.search-input-container { | ||
display: block; | ||
position: relative; | ||
margin-left: auto; | ||
height: 100%; | ||
width: 200px; | ||
transition: width .2s ease; | ||
&:after { | ||
content: ''; | ||
position: absolute; | ||
left: 15px; top: 50%; | ||
transform: translateY(-50%); | ||
height: 28px; | ||
width: 28px; | ||
background: url('../../../../assets/img/icons/ic_search_white_24px.svg') center center no-repeat; | ||
} | ||
} | ||
|
||
input { | ||
background: $input-bg; | ||
border: none; | ||
border-radius: 2px; | ||
color: white; | ||
font-size: 18px; | ||
height: 95%; | ||
line-height: 95%; | ||
padding-left: 50px; | ||
position: relative; | ||
transition: width .2s ease; | ||
width: 100%; | ||
|
||
/* Set placeholder text to be white */ | ||
&::-webkit-input-placeholder { @include color-placeholder(); } /* Chrome/Opera/Safari */ | ||
&::-moz-placeholder { @include color-placeholder(); } /* Firefox 19+ */ | ||
&:-moz-placeholder { @include color-placeholder(); } /* Firefox 18- */ | ||
&:ms-input-placeholder { @include color-placeholder(); } /* IE 10+ */ | ||
|
||
&:focus { | ||
outline: none; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import {Component, HostBinding} from '@angular/core'; | ||
import {Router} from '@angular/router'; | ||
import {FormControl} from '@angular/forms'; | ||
import {MdSnackBar} from '@angular/material'; | ||
import {Observable} from 'rxjs'; | ||
|
||
import {DocumentationItems, DocItem} from '../../documentation-items/documentation-items'; | ||
|
||
|
||
@Component({ | ||
selector: 'search-bar-component', | ||
templateUrl: './searchbar.html', | ||
styleUrls: ['./searchbar.scss'] | ||
}) | ||
|
||
export class SearchBar { | ||
@HostBinding('class.expanded') _isExpanded = false; | ||
public allDocItems: DocItem[]; | ||
public filteredSuggestions: Observable<DocItem[]>; | ||
public searchControl: FormControl = new FormControl(''); | ||
|
||
constructor( | ||
private _docItems: DocumentationItems, | ||
private _router: Router, | ||
private _snackBar: MdSnackBar | ||
) { | ||
this.allDocItems = _docItems.getAllItems(); | ||
this.filteredSuggestions = this.searchControl.valueChanges | ||
.startWith(null) | ||
.map(item => this.filterSearchSuggestions(item)); | ||
} | ||
|
||
public toggleIsExpanded() { | ||
this._isExpanded = !this._isExpanded; | ||
} | ||
|
||
public filterSearchSuggestions(searchTerm): DocItem[] { | ||
return this.allDocItems.filter(item => new RegExp(`^${searchTerm}`, 'gi').test(item.name)); | ||
} | ||
|
||
public navigate(searchValue) { | ||
const category = this.allDocItems.find(item => item.name.toLowerCase() === searchValue); | ||
category ? | ||
this._router.navigateByUrl(`/components/component/${category.id}`) : | ||
this._showError(); | ||
} | ||
|
||
private _showError() { | ||
this._snackBar.open('No search results found.', null, {duration: 3000}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.