123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- /*!
- * 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 { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client/index.js';
- import { c as getElementDir, m as filterDirectChildren } from './dom.js';
- import { c as createObserver } from './observers.js';
- const tabNavCss = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{position:relative;display:flex}:host([scale=s]){min-block-size:1.5rem}:host([scale=m]){min-block-size:2rem}:host([scale=l]){min-block-size:2.75rem}.tab-nav{display:flex;inline-size:100%;justify-content:flex-start;overflow:auto}.tab-nav-active-indicator-container{position:absolute;inset-inline:0px;inset-block-end:0px;block-size:0.125rem;inline-size:100%;overflow:hidden}.tab-nav-active-indicator{position:absolute;inset-block-end:0px;display:block;block-size:0.125rem;background-color:var(--calcite-ui-brand);transition-property:all;transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-duration:150ms;transition-timing-function:cubic-bezier(0, 0, 0.2, 1)}:host([position=below]) .tab-nav-active-indicator{inset-block-end:unset;inset-block-start:0px}:host([position=bottom]) .tab-nav-active-indicator{inset-block-end:unset;inset-block-start:0px}:host([position=below]) .tab-nav-active-indicator-container{inset-block-start:0px;inset-block-end:unset}:host([position=bottom]) .tab-nav-active-indicator-container{inset-block-end:unset;inset-block-start:0px}:host([bordered]) .tab-nav-active-indicator-container{inset-block-end:unset}:host([bordered][position=below]) .tab-nav-active-indicator-container{inset-block-end:0;inset-block-start:unset}:host([bordered][position=bottom]) .tab-nav-active-indicator-container{inset-block-end:0;inset-block-start:unset}@media (forced-colors: active){.tab-nav-active-indicator{background-color:highlight}}";
- const TabNav = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
- constructor() {
- super();
- this.__registerHost();
- this.__attachShadow();
- this.calciteTabChange = createEvent(this, "calciteTabChange", 6);
- this.calciteInternalTabChange = createEvent(this, "calciteInternalTabChange", 6);
- /**
- * @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])");
- }
- get el() { return this; }
- static get watchers() { return {
- "selectedTab": ["selectedTabChanged"],
- "selectedTabEl": ["selectedTabElChanged"]
- }; }
- static get style() { return tabNavCss; }
- }, [1, "calcite-tab-nav", {
- "storageId": [513, "storage-id"],
- "syncId": [513, "sync-id"],
- "scale": [1537],
- "layout": [1537],
- "position": [1537],
- "bordered": [1540],
- "indicatorOffset": [1026, "indicator-offset"],
- "indicatorWidth": [1026, "indicator-width"],
- "selectedTab": [32],
- "selectedTabEl": [32]
- }, [[0, "calciteInternalTabsFocusPrevious", "focusPreviousTabHandler"], [0, "calciteInternalTabsFocusNext", "focusNextTabHandler"], [0, "calciteInternalTabsActivate", "internalActivateTabHandler"], [0, "calciteTabsActivate", "activateTabHandler"], [0, "calciteInternalTabTitleRegister", "updateTabTitles"], [16, "calciteInternalTabChange", "globalInternalTabChangeHandler"], [0, "calciteInternalTabIconChanged", "iconStartChangeHandler"]]]);
- function defineCustomElement() {
- if (typeof customElements === "undefined") {
- return;
- }
- const components = ["calcite-tab-nav"];
- components.forEach(tagName => { switch (tagName) {
- case "calcite-tab-nav":
- if (!customElements.get(tagName)) {
- customElements.define(tagName, TabNav);
- }
- break;
- } });
- }
- defineCustomElement();
- export { TabNav as T, defineCustomElement as d };
|