Skip to content

Instantly share code, notes, and snippets.

@Bestra
Last active September 6, 2016 23:57
Show Gist options
  • Save Bestra/999630ff7c579e98264cdd657d4eaf90 to your computer and use it in GitHub Desktop.
Save Bestra/999630ff7c579e98264cdd657d4eaf90 to your computer and use it in GitHub Desktop.
kata
import Ember from 'ember';
export default Ember.Component.extend({
item: null,
openItem: null,
isOpen: Ember.computed('item', 'openItem', function() {
return this.get('item') === this.get('openItem');
}),
classNames: ['item'],
click() {
this.get('clicked')(this.get('isOpen'));
}
});
import Ember from 'ember';
export default Ember.Component.extend({
items: null, //passed-in
openItem: null,
actions: {
toggleItem(item, itemWasOpen) {
this.set('itemWasOpen', itemWasOpen);
if (this.get('openItem') === item) {
this.set('openItem', null);
} else {
this.set('openItem', item);
}
}
}
});
import Ember from 'ember'
export default Ember.Controller.extend({
listItems: [
{title: "foo"},
{title: "bar"}
]
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.item {
padding: 10px 10px;
cursor: pointer;
border: 1px solid gray;
}
.item .open {
background-color: green;
height: 50px;
}
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{accordion-thing items=listItems}}
{{outlet}}
<br>
<br>
<div class={{if isOpen "open" "closed"}}>
{{item.title}}
</div>
<div>{{itemWasOpen}}</div>
{{#each items as |item|}}
{{accordion-item
item=item
openItem=openItem
showStuff=(action showSomeStuff item)
clicked=(action "toggleItem" item)}}
{{/each}}
{{yield}}
{
"version": "0.10.4",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.7.0",
"ember-data": "2.7.0",
"ember-template-compiler": "2.7.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment