Skip to content

Instantly share code, notes, and snippets.

@locks
Forked from lolmaus/components.my-component.js
Last active April 13, 2018 07:53
Show Gist options
  • Save locks/1311a02d3cc378614fd6f509bcc4611a to your computer and use it in GitHub Desktop.
Save locks/1311a02d3cc378614fd6f509bcc4611a to your computer and use it in GitHub Desktop.
classNames / classNameBindings
import Ember from 'ember';
export default Ember.Component.extend({
classNameBindings: ['colorBoolInternal:purple'],
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export function array(params/*, hash*/) {
return params;
}
export default Ember.Helper.helper(array);
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.red {
color: red;
}
.blue {
color: blue;
}
.purple {
color: purple;
}
<h1>Welcome to {{appName}}</h1>
<label>
{{input type="checkbox" checked=colorBool}}
colorBool
</label>
{{my-component}}
{{! these two seem to be identical }}
{{my-component classBinding = "colorBool:red:blue"}}
{{my-component classNameBindings = "colorBool:red:blue"}}
{{my-component class=(if colorBool "red" "blue")}}
{{! these two seem to be broken (because `params` is frozen in helper?) }}
{{my-component classNameBindings=(array "colorBool:red:blue")}}
{{my-component classNameBindings=(array "colorBool:red:blue") colorBool=colorBool}}
{{! this also works }}
{{my-component colorBoolInternal=true}}
{
"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