Last active
September 17, 2016 11:38
-
-
Save Bestra/7eddc1119cc517a5c83c3ed951735e3c to your computer and use it in GitHub Desktop.
List with Add
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
// components/accordion-item.js | |
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
tagName: 'div', | |
item: null, // passed-in | |
isExpanded: Ember.computed('activeItem', 'item', function() { | |
return this.get('activeItem') === this.get('item'); | |
}) | |
}); |
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
// components/accordion-list.js | |
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
items: null, | |
activeItem: null | |
}); |
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
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
activeItem: null, | |
items: Ember.computed(function() { | |
return [ | |
{title: "Item 1", details: "Details here"}, | |
{title: "Item 2", details: "Details here"}, | |
{title: "Item 3", details: "Details here"} | |
] | |
}), | |
actions: { | |
addItem() { | |
let newItem = { | |
title: `Item ${this.get('items.length') + 1}`, | |
details: 'Details here' | |
} | |
this.get('items').addObject(newItem); | |
this.set('activeItem', newItem); | |
}, | |
toggleActiveItem(item) { | |
if (this.get('activeItem') !== item) { | |
this.set('activeItem', item); | |
} else { | |
this.set('activeItem', null); | |
} | |
} | |
} | |
}); |
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
+---------------------------------+ | |
| | | |
| Parent | | |
| | | |
+---------------------------------+ | |
|| | |
|| items | |
|| | |
|| | |
|| | |
_++_ | |
\ / | |
\/ | |
+------------+ (sibling) +--------------------------------+ | |
| add|button +---------------+ accordion|list | | |
+------------+ +--------------------------------+ | |
/\ || | |
/__\ || | |
|| || item, activeItem | |
|| _++_ | |
toggleActiveItem || \ / | |
|| \/ | |
|| +--------------------+ | |
|----+ accordion+item | | |
+----+ | | |
+--------------------+ |
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
+---------------------------------+ | |
addItem | | | |
+--------------------->| Parent | | |
| | | | |
| +--------------+------------------+ | |
| ^ | | |
| toggleActiveItem | items, activeItem | |
| | v | |
+-----+------+ ----+-----------------------------+ | |
| add-button | | accordion-list | | |
+------------+ +---+------------------+----------+ | |
^ | | |
| | item, activeItem | |
toggleActiveItem | | |
| v | |
| +--------------------+ | |
| | accordion-item | | |
+--------+ | | |
+--------------------+ |
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 { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
.header { | |
background: #eee; | |
padding: 10px; | |
} | |
.details { | |
padding: 10px 10px 20px 10px; | |
} |
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
{ | |
"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