Last active
February 17, 2017 16:44
-
-
Save smfoote/5be44e8c89497b808b76293698193bda to your computer and use it in GitHub Desktop.
Checked
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'; | |
import layout from '../templates/components/toggle-pill'; | |
const CHECKED = 'checked'; | |
export default Ember.Component.extend({ | |
layout, | |
inputId: 123, | |
// Component properties | |
checked: false, | |
// Lifecycle methods | |
didInsertElement() { | |
this.cacheDOMElements(); | |
}, | |
// Ember controlled events | |
click(e) { | |
// A click on the label will actually trigger a separate click event | |
// on the input. So only check for clicks on the input. | |
if (e.target === this.inputEl) { | |
e.stopPropagation(); | |
e.preventDefault(); | |
console.log(this.get(CHECKED)); | |
this.get('onToggle')(!this.get(CHECKED)); | |
} | |
}, | |
// Other methods | |
cacheDOMElements() { | |
this.inputEl = this.$('input')[0]; | |
this.labelEl = this.$('label')[0]; | |
} | |
}); | |
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', | |
isChecked: true, | |
actions: { | |
pillToggled(checked) { | |
console.log('TOGGLED'); | |
// Ember.run.later(() => { | |
this.set('isChecked', !this.get('isChecked')); | |
// }); | |
}, | |
toggle() { | |
this.set('isChecked', !this.get('isChecked')); | |
} | |
} | |
}); |
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.11.0", | |
"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.10.2", | |
"ember-data": "2.11.0", | |
"ember-template-compiler": "2.10.2", | |
"ember-testing": "2.10.2" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment