From 6c4bbf49e85642342b5b44e00bf297ad9f2fb51c Mon Sep 17 00:00:00 2001 From: David Straub Date: Mon, 23 Nov 2020 18:03:59 +0100 Subject: [PATCH] object: better handling of tabs --- src/components/GrampsjsObject.js | 82 +++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 27 deletions(-) diff --git a/src/components/GrampsjsObject.js b/src/components/GrampsjsObject.js index ad0676b8..7def2d5f 100644 --- a/src/components/GrampsjsObject.js +++ b/src/components/GrampsjsObject.js @@ -5,6 +5,20 @@ import '@material/mwc-tab-bar' import { sharedStyles } from '../SharedStyles.js'; +const _allTabs = { + family_list: 'Relationships', + placeref_list: 'Enclosed by', + primary_name: 'Names', + event_ref_list: 'Events', + citation_list: 'Citations', + attribute_list: 'Attributes', + address_list: 'Addresses', + note_list: 'Notes', + media_list: 'Gallery', + urls: 'Internet', + person_ref_list: 'Associations', + backlinks: 'References' +} export class GrampsjsObject extends LitElement { static get styles() { @@ -21,6 +35,8 @@ export class GrampsjsObject extends LitElement { return { data: { type: Object }, strings: { type: Object }, + _currentTabId: {type: Number}, + _currentTab: {type: String}, }; } @@ -28,6 +44,7 @@ export class GrampsjsObject extends LitElement { super(); this.data = {}; this.strings = {}; + this._currentTabId = 0 } @@ -39,44 +56,55 @@ export class GrampsjsObject extends LitElement { ${this.renderProfile()} ${this.renderTabs()} + + ${this.renderTabContent()} `; } renderTabs() { + const tabKeys = this._getTabs() + if (!tabKeys.includes(this._currentTab)) { + [this._currentTab] = tabKeys + } return html` - - ${this._makeTab('family_list', 'Relationships')} - ${this._makeTab('placeref_list', 'Enclosed by')} - ${this._makeTab('primary_name', 'Names')} - ${this._makeTab('event_ref_list', 'Events')} - ${this._makeTab('citation_list', 'Citations')} - ${this._makeTab('attribute_list', 'Attributes')} - ${this._makeTab('address_list', 'Addresses')} - ${this._makeTab('note_list', 'Notes')} - ${this._makeTab('media_list', 'Gallery')} - ${this._makeTab('urls', 'Internet')} - ${this._makeTab('person_ref_list', 'Associations')} - ${this._makeTab('backlinks', 'References')} + + ${tabKeys.map(key => this._makeTab(key))} ` } - _makeTab(key, label) { - if (key in this.data) { - return html` - - - ` - } - return '' - + renderTabContent() { + return html` + ${this._currentTab} + ` } - _handleTabClick(event) { - console.log(event) + _getTabs() { + return Object.keys(_allTabs).filter(key => key in this.data) + } + + _makeTab(key) { + return html` + + + ` + } + + + _handleTabActivated (event) { + this._currentTabId = event.detail.index + } + + _handleTabInteracted (event) { + this._currentTab = event.detail.tabId } _(s) {