An Ionic list directive
Created
August 23, 2015 05:51
-
-
Save arup-b/990f3e37d0e9a5f25e94 to your computer and use it in GitHub Desktop.
Accordion List: Nightly
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
<html ng-app="ionicApp"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> | |
<title>Ionic Accordion</title> | |
<link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet"> | |
<script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script> | |
</head> | |
<body ng-controller="MyCtrl"> | |
<ion-header-bar class="bar-positive"> | |
<h1 class="title">Accordion List</h1> | |
</ion-header-bar> | |
<ion-content> | |
<ion-list> | |
<div ng-repeat="group in groups"> | |
<ion-item class="item-stable" | |
ng-click="toggleGroup(group)" | |
ng-class="{active: isGroupShown(group)}"> | |
<i class="icon" ng-class="isGroupShown(group) ? 'ion-minus' : 'ion-plus'"></i> | |
| |
Group {{group.name}} | |
</ion-item> | |
<ion-item class="item-accordion" | |
ng-repeat="item in group.items" | |
ng-show="isGroupShown(group)"> | |
{{item}} | |
</ion-item> | |
</div> | |
</ion-list> | |
</ion-content> | |
</body> | |
</html> |
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
angular.module('ionicApp', ['ionic']) | |
.controller('MyCtrl', function($scope) { | |
$scope.groups = []; | |
for (var i=0; i<10; i++) { | |
$scope.groups[i] = { | |
name: i, | |
items: [] | |
}; | |
for (var j=0; j<3; j++) { | |
$scope.groups[i].items.push(i + '-' + j); | |
} | |
} | |
/* | |
* if given group is the selected group, deselect it | |
* else, select the given group | |
*/ | |
$scope.toggleGroup = function(group) { | |
if ($scope.isGroupShown(group)) { | |
$scope.shownGroup = null; | |
} else { | |
$scope.shownGroup = group; | |
} | |
}; | |
$scope.isGroupShown = function(group) { | |
return $scope.shownGroup === group; | |
}; | |
}); |
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
body { | |
cursor: url('http://ionicframework.com/img/finger.png'), auto; | |
} | |
/* | |
* http://docs.angularjs.org/api/ng/directive/ngShow#usage_animations | |
*/ | |
.list .item.item-accordion { | |
line-height: 38px; | |
padding-top: 0; | |
padding-bottom: 0; | |
transition: 0.09s all linear; | |
} | |
.list .item.item-accordion.ng-hide { | |
line-height: 0px; | |
} | |
.list .item.item-accordion.ng-hide-add, | |
.list .item.item-accordion.ng-hide-remove { | |
display: block !important; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment