Skip to content

Instantly share code, notes, and snippets.

@dhindurthy
Last active November 20, 2017 16:23
Show Gist options
  • Save dhindurthy/1e4455cdd6ea5f14ffc62a0ebf41d16e to your computer and use it in GitHub Desktop.
Save dhindurthy/1e4455cdd6ea5f14ffc62a0ebf41d16e to your computer and use it in GitHub Desktop.
icon-button
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['icon-button'],
classNameBindings: [
'disabled:disabled:'
],
attributeBindings: [
'aria-controls',
'aria-describedby',
'aria-expanded',
'aria-pressed',
'aria-selected',
'aria-haspopup',
'aria-labelledby',
'label:aria-label',
'tabindex',
'disabled',
'name',
'title'
],
icon: '',
iconName: Ember.computed('icon', function() {
let iconName = 'fa-'+ this.get('icon');
return iconName;
}),
tagName: 'button',
icon: '',
size: '',
spin: '',
pulse: '',
border: false,
rotate: 0,
click: function(event) {
this.sendAction('action', this, event);
this._super(arguments);
},
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Controller.extend({
actions : {
hitAction: function() {
alert('hit the action donkey');
}
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.icon-button {
border: 1px solid transparent;
background: none;
color: orange;
}
.icon-button:hover {
cursor: pointer;
}
<i class="fa {{iconName}} {{spin}} {{pulse}} {{size}} " aria-hidden="true"></i>
<h5>Component using font-awesome icons</h5>
{{icon-button icon="times" action="hitAction"}}
{{icon-button icon="spinner" size='fa-2x' spin="fa-spin" action="hitAction"}}
{{icon-button icon="spinner" size='fa-2x' pulse='fa-pulse' action="hitAction"}}
import Ember from 'ember';
export default function destroyApp(application) {
Ember.run(application, 'destroy');
}
import Resolver from '../../resolver';
import config from '../../config/environment';
const resolver = Resolver.create();
resolver.namespace = {
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix
};
export default resolver;
import Ember from 'ember';
import Application from '../../app';
import config from '../../config/environment';
const { run } = Ember;
const assign = Ember.assign || Ember.merge;
export default function startApp(attrs) {
let application;
let attributes = assign({rootElement: "#test-root"}, config.APP);
attributes = assign(attributes, attrs); // use defaults, but you can override;
run(() => {
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
return application;
}
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
moduleForComponent('icon-button', 'Initally', {
integration: true
});
test('it renders', function(assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });
this.render(hbs`{{icon-button}}`);
assert.equal(this.$().text().trim(), '');
// Template block usage:
this.render(hbs`
{{icon-button icon="times"}}
`);
assert.equal(this.$().text().trim(), '');
});
moduleForComponent('icon-button', 'Change the appearance', {
integration: true
});
test('it assigns the size to the image', function(assert) {
this.render(hbs`{{icon-button icon="spinner" size='fa-2x' }}`);
assert.equal(this.$('i').hasClass('fa-2x'), true);
});
test('it assigns the spin to the image', function(assert) {
this.render(hbs`{{icon-button icon="spinner" spin='fa-spin' }}`);
assert.equal(this.$('i').hasClass('fa-spin'), true);
});
test('it not assigns the pulse to the image', function(assert) {
this.render(hbs`{{icon-button icon="spinner" pulse='fa-pulse'}}`);
assert.equal(this.$('i').hasClass('fa-pulse'), true);
});
test('triggers the function', function(assert) {
this.render(hbs `{{icon-button icon="times" action="hitAction"}}`);
this.set('actions.hitAction', function() {
assert.ok(true, "clickable button");
});
assert.equal(this.$().find('button').length, 1, "icon button loaded");
//click(this.$().find('button'));
(this.$().find('button')).trigger( "click" );
});
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
setResolver(resolver);
{
"version": "0.12.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"devDependencies": {
"ember-font-awesome": "^3.0.5"
},
"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",
"ember-font-awesome": "https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css"
},
"addons": {
"ember-data": "2.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment