Skip to content

Commit

Permalink
FIX #16 added tabs component and basic documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasKulhanek committed Apr 27, 2021
1 parent 78f61d9 commit a278c46
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* [Checkbox](#usersguide/checkbox.md)
* [PDB](#usersguide/pdb.md)
* [Quiz](#usersguide/quiz.md)
* [Tabs](#usersguide/tabs.md)
* [Developer's Guide](#developersguide.md)
* [Examples](#examples.md)
* [Hemodynamics Meurs with controls](#example/hemodynamicsmeurs.md)
Expand Down
48 changes: 48 additions & 0 deletions docs/usersguide/tabs.md
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>
1 change: 1 addition & 0 deletions src/elements/markdown.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
<require from="katex/dist/katex.css"></require>
<require from="font-awesome/css/font-awesome.min.css"></require>
<require from="./markdown.css"></require>
<require from="./tabs"></require>
<div ref="mydiv"></div>
</template>
1 change: 1 addition & 0 deletions src/elements/markdownaurelia.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<require from="highlight.js/styles/github.css"></require>
<require from="katex/dist/katex.css"></require>
<require from="./markdown.css"></require>
<require from="./tabs"></require>
<div class="w3-margin">
<!-- this is markdown aurelia component - use in aurelia plugin - otherwise use bdl-markdown -->
<section class="w3-card-2 w3-padding">
Expand Down
5 changes: 5 additions & 0 deletions src/elements/tabs.html
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>
56 changes: 56 additions & 0 deletions src/elements/tabs.js
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;
}
}
}
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function configure(config) {
PLATFORM.moduleName('./elements/markdown-book-au'),
PLATFORM.moduleName('./elements/markdown-app.html'),
PLATFORM.moduleName('./elements/fmi'),
PLATFORM.moduleName('./elements/pdb-pdbe-molstar')
PLATFORM.moduleName('./elements/pdb-pdbe-molstar'),
PLATFORM.moduleName('./elements/tabs')
]);
}

0 comments on commit a278c46

Please sign in to comment.