Skip to content

Instantly share code, notes, and snippets.

@dhindurthy
Last active February 23, 2018 18:52
Show Gist options
  • Save dhindurthy/405452476bc8ab10420630661adb72b7 to your computer and use it in GitHub Desktop.
Save dhindurthy/405452476bc8ab10420630661adb72b7 to your computer and use it in GitHub Desktop.
contextual-tabs
import Ember from 'ember';
export default Ember.Component.extend({
ariaRole: 'tablist',
tabList:[],
actions:{
clickOnTab: function(tab){
this.sendAction('clickOnTab', tab);
let tabList = this.get('tabList');
for(var i=0;i<tabList.length;i++){
this.$('#'+tabList[i].id).removeClass('active');
if(tabList[i].id === tab.id){
this.$('#'+tabList[i].id).addClass('active');
}
}
}
}
});
import Ember from 'ember';
export default Ember.Component.extend({
classNames:['cx-tabpanel'],
idOfpanel:'',
ariaRole: 'tabpanel',
didReceiveAttrs() {
this.set('isVisible', false);
if(this.get('idOfpanel')===this.get('activeTabAsPerTabToPanel')){
this.set('isVisible', true);
}
},
click: function() {
this.sendAction('clickOnPanel', this.get('idOfpanel'));
}
});
import Ember from 'ember';
export default Ember.Component.extend({
activeTabAsPerTabs:'inse',
actions:{
changePanel: function(tab){
let tabList = this.get('tabList');
for(var i=0;i<tabList.length;i++){
if(tabList[i].id === tab.id){
this.set("activeTabAsPerTabs",tab.id);
}
}
},
clickOnPanel: function(idOfpanel) {
/** click in any panel is reported here with the idOfpanel**/
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Controller.extend({
listOfTabs: [{
"name":"Animals",
"id":"anim"
},{
"name":"Birds",
"id":"bird"
},{
"name":"Fish",
"id":"fish"
},{
"name":"Insects",
"id":"inse"
}]
});
import Ember from 'ember';
export default Ember.Route.extend({
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
font-family:"Comic Sans MS", cursive, sans-serif;
}
ul {
list-style-type: none;
padding:0 5px 5px 5px;
padding: 0;
}
li {
display: inline;
padding:0 5px 5px 5px;
border-bottom: 3px solid gray;
transition: 0.5s ease;
cursor: pointer;
}
.cx-tabpanel {
padding:0 8px 8px 8px;
}
li.active {
border-bottom: 3px solid #F08080;
background-color:#77EDF4;
transition: 0.5s ease;
color:#5D6D7E;
}
<br>
<br>
{{outlet}}
<br>
<br>
<ul>
{{#each tabList as |tab|}}
<li role="tab" {{action "clickOnTab" tab}} id={{tab.id}}>{{tab.name}}{{tab.active}}</li>
{{/each}}
</ul>
{{cx-tablist tabList=tabList clickOnTab="changePanel"}}
{{yield
(hash
panelBody=(component nameOtherComponent tabList=tabList activeTabAsPerTabToPanel=activeTabAsPerTabs clickOnPanel=(action "clickOnPanel"))
)
}}
{{#cx-tabs tabList=listOfTabs nameOtherComponent="cx-tabpanel" as |tabs|}}
{{#tabs.panelBody idOfpanel="anim" }}
This is a tab Animals
{{/tabs.panelBody}}
{{#tabs.panelBody idOfpanel="bird" }}
This is a tab Birdies
{{/tabs.panelBody}}
{{#tabs.panelBody idOfpanel="fish" }}
This is a tab Fishies
{{/tabs.panelBody}}
{{#tabs.panelBody idOfpanel="inse" }}
This is a tab Insecticidies
{{/tabs.panelBody}}
{{/cx-tabs}}
{
"version": "0.13.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.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2"
},
"addons": {
"ember-data": "2.16.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment