Skip to content

Instantly share code, notes, and snippets.

@sheriffderek
Last active August 18, 2017 15:49
Show Gist options
  • Save sheriffderek/c933e81129d7b3da39db7eac1ac31e01 to your computer and use it in GitHub Desktop.
Save sheriffderek/c933e81129d7b3da39db7eac1ac31e01 to your computer and use it in GitHub Desktop.
Dynamic CSS class added to component
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'section',
classNames: ['class-from-component-controller'],
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Dynamic CSS class added to component',
exampleClass: 'warning',
anotherClass: 'donald',
});
<style>
.warning {
color: red;
}
.class-from-component-controller {
color: green;
}
.strong-voice {
font-weight: bold;
}
.donald {
color: orange;
}
</style>
<h1>{{appName}}</h1>
<div class='{{exampleClass}}'>message in template with dynamic CSS class</div>
{{#example-component}} {{!-- style added in component js --}}
message in component with internal 'classNames'
{{/example-component}}
{{#example-component classNames=anotherClass class='strong-voice'}}
message in component with explicitly added 'classNames'
{{/example-component}}
{
"version": "0.12.1",
"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.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment