Skip to content

Instantly share code, notes, and snippets.

@camskene
Last active June 12, 2018 20:13
Show Gist options
  • Save camskene/5eb05dfd05c277c602b731324e471e8b to your computer and use it in GitHub Desktop.
Save camskene/5eb05dfd05c277c602b731324e471e8b to your computer and use it in GitHub Desktop.
My Accordion
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
myAccordianConfig: Ember.computed(function() {
return [
{
label: 'numero uno',
isExpanded: false,
children: [
{
label: '1.1',
isExpanded: true,
}
]
},
{
label: '222',
isExpanded: false,
},
];
}),
actions: {
expandAll() {
this.get('myAccordianConfig').setEach('isExpanded', true);
},
collapseAll() {
this.get('myAccordianConfig').setEach('isExpanded', false);
},
}
});
import Ember from 'ember';
export default Ember.Component.extend({
configuration: undefined,
actions: {
onExpand(item) {
Ember.set(item, 'isExpanded', !item.isExpanded);
},
},
});
{{#each configuration as |item|}}
<h3 {{action 'onExpand' item}}>
{{item.label}}
{{if item.isExpanded '+' '–'}}
</h3>
{{#if item.isExpanded}}
{{yield}}
{{/if}}
{{/each}}
<button {{action 'expandAll'}}>Expand all</button>
<button {{action 'collapseAll'}}>Collapse all</button>
{{#my-accordion
configuration=myAccordianConfig
as |accordion|
}}
{{#accordion.header}}
Hello World
{{/accordion.header}}
{{/my-accordion}}
{
"version": "0.14.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": true,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "2.18.2",
"ember-template-compiler": "2.18.2",
"ember-testing": "2.18.2"
},
"addons": {
"ember-data": "2.18.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment