Skip to content

Instantly share code, notes, and snippets.

@lacek
Created December 31, 2019 10:06
Show Gist options
  • Save lacek/6d30f11baf761a4c6c4be50be79fcd49 to your computer and use it in GitHub Desktop.
Save lacek/6d30f11baf761a4c6c4be50be79fcd49 to your computer and use it in GitHub Desktop.
Ember Bootstrap Tooltip
import Ember from 'ember';
import { computed } from '@ember/object';
export default Ember.Component.extend({
classNames: 'grid-value',
attributeBindings: ['style'],
value: 0,
style: computed('value', function() {
let value = this.get('value');
return Ember.String.htmlSafe(`background-color: rgb(${value}, 0, 0)`);
}),
});
import Ember from 'ember';
export default Ember.Controller.extend({
init() {
this._super(...arguments);
this.data = this.getRandomData();
},
rows: 9,
columns: 9,
getRandomData() {
let rows = parseInt(this.get('rows'));
let columns = parseInt(this.get('columns'));
return [...Array(rows)].map(() => {
return [...Array(columns)].map(() => {
return ~~(Math.random() * 256);
});
});
},
actions: {
update() {
this.set('data', this.getRandomData());
}
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
table {
margin-top: 20px;
}
td {
width: 50px;
height: 50px;
}
.grid-value {
width: 48px;
height: 48px;
color: #ccc;
padding-top: 12px;
text-align: center;
}
<div id="ember-bootstrap-wormhole"></div>
<form class="form-inline" {{action "update" on="submit"}}>
<div class="form-group">
<label>Rows</label>
{{input type="number" class="form-control" min="1" value=rows}}
</div>
<div class="form-group">
<label>Columns</label>
{{input type="number" class="form-control" min="1" value=columns}}
</div>
<button type="submit" class="btn btn-default">Update</button>
</form>
<table>
<tbody>
{{#each data as |row rowIdx|}}
<tr>
{{#each row as |col colIdx|}}
<td>
{{#grid-value value=col}}{{rowIdx}},{{colIdx}}{{/grid-value}}
{{bs-tooltip title=col placement="right"}}
</td>
{{/each}}
</tr>
{{/each}}
</tbody>
</table>
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "2.18.2",
"ember-template-compiler": "2.18.2",
"ember-testing": "2.18.2"
},
"addons": {
"ember-data": "2.18.5",
"ember-bootstrap": "3.1.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment