/*! * 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 { g as guid } from './guid.js'; import { n as nodeListToArray } from './dom.js'; const tabCss = "@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([selected]) section,:host([selected]) .container{display:block}:host{display:none;block-size:100%;inline-size:100%}:host([selected]){display:block;block-size:100%;inline-size:100%;overflow:auto}section,.container{display:none;block-size:100%;inline-size:100%}:host([scale=s]){padding-block:0.25rem;font-size:var(--calcite-font-size--2);line-height:1rem}:host([scale=m]){padding-block:0.5rem;font-size:var(--calcite-font-size--1);line-height:1rem}:host([scale=l]){padding-block:0.75rem;font-size:var(--calcite-font-size-0);line-height:1.25rem}"; const Tab = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement { constructor() { super(); this.__registerHost(); this.__attachShadow(); this.calciteInternalTabRegister = createEvent(this, "calciteInternalTabRegister", 6); /** * When `true`, the component's contents are selected. * * Only one tab can be selected within the `calcite-tabs` parent. * * @deprecated Use `selected` instead. */ this.active = false; /** * When `true`, the component's contents are selected. * * Only one tab can be selected within the `calcite-tabs` parent. */ this.selected = false; /** * @internal */ this.scale = "m"; this.guid = `calcite-tab-title-${guid()}`; } activeHandler(value) { this.selected = value; } selectedHandler(value) { this.active = value; } //-------------------------------------------------------------------------- // // Lifecycle // //-------------------------------------------------------------------------- render() { const id = this.el.id || this.guid; return (h(Host, { "aria-labelledby": this.labeledBy, id: id }, h("div", { class: "container", role: "tabpanel", tabIndex: this.selected ? 0 : -1 }, h("section", null, h("slot", null))))); } connectedCallback() { this.parentTabsEl = this.el.closest("calcite-tabs"); const isSelected = this.selected || this.active; if (isSelected) { this.activeHandler(isSelected); this.selectedHandler(isSelected); } } componentDidLoad() { this.calciteInternalTabRegister.emit(); } componentWillRender() { var _a; this.scale = (_a = this.parentTabsEl) === null || _a === void 0 ? void 0 : _a.scale; } disconnectedCallback() { var _a; // Dispatching to body in order to be listened by other elements that are still connected to the DOM. (_a = document.body) === null || _a === void 0 ? void 0 : _a.dispatchEvent(new CustomEvent("calciteTabUnregister", { detail: this.el })); } //-------------------------------------------------------------------------- // // Event Listeners // //-------------------------------------------------------------------------- internalTabChangeHandler(event) { const targetTabsEl = event .composedPath() .find((el) => el.tagName === "CALCITE-TABS"); // to allow `` to be nested we need to make sure this // `calciteTabChange` event was actually fired from a within the same // `` that is the a parent of this tab. if (targetTabsEl !== this.parentTabsEl) { return; } if (this.tab) { this.selected = this.tab === event.detail.tab; } else { this.getTabIndex().then((index) => { this.selected = index === event.detail.tab; }); } event.stopPropagation(); } //-------------------------------------------------------------------------- // // Public Methods // //-------------------------------------------------------------------------- /** * Returns the index of the component item within the tab array. */ async getTabIndex() { return Array.prototype.indexOf.call(nodeListToArray(this.el.parentElement.children).filter((el) => el.matches("calcite-tab")), this.el); } //-------------------------------------------------------------------------- // // Private Methods // //-------------------------------------------------------------------------- /** * @param tabIds * @param titleIds * @internal */ async updateAriaInfo(tabIds = [], titleIds = []) { this.labeledBy = titleIds[tabIds.indexOf(this.el.id)] || null; } get el() { return this; } static get watchers() { return { "active": ["activeHandler"], "selected": ["selectedHandler"] }; } static get style() { return tabCss; } }, [1, "calcite-tab", { "tab": [513], "active": [1540], "selected": [1540], "scale": [1537], "labeledBy": [32], "getTabIndex": [64], "updateAriaInfo": [64] }, [[16, "calciteInternalTabChange", "internalTabChangeHandler"]]]); function defineCustomElement() { if (typeof customElements === "undefined") { return; } const components = ["calcite-tab"]; components.forEach(tagName => { switch (tagName) { case "calcite-tab": if (!customElements.get(tagName)) { customElements.define(tagName, Tab); } break; } }); } defineCustomElement(); export { Tab as T, defineCustomElement as d };