Skip to content

Instantly share code, notes, and snippets.

@camskene
Last active September 20, 2017 16:15
Show Gist options
  • Save camskene/b38352789f97c40173f7cb21c4240463 to your computer and use it in GitHub Desktop.
Save camskene/b38352789f97c40173f7cb21c4240463 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
});
import Ember from 'ember';
export default Ember.Component.extend({
numRowClicks: 0,
actions: {
onClick(e) {
this.set('numRowClicks', this.get('numRowClicks') + 1);
},
},
});
<table>
<caption>This is a table</caption>
{{tr-component on-click=(action 'onClick')}}
</table>
<p>Number of row clicks: {{numRowClicks}}</p>
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
table {
border-collapse: collapse;
table-layout: fixed;
width: 100%;
}
tr.is-focused {
outline: 1px dotted;
}
td {
border: 1px solid #ccc;
padding: 8px;
}
.visually-hidden-cell {
width: 0;
}
.secret-button {
position: absolute;
top: -9999px;
}
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{{my-component}}
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'tr',
isExpanded: false,
didInsertElement() {
this._super(...arguments);
let $secretButton = this.$('.secret-button');
$secretButton.on('focusin focusout', function() {
$(this).closest('tr').toggleClass('is-focused');
})
},
click() {
if (this.get('on-click')) {
this.get('on-click')();
this.toggleProperty('isExpanded');
}
},
actions: {
clickButton(e) {
console.log('button clicked');
e.stopPropagation();
},
clickLink(e) {
e.stopPropagation();
},
},
});
{{#if on-click}}
<td class="visually-hidden-cell">
<button class="secret-button" aria-expanded="{{isExpanded}}">{{if isExpanded 'Collapse' 'Expand'}} Summary Panel</button>
</td>
{{/if}}
<td>
<button onclick={{action 'clickButton'}}>button</button>
</td>
<td>Cell</td>
<td>
<button onclick={{action 'clickLink'}}>button</button>
</td>
{
"version": "0.12.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": true,
"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