| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502 | 
							- /*!
 
-  * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
 
-  * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
 
-  * v1.0.0-beta.97
 
-  */
 
- import { h, Host } from "@stencil/core";
 
- import { getElementDir, filterDirectChildren } from "../../utils/dom";
 
- import { createObserver } from "../../utils/observers";
 
- /**
 
-  * @slot - A slot for adding `calcite-tab-title`s.
 
-  */
 
- export class TabNav {
 
-   constructor() {
 
-     /**
 
-      * @internal
 
-      */
 
-     this.scale = "m";
 
-     /**
 
-      * @internal
 
-      */
 
-     this.layout = "inline";
 
-     /**
 
-      * @internal
 
-      */
 
-     this.position = "bottom";
 
-     /**
 
-      * @internal
 
-      */
 
-     this.bordered = false;
 
-     this.animationActiveDuration = 0.3;
 
-     this.resizeObserver = createObserver("resize", () => {
 
-       // remove active indicator transition duration during resize to prevent wobble
 
-       this.activeIndicatorEl.style.transitionDuration = "0s";
 
-       this.updateActiveWidth();
 
-       this.updateOffsetPosition();
 
-     });
 
-     //--------------------------------------------------------------------------
 
-     //
 
-     //  Private Methods
 
-     //
 
-     //--------------------------------------------------------------------------
 
-     this.handleContainerScroll = () => {
 
-       // remove active indicator transition duration while container is scrolling to prevent wobble
 
-       this.activeIndicatorEl.style.transitionDuration = "0s";
 
-       this.updateOffsetPosition();
 
-     };
 
-   }
 
-   async selectedTabChanged() {
 
-     if (localStorage &&
 
-       this.storageId &&
 
-       this.selectedTab !== undefined &&
 
-       this.selectedTab !== null) {
 
-       localStorage.setItem(`calcite-tab-nav-${this.storageId}`, JSON.stringify(this.selectedTab));
 
-     }
 
-     this.calciteInternalTabChange.emit({
 
-       tab: this.selectedTab
 
-     });
 
-     this.selectedTabEl = await this.getTabTitleById(this.selectedTab);
 
-   }
 
-   selectedTabElChanged() {
 
-     this.updateOffsetPosition();
 
-     this.updateActiveWidth();
 
-     // reset the animation time on tab selection
 
-     this.activeIndicatorEl.style.transitionDuration = `${this.animationActiveDuration}s`;
 
-   }
 
-   //--------------------------------------------------------------------------
 
-   //
 
-   //  Lifecycle
 
-   //
 
-   //--------------------------------------------------------------------------
 
-   connectedCallback() {
 
-     var _a;
 
-     this.parentTabsEl = this.el.closest("calcite-tabs");
 
-     (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el);
 
-   }
 
-   disconnectedCallback() {
 
-     var _a;
 
-     (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
 
-   }
 
-   componentWillLoad() {
 
-     const storageKey = `calcite-tab-nav-${this.storageId}`;
 
-     if (localStorage && this.storageId && localStorage.getItem(storageKey)) {
 
-       const storedTab = JSON.parse(localStorage.getItem(storageKey));
 
-       this.selectedTab = storedTab;
 
-     }
 
-   }
 
-   componentWillRender() {
 
-     const { parentTabsEl } = this;
 
-     this.layout = parentTabsEl === null || parentTabsEl === void 0 ? void 0 : parentTabsEl.layout;
 
-     this.position = parentTabsEl === null || parentTabsEl === void 0 ? void 0 : parentTabsEl.position;
 
-     this.scale = parentTabsEl === null || parentTabsEl === void 0 ? void 0 : parentTabsEl.scale;
 
-     this.bordered = parentTabsEl === null || parentTabsEl === void 0 ? void 0 : parentTabsEl.bordered;
 
-     // fix issue with active tab-title not lining up with blue indicator
 
-     if (this.selectedTabEl) {
 
-       this.updateOffsetPosition();
 
-     }
 
-   }
 
-   componentDidRender() {
 
-     // if every tab title is active select the first tab.
 
-     if (this.tabTitles.length &&
 
-       this.tabTitles.every((title) => !title.active) &&
 
-       !this.selectedTab) {
 
-       this.tabTitles[0].getTabIdentifier().then((tab) => {
 
-         this.calciteInternalTabChange.emit({
 
-           tab
 
-         });
 
-       });
 
-     }
 
-   }
 
-   render() {
 
-     const dir = getElementDir(this.el);
 
-     const width = `${this.indicatorWidth}px`;
 
-     const offset = `${this.indicatorOffset}px`;
 
-     const indicatorStyle = dir !== "rtl" ? { width, left: offset } : { width, right: offset };
 
-     return (h(Host, { role: "tablist" }, h("div", { class: "tab-nav", onScroll: this.handleContainerScroll, ref: (el) => (this.tabNavEl = el) }, h("div", { class: "tab-nav-active-indicator-container", ref: (el) => (this.activeIndicatorContainerEl = el) }, h("div", { class: "tab-nav-active-indicator", ref: (el) => (this.activeIndicatorEl = el), style: indicatorStyle })), h("slot", null))));
 
-   }
 
-   //--------------------------------------------------------------------------
 
-   //
 
-   //  Event Listeners
 
-   //
 
-   //--------------------------------------------------------------------------
 
-   focusPreviousTabHandler(event) {
 
-     const currentIndex = this.getIndexOfTabTitle(event.target, this.enabledTabTitles);
 
-     const previousTab = this.enabledTabTitles[currentIndex - 1] ||
 
-       this.enabledTabTitles[this.enabledTabTitles.length - 1];
 
-     previousTab === null || previousTab === void 0 ? void 0 : previousTab.focus();
 
-     event.stopPropagation();
 
-     event.preventDefault();
 
-   }
 
-   focusNextTabHandler(event) {
 
-     const currentIndex = this.getIndexOfTabTitle(event.target, this.enabledTabTitles);
 
-     const nextTab = this.enabledTabTitles[currentIndex + 1] || this.enabledTabTitles[0];
 
-     nextTab === null || nextTab === void 0 ? void 0 : nextTab.focus();
 
-     event.stopPropagation();
 
-     event.preventDefault();
 
-   }
 
-   internalActivateTabHandler(event) {
 
-     this.selectedTab = event.detail.tab
 
-       ? event.detail.tab
 
-       : this.getIndexOfTabTitle(event.target);
 
-     event.stopPropagation();
 
-     event.preventDefault();
 
-   }
 
-   activateTabHandler(event) {
 
-     this.calciteTabChange.emit({
 
-       tab: this.selectedTab
 
-     });
 
-     event.stopPropagation();
 
-     event.preventDefault();
 
-   }
 
-   /**
 
-    * Check for active tabs on register and update selected
 
-    *
 
-    * @param event
 
-    */
 
-   updateTabTitles(event) {
 
-     if (event.target.active) {
 
-       this.selectedTab = event.detail;
 
-     }
 
-   }
 
-   globalInternalTabChangeHandler(event) {
 
-     if (this.syncId &&
 
-       event.target !== this.el &&
 
-       event.target.syncId === this.syncId &&
 
-       this.selectedTab !== event.detail.tab) {
 
-       this.selectedTab = event.detail.tab;
 
-     }
 
-     event.stopPropagation();
 
-   }
 
-   iconStartChangeHandler() {
 
-     this.updateActiveWidth();
 
-   }
 
-   updateOffsetPosition() {
 
-     var _a, _b, _c, _d, _e;
 
-     const dir = getElementDir(this.el);
 
-     const navWidth = (_a = this.activeIndicatorContainerEl) === null || _a === void 0 ? void 0 : _a.offsetWidth;
 
-     const tabLeft = (_b = this.selectedTabEl) === null || _b === void 0 ? void 0 : _b.offsetLeft;
 
-     const tabWidth = (_c = this.selectedTabEl) === null || _c === void 0 ? void 0 : _c.offsetWidth;
 
-     const offsetRight = navWidth - (tabLeft + tabWidth);
 
-     this.indicatorOffset =
 
-       dir !== "rtl" ? tabLeft - ((_d = this.tabNavEl) === null || _d === void 0 ? void 0 : _d.scrollLeft) : offsetRight + ((_e = this.tabNavEl) === null || _e === void 0 ? void 0 : _e.scrollLeft);
 
-   }
 
-   updateActiveWidth() {
 
-     var _a;
 
-     this.indicatorWidth = (_a = this.selectedTabEl) === null || _a === void 0 ? void 0 : _a.offsetWidth;
 
-   }
 
-   getIndexOfTabTitle(el, tabTitles = this.tabTitles) {
 
-     // In most cases, since these indexes correlate with tab contents, we want to consider all tab titles.
 
-     // However, when doing relative index operations, it makes sense to pass in this.enabledTabTitles as the 2nd arg.
 
-     return tabTitles.indexOf(el);
 
-   }
 
-   async getTabTitleById(id) {
 
-     return Promise.all(this.tabTitles.map((el) => el.getTabIdentifier())).then((ids) => {
 
-       return this.tabTitles[ids.indexOf(id)];
 
-     });
 
-   }
 
-   get tabTitles() {
 
-     return filterDirectChildren(this.el, "calcite-tab-title");
 
-   }
 
-   get enabledTabTitles() {
 
-     return filterDirectChildren(this.el, "calcite-tab-title:not([disabled])");
 
-   }
 
-   static get is() { return "calcite-tab-nav"; }
 
-   static get encapsulation() { return "shadow"; }
 
-   static get originalStyleUrls() {
 
-     return {
 
-       "$": ["tab-nav.scss"]
 
-     };
 
-   }
 
-   static get styleUrls() {
 
-     return {
 
-       "$": ["tab-nav.css"]
 
-     };
 
-   }
 
-   static get properties() {
 
-     return {
 
-       "storageId": {
 
-         "type": "string",
 
-         "mutable": false,
 
-         "complexType": {
 
-           "original": "string",
 
-           "resolved": "string",
 
-           "references": {}
 
-         },
 
-         "required": false,
 
-         "optional": false,
 
-         "docs": {
 
-           "tags": [],
 
-           "text": "Specifies the name when saving selected `calcite-tab` data to `localStorage`."
 
-         },
 
-         "attribute": "storage-id",
 
-         "reflect": true
 
-       },
 
-       "syncId": {
 
-         "type": "string",
 
-         "mutable": false,
 
-         "complexType": {
 
-           "original": "string",
 
-           "resolved": "string",
 
-           "references": {}
 
-         },
 
-         "required": false,
 
-         "optional": false,
 
-         "docs": {
 
-           "tags": [],
 
-           "text": "Specifies text to update multiple components to keep in sync if one changes."
 
-         },
 
-         "attribute": "sync-id",
 
-         "reflect": true
 
-       },
 
-       "scale": {
 
-         "type": "string",
 
-         "mutable": true,
 
-         "complexType": {
 
-           "original": "Scale",
 
-           "resolved": "\"l\" | \"m\" | \"s\"",
 
-           "references": {
 
-             "Scale": {
 
-               "location": "import",
 
-               "path": "../interfaces"
 
-             }
 
-           }
 
-         },
 
-         "required": false,
 
-         "optional": false,
 
-         "docs": {
 
-           "tags": [{
 
-               "name": "internal",
 
-               "text": undefined
 
-             }],
 
-           "text": ""
 
-         },
 
-         "attribute": "scale",
 
-         "reflect": true,
 
-         "defaultValue": "\"m\""
 
-       },
 
-       "layout": {
 
-         "type": "string",
 
-         "mutable": true,
 
-         "complexType": {
 
-           "original": "TabLayout",
 
-           "resolved": "\"center\" | \"inline\"",
 
-           "references": {
 
-             "TabLayout": {
 
-               "location": "import",
 
-               "path": "../tabs/interfaces"
 
-             }
 
-           }
 
-         },
 
-         "required": false,
 
-         "optional": false,
 
-         "docs": {
 
-           "tags": [{
 
-               "name": "internal",
 
-               "text": undefined
 
-             }],
 
-           "text": ""
 
-         },
 
-         "attribute": "layout",
 
-         "reflect": true,
 
-         "defaultValue": "\"inline\""
 
-       },
 
-       "position": {
 
-         "type": "string",
 
-         "mutable": true,
 
-         "complexType": {
 
-           "original": "TabPosition",
 
-           "resolved": "\"above\" | \"below\" | \"bottom\" | \"top\"",
 
-           "references": {
 
-             "TabPosition": {
 
-               "location": "import",
 
-               "path": "../tabs/interfaces"
 
-             }
 
-           }
 
-         },
 
-         "required": false,
 
-         "optional": false,
 
-         "docs": {
 
-           "tags": [{
 
-               "name": "internal",
 
-               "text": undefined
 
-             }],
 
-           "text": ""
 
-         },
 
-         "attribute": "position",
 
-         "reflect": true,
 
-         "defaultValue": "\"bottom\""
 
-       },
 
-       "bordered": {
 
-         "type": "boolean",
 
-         "mutable": true,
 
-         "complexType": {
 
-           "original": "boolean",
 
-           "resolved": "boolean",
 
-           "references": {}
 
-         },
 
-         "required": false,
 
-         "optional": false,
 
-         "docs": {
 
-           "tags": [{
 
-               "name": "internal",
 
-               "text": undefined
 
-             }],
 
-           "text": ""
 
-         },
 
-         "attribute": "bordered",
 
-         "reflect": true,
 
-         "defaultValue": "false"
 
-       },
 
-       "indicatorOffset": {
 
-         "type": "number",
 
-         "mutable": true,
 
-         "complexType": {
 
-           "original": "number",
 
-           "resolved": "number",
 
-           "references": {}
 
-         },
 
-         "required": false,
 
-         "optional": false,
 
-         "docs": {
 
-           "tags": [{
 
-               "name": "internal",
 
-               "text": undefined
 
-             }],
 
-           "text": ""
 
-         },
 
-         "attribute": "indicator-offset",
 
-         "reflect": false
 
-       },
 
-       "indicatorWidth": {
 
-         "type": "number",
 
-         "mutable": true,
 
-         "complexType": {
 
-           "original": "number",
 
-           "resolved": "number",
 
-           "references": {}
 
-         },
 
-         "required": false,
 
-         "optional": false,
 
-         "docs": {
 
-           "tags": [{
 
-               "name": "internal",
 
-               "text": undefined
 
-             }],
 
-           "text": ""
 
-         },
 
-         "attribute": "indicator-width",
 
-         "reflect": false
 
-       }
 
-     };
 
-   }
 
-   static get states() {
 
-     return {
 
-       "selectedTab": {},
 
-       "selectedTabEl": {}
 
-     };
 
-   }
 
-   static get events() {
 
-     return [{
 
-         "method": "calciteTabChange",
 
-         "name": "calciteTabChange",
 
-         "bubbles": true,
 
-         "cancelable": false,
 
-         "composed": true,
 
-         "docs": {
 
-           "tags": [{
 
-               "name": "see",
 
-               "text": "[TabChangeEventDetail](https://github.com/Esri/calcite-components/blob/master/src/components/tab/interfaces.ts#L1)"
 
-             }],
 
-           "text": "Emits when the selected `calcite-tab` changes."
 
-         },
 
-         "complexType": {
 
-           "original": "TabChangeEventDetail",
 
-           "resolved": "TabChangeEventDetail",
 
-           "references": {
 
-             "TabChangeEventDetail": {
 
-               "location": "import",
 
-               "path": "../tab/interfaces"
 
-             }
 
-           }
 
-         }
 
-       }, {
 
-         "method": "calciteInternalTabChange",
 
-         "name": "calciteInternalTabChange",
 
-         "bubbles": true,
 
-         "cancelable": false,
 
-         "composed": true,
 
-         "docs": {
 
-           "tags": [{
 
-               "name": "internal",
 
-               "text": undefined
 
-             }],
 
-           "text": ""
 
-         },
 
-         "complexType": {
 
-           "original": "TabChangeEventDetail",
 
-           "resolved": "TabChangeEventDetail",
 
-           "references": {
 
-             "TabChangeEventDetail": {
 
-               "location": "import",
 
-               "path": "../tab/interfaces"
 
-             }
 
-           }
 
-         }
 
-       }];
 
-   }
 
-   static get elementRef() { return "el"; }
 
-   static get watchers() {
 
-     return [{
 
-         "propName": "selectedTab",
 
-         "methodName": "selectedTabChanged"
 
-       }, {
 
-         "propName": "selectedTabEl",
 
-         "methodName": "selectedTabElChanged"
 
-       }];
 
-   }
 
-   static get listeners() {
 
-     return [{
 
-         "name": "calciteInternalTabsFocusPrevious",
 
-         "method": "focusPreviousTabHandler",
 
-         "target": undefined,
 
-         "capture": false,
 
-         "passive": false
 
-       }, {
 
-         "name": "calciteInternalTabsFocusNext",
 
-         "method": "focusNextTabHandler",
 
-         "target": undefined,
 
-         "capture": false,
 
-         "passive": false
 
-       }, {
 
-         "name": "calciteInternalTabsActivate",
 
-         "method": "internalActivateTabHandler",
 
-         "target": undefined,
 
-         "capture": false,
 
-         "passive": false
 
-       }, {
 
-         "name": "calciteTabsActivate",
 
-         "method": "activateTabHandler",
 
-         "target": undefined,
 
-         "capture": false,
 
-         "passive": false
 
-       }, {
 
-         "name": "calciteInternalTabTitleRegister",
 
-         "method": "updateTabTitles",
 
-         "target": undefined,
 
-         "capture": false,
 
-         "passive": false
 
-       }, {
 
-         "name": "calciteInternalTabChange",
 
-         "method": "globalInternalTabChangeHandler",
 
-         "target": "body",
 
-         "capture": false,
 
-         "passive": false
 
-       }, {
 
-         "name": "calciteInternalTabIconChanged",
 
-         "method": "iconStartChangeHandler",
 
-         "target": undefined,
 
-         "capture": false,
 
-         "passive": false
 
-       }];
 
-   }
 
- }
 
 
  |