Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
feat(autocomplete): custom template demo
Browse files Browse the repository at this point in the history
Closes #2505. Closes #2835.
  • Loading branch information
Marcy Sutton authored and ThomasBurleson committed Jun 4, 2015
1 parent b4533b5 commit 7d2deb7
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 10 deletions.
49 changes: 39 additions & 10 deletions docs/app/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -750,16 +750,6 @@ ul.methods > li:first-child > *:first-child {
padding-top: 0;
}

/* Styles for Windows High Contrast mode */
@media screen and (-ms-high-contrast: active) {
a {
text-decoration: underline;
}
iframe, hljs pre {
border: 1px solid #fff;
}
}


[ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {
display: none !important;
Expand Down Expand Up @@ -807,3 +797,42 @@ docs-demo .doc-demo-content {
.service-desc > p:last-child {
margin-bottom: 0;
}

/* ---------------------
* Demo Workarounds
*
* Necessary for component demos that append DOM subtrees outside of the demo app.
* Because our docs build prepends CSS classes onto custom demo styles provided for developers,
* these styles are needed for the docs website.
*/
.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;
}


/* Styles for Windows High Contrast mode */
@media screen and (-ms-high-contrast: active) {
a {
text-decoration: underline;
}
iframe, hljs pre {
border: 1px solid #fff;
}
}

5 changes: 5 additions & 0 deletions docs/app/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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions src/components/autocomplete/demoCustomTemplate/index.html
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>&lt;md-autocomplete&gt;</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 src/components/autocomplete/demoCustomTemplate/script.js
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);
};

}
}
})();
19 changes: 19 additions & 0 deletions src/components/autocomplete/demoCustomTemplate/style.css
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;
}

0 comments on commit 7d2deb7

Please sign in to comment.