Skip to content

Instantly share code, notes, and snippets.

@willrax
Last active March 9, 2016 20:41
Show Gist options
  • Save willrax/bff56678d04b6eaf8999 to your computer and use it in GitHub Desktop.
Save willrax/bff56678d04b6eaf8999 to your computer and use it in GitHub Desktop.
custom-not-custom-component
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{#x-list headerText="Click Me"}}
I am Content
{{/x-list}}
<br>
<br>
{{#x-list headerComponent="custom-header"
headerAttrs=(hash title="Oh hai")}}
I am Content
{{/x-list}}
import Ember from 'ember';
const { computed } = Ember;
export default Ember.Component.extend({
headerAttrs: null,
h1: computed.readOnly('headerAttrs.title'),
h2: computed.readOnly('headerAttrs.subtitle')
});
{
"version": "0.6.3",
"EmberENV": {
"FEATURES": {}
},
"options": {
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.1/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.0/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.1/ember-template-compiler.js"
}
}
import Ember from 'ember';
export default Ember.Component.extend({
text: Ember.computed.alias('headerAttrs.text')
});
import Ember from 'ember';
const { computed } = Ember;
export default Ember.Component.extend({
headerComponent: 'x-list-header',
headerText: '',
headerAttrs: computed('headerText', function() {
return {
text: this.get('headerText')
}
}),
isExpanded: false,
actions: {
toggle() {
this.toggleProperty('isExpanded');
}
}
});
{{#if isExpanded}}
<div class="trigger"
onclick={{action "toggle"}}>
{{component
headerComponent
headerAttrs=headerAttrs}}
</div>
{{yield inverse=true}}
{{else}}
<div class="trigger"
onclick={{action "toggle"}}>
{{component
headerComponent
headerAttrs=headerAttrs}}
</div>
{{/if}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment