This repository was archived by the owner on Sep 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhydrofoil-resource-tabs.ts
47 lines (39 loc) · 1.62 KB
/
hydrofoil-resource-tabs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import HydrofoilMultiResourceView from '@hydrofoil/hydrofoil-shell/hydrofoil-multi-resource-view'
import { IronPagesElement } from '@polymer/iron-pages/iron-pages'
import { html, query } from 'lit-element'
import { repeat } from 'lit-html/directives/repeat'
import '@polymer/iron-pages/iron-pages'
import '@polymer/paper-icon-button/paper-icon-button'
import '@polymer/paper-tabs/paper-tabs'
/**
* An implementation of `<hydrofoil-multi-resource-view>` in the form of Material design tabs
* item.
*
* @customElement
*/
export default class HydrofoilResourceTabs extends HydrofoilMultiResourceView {
@query('iron-pages')
private pages: IronPagesElement
protected areSame (left, right) {
return left && right && left.id === right.id
}
protected renderAll () {
const renderTab = (res) =>
html`<paper-tab>${this.getHeader(res)}
${this.areSame(res, this.root)
? ''
: html`<paper-icon-button icon="close" @click="${this.close(res)}"></paper-icon-button>`}
</paper-tab>`
return html`
<paper-tabs @selected-changed="${this.selectPage}" .selected="${this.displayedResources.lastIndexOf(this.current)}">
${repeat(this.displayedResources, renderTab)}
</paper-tabs>
<iron-pages .selected="${this.displayedResources.lastIndexOf(this.current)}">
${repeat(this.displayedResources, (res) => html`<div>${this.renderModel(res)}</div>`)}
</iron-pages>`
}
private selectPage (e: CustomEvent) {
this.pages.select(e.detail.value)
}
}
customElements.define('hydrofoil-resource-tabs', HydrofoilResourceTabs)