Created
September 19, 2016 18:12
-
-
Save lamchau/0f46c8c5ed9808eb2f770cf8cae1b32c to your computer and use it in GitHub Desktop.
simple-checkbox
This file contains hidden or 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 Component from 'ember-component'; | |
import { assert } from 'ember-metal/utils'; | |
const DEFAULT_CLASS_NAME = 'simple-checkbox'; | |
const AVAILABLE_POSITIONS = ['top', 'middle']; | |
export default Component.extend({ | |
classNames: `${DEFAULT_CLASS_NAME}`, | |
classNameBindings: [`disabled:${DEFAULT_CLASS_NAME}--disabled`], | |
autofocus: false, | |
checked: null, | |
disabled: false, | |
position: 'middle', | |
readonly: false, | |
_update() { | |
const componentId = this.get('componentId'); | |
const checkbox = this.$(`#${componentId}`); | |
assert(`Component must have at least one element with an id='{{elementId}}_checkbox'`, checkbox.length); | |
checkbox.prop('checked', Boolean(this.get('checked'))); | |
if (this.get('disabled') || this.get('readonly')) { | |
return; | |
} | |
checkbox.focus(); | |
this.update(); | |
}, | |
click() { | |
this._update(); | |
}, | |
didReceiveAttrs() { | |
assert(`Attribute 'update' must be a function`, typeof this.update === 'function'); | |
const position = this.get('position'); | |
assert(`Unsupported position '${position}'. Available: ${AVAILABLE_POSITIONS.join(', ')}`, AVAILABLE_POSITIONS.indexOf(position) >= 0); | |
}, | |
init() { | |
this._super(...arguments); | |
const elementId = this.get('elementId'); | |
this.set('componentId', `${elementId}_checkbox`); | |
} | |
}); |
This file contains hidden or 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', | |
init() { | |
this._super(...arguments); | |
this.set('model', Ember.Object.create()); | |
} | |
}); |
This file contains hidden or 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: 10pt; | |
} | |
.simple-checkbox__input--top { | |
vertical-align: top; | |
} | |
.simple-checkbox__input--middle { | |
vertical-align: middle; | |
} | |
.simple-checkbox__content { | |
display: inline-block; | |
} | |
.simple-checkbox__image { | |
display: inline-block; | |
vertical-align: middle; | |
} | |
.simple-checkbox__text { | |
display: inline-block; | |
} | |
.simple-checkbox__text--hint { | |
color: silver; | |
} | |
textarea { | |
height: 150px; | |
width: 200px; | |
margin: 5px 5px 0px 20px; | |
} |
This file contains hidden or 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.5", | |
"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.8.0", | |
"ember-data": "2.8.0", | |
"ember-template-compiler": "2.8.0", | |
"ember-testing": "2.8.0" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment