Created
February 18, 2014 19:31
-
-
Save vojtajina/9078191 to your computer and use it in GitHub Desktop.
A tree example
This file contains hidden or 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
<i class="file {{data.extension}}" on-click="emitClick()"> | |
<span class="folder-name">{{data.basename}}</span> | |
</i> |
This file contains hidden or 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
import {Component, Scope} from 'ng/core'; | |
@Component({ | |
interface: ['data'], | |
events: ['item-click'], | |
// these are the default values | |
template: './file-component.html', | |
style: './file-component.css' | |
}) | |
class FileComponent { | |
constructor() {} | |
emitClick() { | |
this.$scope.emit('item-click', this.data); | |
} | |
} |
This file contains hidden or 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
<i class="folder {{open: isOpen, collapsed: !isOpen}}" on-click="toggleChildren()"> | |
<span class="folder-name">{{data.basename}}</span> | |
</i> | |
<ul ng-if="isOpen"> | |
<li ng-repeat="item in data.children" dynamic-component="item.type" data="item"></li> | |
</ul> |
This file contains hidden or 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
import {Component, Scope} from 'ng/core'; | |
@Component({ | |
interface: ['data'], | |
events: ['item-click'], | |
// these are the default values | |
template: './folder-component.html', | |
style: './folder-component.css' | |
}) | |
class FolderComponent { | |
constructor($scope: Scope) { | |
this.isOpen = false; | |
} | |
toggleChildren() { | |
this.isOpen = !this.isOpen; | |
this.$scope.emit('item-click', this.data); | |
} | |
} |
This file contains hidden or 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
<!-- using in a parent component --> | |
<folder data="rootFolder" on-item-click="whatever()"></folder> |
This file contains hidden or 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
import {FileComponent} from '../file-component.js'; | |
import {FolderComponent} from '../folder-component.js'; | |
// these don't have to be classes, | |
// it can be any object | |
class FileItem { | |
constructor(basename, extension) { | |
this.basename = basename; | |
this.extension = extension; | |
} | |
get type() { | |
return FileComponent; | |
} | |
} | |
class FolderItem { | |
constructor(basename, children) { | |
this.basename = basename; | |
this.children = children; | |
} | |
get type() { | |
return FolderComponent; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment