forked from TomasKulhanek/aurelia-bodylight-plugin
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX #16 added tabs component and basic documentation
- Loading branch information
1 parent
78f61d9
commit a278c46
Showing
7 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Tabs | ||
|
||
```html | ||
<bdl-tabs idlist="uvod,modelplic,modeltkani,krivkao2,krivkaco2,porovnani" | ||
titlelist="Úvod,Model plic,Model tkání,Křivka O2,KřivkaCO2,Porovnání O2 a CO2"></bdl-tabs> | ||
<div id="uvod"> | ||
uvod | ||
</div> | ||
<div id="modelplic"> | ||
modelplic | ||
</div> | ||
<div id="modeltkani"> | ||
modeltkani | ||
</div> | ||
<div id="krivkao2"> | ||
krivkao2 | ||
</div> | ||
<div id="krivkaco2"> | ||
krivkaco2 | ||
</div> | ||
<div id="porovnani"> | ||
porovnani | ||
</div> | ||
|
||
``` | ||
Creates tabs (buttons) - associated with divs with id, you should define divs later. | ||
If the tab is clicked, the associated div is made visible, others are hidden | ||
|
||
<bdl-tabs idlist="uvod,modelplic,modeltkani,krivkao2,krivkaco2,porovnani" | ||
titlelist="Úvod,Model plic,Model tkání,Křivka O2,KřivkaCO2,Porovnání O2 a CO2"></bdl-tabs> | ||
<div id="uvod"> | ||
uvod | ||
</div> | ||
<div id="modelplic"> | ||
modelplic | ||
</div> | ||
<div id="modeltkani"> | ||
modeltkani | ||
</div> | ||
<div id="krivkao2"> | ||
krivkao2 | ||
</div> | ||
<div id="krivkaco2"> | ||
krivkaco2 | ||
</div> | ||
<div id="porovnani"> | ||
porovnani | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<template> | ||
<div class="w3-bar"> | ||
<button repeat.for="id of ids" class.bind="id.cls" click.delegate="open(id)">${id.title}</button> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import {bindable} from 'aurelia-templating'; | ||
|
||
export class Tabs { | ||
@bindable idlist; | ||
@bindable titlelist; | ||
ids=[]; | ||
activeclass='w3-bar-item w3-button w3-white w3-border-top w3-border-left w3-border-right'; | ||
inactiveclass='w3-bar-item w3-button w3-border-bottom w3-theme-l5'; | ||
bind() { | ||
if (this.idlist) { | ||
//convert comma separated list of ids to array [{id:'id1',title:'id1'}] | ||
this.ids = this.idlist.split(',').map(x => {return {name: x, title: x, cls: this.inactiveclass};}); | ||
if (this.titlelist) { | ||
let titles = this.titlelist.split(','); | ||
//if titles are defined, replace title in the ids array [{id:'id1',title:'title1'}] | ||
for (let i = 0; i < titles.length; i++) { | ||
if (this.ids[i]) this.ids[i].title = titles[i]; | ||
} | ||
} | ||
} | ||
} | ||
attached() { | ||
console.log('tabs component', this); | ||
//open first, hide all no-active | ||
this.open(this.ids[0]); | ||
} | ||
|
||
open(newid) { | ||
if (this.active) { | ||
this.setinactive(this.active); | ||
this.setactive(newid); | ||
this.active = newid; | ||
} else { | ||
for (let id of this.ids) { | ||
if (id !== this.active) {this.setinactive(id);} | ||
} | ||
this.setactive(newid); | ||
this.active = newid; | ||
} | ||
} | ||
|
||
setactive(id) { | ||
let el = document.getElementById(id.name); | ||
if (el) { | ||
el.style.display = 'block'; | ||
id.cls = this.activeclass; | ||
} | ||
} | ||
setinactive(id) { | ||
let el = document.getElementById(id.name); | ||
if (el) { | ||
el.style.display = 'none'; | ||
id.cls = this.inactiveclass; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters