This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(autocomplete): custom template demo
- Loading branch information
1 parent
b4533b5
commit 7d2deb7
Showing
6 changed files
with
203 additions
and
10 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions
5
src/components/autocomplete/demoCustomTemplate/img/icons/octicon-repo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,35 @@ | ||
<div ng-controller="DemoCtrl as ctrl" layout="column"> | ||
<md-content layout-padding layout="column"> | ||
<form ng-submit="$event.preventDefault()"> | ||
<p>Use <code><md-autocomplete></code> with custom templates to show styled autocomplete results.</p> | ||
<md-autocomplete | ||
ng-disabled="ctrl.isDisabled" | ||
md-no-cache="ctrl.noCache" | ||
md-selected-item="ctrl.selectedItem" | ||
md-search-text-change="ctrl.searchTextChange(ctrl.searchText)" | ||
md-search-text="ctrl.searchText" | ||
md-selected-item-change="ctrl.selectedItemChange(item)" | ||
md-items="item in ctrl.querySearch(ctrl.searchText)" | ||
md-item-text="item.name" | ||
md-min-length="0" | ||
placeholder="Pick an Angular repository" | ||
md-menu-class="autocomplete-custom-template"> | ||
<md-item-template> | ||
<span class="item-title"> | ||
<md-icon md-svg-icon="img/icons/octicon-repo.svg"></md-icon> | ||
<span> {{item.name}} </span> | ||
</span> | ||
<span class="item-metadata"> | ||
<span class="item-metastat"> | ||
<strong>{{item.watchers}}</strong> watchers | ||
</span> | ||
<span class="item-metastat"> | ||
<strong>{{item.forks}}</strong> forks | ||
</span> | ||
</span> | ||
</md-item-template> | ||
</md-autocomplete> | ||
</form> | ||
</md-content> | ||
</div> | ||
|
100 changes: 100 additions & 0 deletions
100
src/components/autocomplete/demoCustomTemplate/script.js
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,100 @@ | ||
(function () { | ||
'use strict'; | ||
angular | ||
.module('autocompleteCustomTemplateDemo', ['ngMaterial']) | ||
.controller('DemoCtrl', DemoCtrl); | ||
|
||
function DemoCtrl ($timeout, $q, $log) { | ||
var self = this; | ||
|
||
self.simulateQuery = false; | ||
self.isDisabled = false; | ||
|
||
self.repos = loadAll(); | ||
self.querySearch = querySearch; | ||
self.selectedItemChange = selectedItemChange; | ||
self.searchTextChange = searchTextChange; | ||
|
||
// ****************************** | ||
// Internal methods | ||
// ****************************** | ||
|
||
/** | ||
* Search for repos... use $timeout to simulate | ||
* remote dataservice call. | ||
*/ | ||
function querySearch (query) { | ||
var results = query ? self.repos.filter( createFilterFor(query) ) : self.repos, | ||
deferred; | ||
if (self.simulateQuery) { | ||
deferred = $q.defer(); | ||
$timeout(function () { deferred.resolve( results ); }, Math.random() * 1000, false); | ||
return deferred.promise; | ||
} else { | ||
return results; | ||
} | ||
} | ||
|
||
function searchTextChange(text) { | ||
$log.info('Text changed to ' + text); | ||
} | ||
|
||
function selectedItemChange(item) { | ||
$log.info('Item changed to ' + JSON.stringify(item)); | ||
} | ||
|
||
/** | ||
* Build `components` list of key/value pairs | ||
*/ | ||
function loadAll() { | ||
var repos = [ | ||
{ | ||
'name' : 'Angular 1', | ||
'url' : 'https://github.com/angular/angular.js', | ||
'watchers' : '3,623', | ||
'forks' : '16,175', | ||
}, | ||
{ | ||
'name' : 'Angular 2', | ||
'url' : 'https://github.com/angular/angular', | ||
'watchers' : '469', | ||
'forks' : '760', | ||
}, | ||
{ | ||
'name' : 'Angular Material', | ||
'url' : 'https://github.com/angular/material', | ||
'watchers' : '727', | ||
'forks' : '1,241', | ||
}, | ||
{ | ||
'name' : 'Bower Material', | ||
'url' : 'https://github.com/angular/bower-material', | ||
'watchers' : '42', | ||
'forks' : '84', | ||
}, | ||
{ | ||
'name' : 'Material Start', | ||
'url' : 'https://github.com/angular/material-start', | ||
'watchers' : '81', | ||
'forks' : '303', | ||
} | ||
]; | ||
return repos.map( function (repo) { | ||
repo.value = repo.name.toLowerCase(); | ||
return repo; | ||
}); | ||
} | ||
|
||
/** | ||
* Create filter function for a query string | ||
*/ | ||
function createFilterFor(query) { | ||
var lowercaseQuery = angular.lowercase(query); | ||
|
||
return function filterFn(item) { | ||
return (item.value.indexOf(lowercaseQuery) === 0); | ||
}; | ||
|
||
} | ||
} | ||
})(); |
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,19 @@ | ||
.autocomplete-custom-template li { | ||
border-bottom: 1px solid #ccc; | ||
height: auto; | ||
padding-top: 8px; | ||
padding-bottom: 8px; | ||
white-space: normal; | ||
} | ||
.autocomplete-custom-template li:last-child { | ||
border-bottom-width: 0; | ||
} | ||
.autocomplete-custom-template .item-title, | ||
.autocomplete-custom-template .item-metadata { | ||
display: block; | ||
line-height: 2; | ||
} | ||
.autocomplete-custom-template .item-title md-icon { | ||
height: 18px; | ||
width: 18px; | ||
} |