calcite-tab_4.entry.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. /*!
  2. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  4. * v1.0.0-beta.82
  5. */
  6. import { r as registerInstance, c as createEvent, h, H as Host, g as getElement, F as Fragment } from './index-8ece2564.js';
  7. import { g as guid } from './guid-b4461004.js';
  8. import { t as toAriaBoolean, n as nodeListToArray, a as getElementDir, k as filterDirectChildren, d as getElementProp } from './dom-da697a3f.js';
  9. import { c as createObserver } from './observers-b198f831.js';
  10. import { u as updateHostInteraction } from './interactive-cb5bf285.js';
  11. const tabCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 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;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host([active]) section{display:block}:host{display:none;height:100%;width:100%}:host([active]){display:block;height:100%;width:100%;overflow:auto}section{display:none;height:100%;width:100%}:host([scale=s]){padding-top:0.25rem;padding-bottom:0.25rem;font-size:var(--calcite-font-size--2);line-height:1rem}:host([scale=m]){padding-top:0.5rem;padding-bottom:0.5rem;font-size:var(--calcite-font-size--1);line-height:1rem}:host([scale=l]){padding-top:0.75rem;padding-bottom:0.75rem;font-size:var(--calcite-font-size-0);line-height:1.25rem}";
  12. const Tab = class {
  13. constructor(hostRef) {
  14. registerInstance(this, hostRef);
  15. this.calciteTabRegister = createEvent(this, "calciteTabRegister", 7);
  16. /**
  17. * Show this tab
  18. */
  19. this.active = false;
  20. /** @internal Parent tabs component scale value */
  21. this.scale = "m";
  22. this.guid = `calcite-tab-title-${guid()}`;
  23. }
  24. //--------------------------------------------------------------------------
  25. //
  26. // Lifecycle
  27. //
  28. //--------------------------------------------------------------------------
  29. render() {
  30. const id = this.el.id || this.guid;
  31. return (h(Host, { "aria-expanded": toAriaBoolean(this.active), "aria-labelledby": this.labeledBy, id: id, role: "tabpanel" }, h("section", null, h("slot", null))));
  32. }
  33. connectedCallback() {
  34. this.parentTabsEl = this.el.closest("calcite-tabs");
  35. }
  36. componentDidLoad() {
  37. this.calciteTabRegister.emit();
  38. }
  39. componentWillRender() {
  40. var _a;
  41. this.scale = (_a = this.parentTabsEl) === null || _a === void 0 ? void 0 : _a.scale;
  42. }
  43. disconnectedCallback() {
  44. var _a;
  45. // Dispatching to body in order to be listened by other elements that are still connected to the DOM.
  46. (_a = document.body) === null || _a === void 0 ? void 0 : _a.dispatchEvent(new CustomEvent("calciteTabUnregister", {
  47. detail: this.el
  48. }));
  49. }
  50. //--------------------------------------------------------------------------
  51. //
  52. // Event Listeners
  53. //
  54. //--------------------------------------------------------------------------
  55. internalTabChangeHandler(event) {
  56. const targetTabsEl = event
  57. .composedPath()
  58. .find((el) => el.tagName === "CALCITE-TABS");
  59. // to allow `<calcite-tabs>` to be nested we need to make sure this
  60. // `calciteTabChange` event was actually fired from a within the same
  61. // `<calcite-tabs>` that is the a parent of this tab.
  62. if (targetTabsEl !== this.parentTabsEl) {
  63. return;
  64. }
  65. if (this.tab) {
  66. this.active = this.tab === event.detail.tab;
  67. }
  68. else {
  69. this.getTabIndex().then((index) => {
  70. this.active = index === event.detail.tab;
  71. });
  72. }
  73. }
  74. //--------------------------------------------------------------------------
  75. //
  76. // Public Methods
  77. //
  78. //--------------------------------------------------------------------------
  79. /**
  80. * Return the index of this tab within the tab array
  81. */
  82. async getTabIndex() {
  83. return Array.prototype.indexOf.call(nodeListToArray(this.el.parentElement.children).filter((e) => e.matches("calcite-tab")), this.el);
  84. }
  85. //--------------------------------------------------------------------------
  86. //
  87. // Private Methods
  88. //
  89. //--------------------------------------------------------------------------
  90. /**
  91. * @internal
  92. */
  93. async updateAriaInfo(tabIds = [], titleIds = []) {
  94. this.labeledBy = titleIds[tabIds.indexOf(this.el.id)] || null;
  95. }
  96. get el() { return getElement(this); }
  97. };
  98. Tab.style = tabCss;
  99. const tabNavCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 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;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{position:relative;display:-ms-flexbox;display:flex}:host([scale=s]){min-height:1.5rem}:host([scale=m]){min-height:2rem}:host([scale=l]){min-height:2.75rem}.tab-nav{display:-ms-flexbox;display:flex;width:100%;-ms-flex-pack:start;justify-content:flex-start;overflow:auto}:host([layout=center]) .tab-nav{-ms-flex-pack:center;justify-content:center}.tab-nav-active-indicator-container{position:absolute;left:0px;right:0px;bottom:0px;height:0.125rem;width:100%;overflow:hidden}.tab-nav-active-indicator{position:absolute;bottom:0px;display:block;height:0.125rem;background-color:var(--calcite-ui-brand);-webkit-transition-property:all;transition-property:all;-webkit-transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);-webkit-transition-duration:150ms;transition-duration:150ms;-webkit-transition-timing-function:cubic-bezier(0, 0, 0.2, 1);transition-timing-function:cubic-bezier(0, 0, 0.2, 1)}:host([position=below]) .tab-nav-active-indicator{bottom:unset;top:0px}:host([position=below]) .tab-nav-active-indicator-container{bottom:unset;top:0px}:host([bordered]) .tab-nav-active-indicator-container{bottom:unset}:host([bordered][position=below]) .tab-nav-active-indicator-container{bottom:0;top:unset}";
  100. const TabNav = class {
  101. constructor(hostRef) {
  102. registerInstance(this, hostRef);
  103. this.calciteTabChange = createEvent(this, "calciteTabChange", 7);
  104. this.calciteInternalTabChange = createEvent(this, "calciteInternalTabChange", 7);
  105. /** @internal Parent tabs component scale value */
  106. this.scale = "m";
  107. /** @internal Parent tabs component layout value */
  108. this.layout = "inline";
  109. /** @internal Parent tabs component position value */
  110. this.position = "below";
  111. /** @internal Parent tabs component bordered value when layout is "inline" */
  112. this.bordered = false;
  113. this.animationActiveDuration = 0.3;
  114. this.resizeObserver = createObserver("resize", () => {
  115. // remove active indicator transition duration during resize to prevent wobble
  116. this.activeIndicatorEl.style.transitionDuration = "0s";
  117. this.updateActiveWidth();
  118. this.updateOffsetPosition();
  119. });
  120. //--------------------------------------------------------------------------
  121. //
  122. // Private Methods
  123. //
  124. //--------------------------------------------------------------------------
  125. this.handleContainerScroll = () => {
  126. // remove active indicator transition duration while container is scrolling to prevent wobble
  127. this.activeIndicatorEl.style.transitionDuration = "0s";
  128. this.updateOffsetPosition();
  129. };
  130. }
  131. async selectedTabChanged() {
  132. if (localStorage &&
  133. this.storageId &&
  134. this.selectedTab !== undefined &&
  135. this.selectedTab !== null) {
  136. localStorage.setItem(`calcite-tab-nav-${this.storageId}`, JSON.stringify(this.selectedTab));
  137. }
  138. this.calciteInternalTabChange.emit({
  139. tab: this.selectedTab
  140. });
  141. this.selectedTabEl = await this.getTabTitleById(this.selectedTab);
  142. }
  143. selectedTabElChanged() {
  144. this.updateOffsetPosition();
  145. this.updateActiveWidth();
  146. // reset the animation time on tab selection
  147. this.activeIndicatorEl.style.transitionDuration = `${this.animationActiveDuration}s`;
  148. }
  149. //--------------------------------------------------------------------------
  150. //
  151. // Lifecycle
  152. //
  153. //--------------------------------------------------------------------------
  154. connectedCallback() {
  155. var _a;
  156. this.parentTabsEl = this.el.closest("calcite-tabs");
  157. (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el);
  158. }
  159. disconnectedCallback() {
  160. var _a;
  161. (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
  162. }
  163. componentWillLoad() {
  164. const storageKey = `calcite-tab-nav-${this.storageId}`;
  165. if (localStorage && this.storageId && localStorage.getItem(storageKey)) {
  166. const storedTab = JSON.parse(localStorage.getItem(storageKey));
  167. this.selectedTab = storedTab;
  168. }
  169. }
  170. componentWillRender() {
  171. const { parentTabsEl } = this;
  172. this.layout = parentTabsEl === null || parentTabsEl === void 0 ? void 0 : parentTabsEl.layout;
  173. this.position = parentTabsEl === null || parentTabsEl === void 0 ? void 0 : parentTabsEl.position;
  174. this.scale = parentTabsEl === null || parentTabsEl === void 0 ? void 0 : parentTabsEl.scale;
  175. this.bordered = parentTabsEl === null || parentTabsEl === void 0 ? void 0 : parentTabsEl.bordered;
  176. // fix issue with active tab-title not lining up with blue indicator
  177. if (this.selectedTabEl) {
  178. this.updateOffsetPosition();
  179. }
  180. }
  181. componentDidRender() {
  182. // if every tab title is active select the first tab.
  183. if (this.tabTitles.length &&
  184. this.tabTitles.every((title) => !title.active) &&
  185. !this.selectedTab) {
  186. this.tabTitles[0].getTabIdentifier().then((tab) => {
  187. this.calciteInternalTabChange.emit({
  188. tab
  189. });
  190. });
  191. }
  192. }
  193. render() {
  194. const dir = getElementDir(this.el);
  195. const width = `${this.indicatorWidth}px`;
  196. const offset = `${this.indicatorOffset}px`;
  197. const indicatorStyle = dir !== "rtl" ? { width, left: offset } : { width, right: offset };
  198. 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))));
  199. }
  200. //--------------------------------------------------------------------------
  201. //
  202. // Event Listeners
  203. //
  204. //--------------------------------------------------------------------------
  205. focusPreviousTabHandler(e) {
  206. const currentIndex = this.getIndexOfTabTitle(e.target, this.enabledTabTitles);
  207. const previousTab = this.enabledTabTitles[currentIndex - 1] ||
  208. this.enabledTabTitles[this.enabledTabTitles.length - 1];
  209. previousTab.focus();
  210. e.stopPropagation();
  211. e.preventDefault();
  212. }
  213. focusNextTabHandler(e) {
  214. const currentIndex = this.getIndexOfTabTitle(e.target, this.enabledTabTitles);
  215. const nextTab = this.enabledTabTitles[currentIndex + 1] || this.enabledTabTitles[0];
  216. nextTab.focus();
  217. e.stopPropagation();
  218. e.preventDefault();
  219. }
  220. internalActivateTabHandler(e) {
  221. this.selectedTab = e.detail.tab
  222. ? e.detail.tab
  223. : this.getIndexOfTabTitle(e.target);
  224. e.stopPropagation();
  225. e.preventDefault();
  226. }
  227. activateTabHandler(e) {
  228. this.calciteTabChange.emit({
  229. tab: this.selectedTab
  230. });
  231. e.stopPropagation();
  232. e.preventDefault();
  233. }
  234. /**
  235. * Check for active tabs on register and update selected
  236. */
  237. updateTabTitles(e) {
  238. if (e.target.active) {
  239. this.selectedTab = e.detail;
  240. }
  241. }
  242. globalInternalTabChangeHandler(e) {
  243. if (this.syncId &&
  244. e.target !== this.el &&
  245. e.target.syncId === this.syncId &&
  246. this.selectedTab !== e.detail.tab) {
  247. this.selectedTab = e.detail.tab;
  248. e.stopPropagation();
  249. }
  250. }
  251. updateOffsetPosition() {
  252. var _a, _b, _c, _d, _e;
  253. const dir = getElementDir(this.el);
  254. const navWidth = (_a = this.activeIndicatorContainerEl) === null || _a === void 0 ? void 0 : _a.offsetWidth;
  255. const tabLeft = (_b = this.selectedTabEl) === null || _b === void 0 ? void 0 : _b.offsetLeft;
  256. const tabWidth = (_c = this.selectedTabEl) === null || _c === void 0 ? void 0 : _c.offsetWidth;
  257. const offsetRight = navWidth - (tabLeft + tabWidth);
  258. this.indicatorOffset =
  259. 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);
  260. }
  261. updateActiveWidth() {
  262. var _a;
  263. this.indicatorWidth = (_a = this.selectedTabEl) === null || _a === void 0 ? void 0 : _a.offsetWidth;
  264. }
  265. getIndexOfTabTitle(el, tabTitles = this.tabTitles) {
  266. // In most cases, since these indexes correlate with tab contents, we want to consider all tab titles.
  267. // However, when doing relative index operations, it makes sense to pass in this.enabledTabTitles as the 2nd arg.
  268. return tabTitles.indexOf(el);
  269. }
  270. async getTabTitleById(id) {
  271. return Promise.all(this.tabTitles.map((el) => el.getTabIdentifier())).then((ids) => {
  272. return this.tabTitles[ids.indexOf(id)];
  273. });
  274. }
  275. get tabTitles() {
  276. return filterDirectChildren(this.el, "calcite-tab-title");
  277. }
  278. get enabledTabTitles() {
  279. return filterDirectChildren(this.el, "calcite-tab-title:not([disabled])");
  280. }
  281. get el() { return getElement(this); }
  282. static get watchers() { return {
  283. "selectedTab": ["selectedTabChanged"],
  284. "selectedTabEl": ["selectedTabElChanged"]
  285. }; }
  286. };
  287. TabNav.style = tabNavCss;
  288. const tabTitleCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 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;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{margin-right:1.25rem;display:block;-ms-flex:0 1 auto;flex:0 1 auto;outline:2px solid transparent;outline-offset:2px;-webkit-margin-start:0px;margin-inline-start:0px;-webkit-margin-end:1.25rem;margin-inline-end:1.25rem}:host([layout=center]){margin-top:0px;margin-bottom:0px;margin-left:1.25rem;margin-right:1.25rem;text-align:center;-ms-flex-preferred-size:12rem;flex-basis:12rem}:host([position=below]) a{border-bottom-width:0px;border-top-width:2px;border-top-color:transparent;border-top-style:solid}:host a{outline-offset:0;outline-color:transparent;-webkit-transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out}:host(:focus) a{outline:2px solid var(--calcite-ui-brand);outline-offset:-2px}:host(:active) a,:host(:focus) a,:host(:hover) a{border-color:var(--calcite-ui-border-2);color:var(--calcite-ui-text-1);-webkit-text-decoration-line:none;text-decoration-line:none}:host([active]) a{border-color:transparent;color:var(--calcite-ui-text-1)}:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host([disabled]) span,:host([disabled]) a{pointer-events:none;opacity:0.5}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}:host([scale=s]){-webkit-margin-end:1rem;margin-inline-end:1rem}:host([scale=s]) a,:host([scale=s]) span{padding-top:0.25rem;padding-bottom:0.25rem;font-size:var(--calcite-font-size--2);line-height:1rem}:host([scale=m]) a,:host([scale=m]) span{padding-top:0.5rem;padding-bottom:0.5rem;font-size:var(--calcite-font-size--1);line-height:1rem}:host([scale=l]){-webkit-margin-end:1.5rem;margin-inline-end:1.5rem}:host([scale=l]) a,:host([scale=l]) span{padding-top:0.75rem;padding-bottom:0.75rem;font-size:var(--calcite-font-size-0);line-height:1.25rem}a,span{-webkit-box-sizing:border-box;box-sizing:border-box;display:-ms-flexbox;display:flex;height:100%;width:100%;cursor:pointer;-webkit-appearance:none;-moz-appearance:none;appearance:none;-ms-flex-pack:center;justify-content:center;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;border-bottom-width:2px;padding-left:0px;padding-right:0px;padding-top:0.5rem;padding-bottom:0.5rem;font-size:var(--calcite-font-size--1);line-height:1rem;color:var(--calcite-ui-text-3);-webkit-transition-property:all;transition-property:all;-webkit-transition-duration:var(--calcite-animation-timing);transition-duration:var(--calcite-animation-timing);-webkit-transition-timing-function:ease-in-out;transition-timing-function:ease-in-out;-webkit-transition-delay:0s;transition-delay:0s;border-bottom-color:transparent;border-bottom-style:solid}span{cursor:default}.calcite-tab-title--icon{position:relative;margin:0px;display:-ms-inline-flexbox;display:inline-flex;-ms-flex-item-align:center;align-self:center}.calcite-tab-title--icon svg{-webkit-transition-property:all;transition-property:all;-webkit-transition-duration:var(--calcite-animation-timing);transition-duration:var(--calcite-animation-timing);-webkit-transition-timing-function:ease-in-out;transition-timing-function:ease-in-out;-webkit-transition-delay:0s;transition-delay:0s}.container--has-text{padding:0.25rem}.container--has-text .calcite-tab-title--icon.icon-start{-webkit-margin-end:0.5rem;margin-inline-end:0.5rem}.container--has-text .calcite-tab-title--icon.icon-end{-webkit-margin-start:0.5rem;margin-inline-start:0.5rem}:host([icon-start][icon-end]) .calcite-tab-title--icon:first-child{-webkit-margin-end:0.5rem;margin-inline-end:0.5rem}:host([bordered]){-webkit-margin-end:0;margin-inline-end:0}:host([bordered][active]){-webkit-box-shadow:inset 0px -2px var(--calcite-ui-foreground-1);box-shadow:inset 0px -2px var(--calcite-ui-foreground-1)}:host([bordered][active][position=below]){-webkit-box-shadow:inset 0 2px 0 var(--calcite-ui-foreground-1);box-shadow:inset 0 2px 0 var(--calcite-ui-foreground-1)}:host([bordered]:hover) a,:host([bordered]:focus) a,:host([bordered]:active) a{position:relative}:host([bordered]:hover) a{background-color:var(--calcite-button-transparent-hover);-webkit-transition-property:all;transition-property:all;-webkit-transition-duration:var(--calcite-animation-timing);transition-duration:var(--calcite-animation-timing);-webkit-transition-timing-function:ease-in-out;transition-timing-function:ease-in-out;-webkit-transition-delay:0s;transition-delay:0s}:host([bordered]) a{border-bottom-style:unset}:host([bordered][position=below]) a{border-top-style:unset}:host([active][bordered]) a{border-left:1px solid var(--calcite-ui-border-1);border-right:1px solid var(--calcite-ui-border-1)}:host([bordered]) a,:host([bordered]) span{padding-left:0.75rem;padding-right:0.75rem}:host([bordered][scale=s]) a,:host([bordered][scale=s]) span{padding-left:0.5rem;padding-right:0.5rem}:host([bordered][scale=l]) a,:host([bordered][scale=l]) span{padding-left:1rem;padding-right:1rem}";
  289. const TabTitle = class {
  290. constructor(hostRef) {
  291. registerInstance(this, hostRef);
  292. this.calciteTabsActivate = createEvent(this, "calciteTabsActivate", 7);
  293. this.calciteInternalTabsActivate = createEvent(this, "calciteInternalTabsActivate", 7);
  294. this.calciteTabsFocusNext = createEvent(this, "calciteTabsFocusNext", 7);
  295. this.calciteTabsFocusPrevious = createEvent(this, "calciteTabsFocusPrevious", 7);
  296. this.calciteTabTitleRegister = createEvent(this, "calciteTabTitleRegister", 7);
  297. //--------------------------------------------------------------------------
  298. //
  299. // Properties
  300. //
  301. //--------------------------------------------------------------------------
  302. /** Show this tab title as selected */
  303. this.active = false;
  304. /** Disable this tab title */
  305. this.disabled = false;
  306. /** @internal Parent tabs component bordered value */
  307. this.bordered = false;
  308. //--------------------------------------------------------------------------
  309. //
  310. // Private State/Props
  311. //
  312. //--------------------------------------------------------------------------
  313. /** watches for changing text content **/
  314. this.mutationObserver = createObserver("mutation", () => this.updateHasText());
  315. /** determine if there is slotted text for styling purposes */
  316. this.hasText = false;
  317. this.guid = `calcite-tab-title-${guid()}`;
  318. }
  319. activeTabChanged() {
  320. if (this.active) {
  321. this.emitActiveTab(false);
  322. }
  323. }
  324. //--------------------------------------------------------------------------
  325. //
  326. // Lifecycle
  327. //
  328. //--------------------------------------------------------------------------
  329. connectedCallback() {
  330. this.setupTextContentObserver();
  331. this.parentTabNavEl = this.el.closest("calcite-tab-nav");
  332. this.parentTabsEl = this.el.closest("calcite-tabs");
  333. }
  334. disconnectedCallback() {
  335. var _a, _b;
  336. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
  337. // Dispatching to body in order to be listened by other elements that are still connected to the DOM.
  338. (_b = document.body) === null || _b === void 0 ? void 0 : _b.dispatchEvent(new CustomEvent("calciteTabTitleUnregister", {
  339. detail: this.el
  340. }));
  341. }
  342. componentWillLoad() {
  343. {
  344. this.updateHasText();
  345. }
  346. if (this.tab && this.active) {
  347. this.emitActiveTab(false);
  348. }
  349. }
  350. componentWillRender() {
  351. if (this.parentTabsEl) {
  352. this.layout = this.parentTabsEl.layout;
  353. this.position = this.parentTabsEl.position;
  354. this.scale = this.parentTabsEl.scale;
  355. this.bordered = this.parentTabsEl.bordered;
  356. }
  357. // handle case when tab-nav is only parent
  358. if (!this.parentTabsEl && this.parentTabNavEl) {
  359. this.position = getElementProp(this.parentTabNavEl, "position", this.position);
  360. this.scale = getElementProp(this.parentTabNavEl, "scale", this.scale);
  361. }
  362. }
  363. render() {
  364. const id = this.el.id || this.guid;
  365. const showSideBorders = this.bordered && !this.disabled && this.layout !== "center";
  366. const iconStartEl = (h("calcite-icon", { class: "calcite-tab-title--icon icon-start", flipRtl: this.iconFlipRtl === "start" || this.iconFlipRtl === "both", icon: this.iconStart, scale: "s" }));
  367. const iconEndEl = (h("calcite-icon", { class: "calcite-tab-title--icon icon-end", flipRtl: this.iconFlipRtl === "end" || this.iconFlipRtl === "both", icon: this.iconEnd, scale: "s" }));
  368. return (h(Host, { "aria-controls": this.controls, "aria-expanded": toAriaBoolean(this.active), id: id, role: "tab" }, h("a", { class: {
  369. container: true,
  370. "container--has-text": this.hasText
  371. }, style: showSideBorders && { width: `${this.parentTabNavEl.indicatorWidth}px` } }, this.iconStart ? iconStartEl : null, h("slot", null), this.iconEnd ? iconEndEl : null)));
  372. }
  373. async componentDidLoad() {
  374. this.calciteTabTitleRegister.emit(await this.getTabIdentifier());
  375. }
  376. componentDidRender() {
  377. updateHostInteraction(this, true);
  378. }
  379. //--------------------------------------------------------------------------
  380. //
  381. // Event Listeners
  382. //
  383. //--------------------------------------------------------------------------
  384. internalTabChangeHandler(event) {
  385. const targetTabsEl = event
  386. .composedPath()
  387. .find((el) => el.tagName === "CALCITE-TABS");
  388. if (targetTabsEl !== this.parentTabsEl) {
  389. return;
  390. }
  391. if (this.tab) {
  392. this.active = this.tab === event.detail.tab;
  393. }
  394. else {
  395. this.getTabIndex().then((index) => {
  396. this.active = index === event.detail.tab;
  397. });
  398. }
  399. event.stopPropagation();
  400. }
  401. onClick() {
  402. this.emitActiveTab();
  403. }
  404. keyDownHandler(e) {
  405. switch (e.key) {
  406. case " ":
  407. case "Enter":
  408. this.emitActiveTab();
  409. e.preventDefault();
  410. break;
  411. case "ArrowRight":
  412. if (getElementDir(this.el) === "ltr") {
  413. this.calciteTabsFocusNext.emit();
  414. }
  415. else {
  416. this.calciteTabsFocusPrevious.emit();
  417. }
  418. break;
  419. case "ArrowLeft":
  420. if (getElementDir(this.el) === "ltr") {
  421. this.calciteTabsFocusPrevious.emit();
  422. }
  423. else {
  424. this.calciteTabsFocusNext.emit();
  425. }
  426. break;
  427. }
  428. }
  429. //--------------------------------------------------------------------------
  430. //
  431. // Public Methods
  432. //
  433. //--------------------------------------------------------------------------
  434. /**
  435. * Return the index of this title within the nav
  436. */
  437. async getTabIndex() {
  438. return Array.prototype.indexOf.call(this.el.parentElement.querySelectorAll("calcite-tab-title"), this.el);
  439. }
  440. /**
  441. * @internal
  442. */
  443. async getTabIdentifier() {
  444. return this.tab ? this.tab : this.getTabIndex();
  445. }
  446. /**
  447. * @internal
  448. */
  449. async updateAriaInfo(tabIds = [], titleIds = []) {
  450. this.controls = tabIds[titleIds.indexOf(this.el.id)] || null;
  451. }
  452. updateHasText() {
  453. this.hasText = this.el.textContent.trim().length > 0;
  454. }
  455. setupTextContentObserver() {
  456. var _a;
  457. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el, { childList: true, subtree: true });
  458. }
  459. emitActiveTab(userTriggered = true) {
  460. if (this.disabled) {
  461. return;
  462. }
  463. const payload = { tab: this.tab };
  464. this.calciteInternalTabsActivate.emit(payload);
  465. if (userTriggered) {
  466. this.calciteTabsActivate.emit(payload);
  467. }
  468. }
  469. get el() { return getElement(this); }
  470. static get watchers() { return {
  471. "active": ["activeTabChanged"]
  472. }; }
  473. };
  474. TabTitle.style = tabTitleCss;
  475. const SLOTS = {
  476. tabNav: "tab-nav"
  477. };
  478. const tabsCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 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;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column}:host([bordered]){-webkit-box-shadow:inset 0 1px 0 var(--calcite-ui-border-1);box-shadow:inset 0 1px 0 var(--calcite-ui-border-1);background-color:var(--calcite-ui-foreground-1)}:host([bordered]:not([position=below])) ::slotted(calcite-tab-nav){margin-bottom:-1px}:host([bordered][position=below]) ::slotted(calcite-tab-nav){margin-top:-1px}:host([bordered][position=below]){-webkit-box-shadow:inset 0 1px 0 var(--calcite-ui-border-1), inset 0 -1px 0 var(--calcite-ui-border-1);box-shadow:inset 0 1px 0 var(--calcite-ui-border-1), inset 0 -1px 0 var(--calcite-ui-border-1)}:host([bordered]) section{border-width:1px;border-style:solid;border-color:var(--calcite-ui-border-1)}:host([bordered][scale=s]) section{padding:0.75rem}:host([bordered][scale=m]) section{padding:0.5rem}:host([bordered][scale=l]) section{padding:1rem}:host([position=below]){-ms-flex-direction:column-reverse;flex-direction:column-reverse}section{display:-ms-flexbox;display:flex;-ms-flex-positive:1;flex-grow:1;overflow:hidden;border-top-width:1px;border-top-color:var(--calcite-ui-border-1);border-top-style:solid}:host([position=below]) section{-ms-flex-direction:column-reverse;flex-direction:column-reverse;border-top-width:0px;border-bottom-width:1px;border-bottom-color:var(--calcite-ui-border-1)}:host([position=below]:not([bordered])) section{border-bottom-style:solid}";
  479. const Tabs = class {
  480. constructor(hostRef) {
  481. registerInstance(this, hostRef);
  482. //--------------------------------------------------------------------------
  483. //
  484. // Public Properties
  485. //
  486. //--------------------------------------------------------------------------
  487. /**
  488. * Align tab titles to the edge or fully justify them across the tab nav ("center")
  489. */
  490. this.layout = "inline";
  491. /**
  492. * Display the tabs above (default) or below the tab content
  493. */
  494. this.position = "above";
  495. /**
  496. * Specify the scale of the tabs component, defaults to m
  497. */
  498. this.scale = "m";
  499. /**
  500. * Optionally enable tabs to appear like a folder-style menu when its layout is "inline"
  501. */
  502. this.bordered = false;
  503. //--------------------------------------------------------------------------
  504. //
  505. // Events
  506. //
  507. //--------------------------------------------------------------------------
  508. //--------------------------------------------------------------------------
  509. //
  510. // Private State/Props
  511. //
  512. //--------------------------------------------------------------------------
  513. /**
  514. *
  515. * Stores an array of ids of `<calcite-tab-titles>`s to match up ARIA
  516. * attributes.
  517. */
  518. this.titles = [];
  519. /**
  520. *
  521. * Stores an array of ids of `<calcite-tab>`s to match up ARIA attributes.
  522. */
  523. this.tabs = [];
  524. }
  525. //--------------------------------------------------------------------------
  526. //
  527. // Lifecycle
  528. //
  529. //--------------------------------------------------------------------------
  530. connectedCallback() {
  531. if (this.layout === "center") {
  532. this.bordered = false;
  533. }
  534. }
  535. render() {
  536. return (h(Fragment, null, h("slot", { name: SLOTS.tabNav }), h("section", null, h("slot", null))));
  537. }
  538. //--------------------------------------------------------------------------
  539. //
  540. // Event Listeners
  541. //
  542. //--------------------------------------------------------------------------
  543. /**
  544. * @internal
  545. */
  546. calciteTabTitleRegister(e) {
  547. this.titles = [...this.titles, e.target];
  548. this.registryHandler();
  549. e.stopPropagation();
  550. }
  551. /**
  552. * @internal
  553. */
  554. calciteTabTitleUnregister(e) {
  555. this.titles = this.titles.filter((el) => el !== e.detail);
  556. this.registryHandler();
  557. e.stopPropagation();
  558. }
  559. /**
  560. * @internal
  561. */
  562. calciteTabRegister(e) {
  563. this.tabs = [...this.tabs, e.target];
  564. this.registryHandler();
  565. e.stopPropagation();
  566. }
  567. /**
  568. * @internal
  569. */
  570. calciteTabUnregister(e) {
  571. this.tabs = this.tabs.filter((el) => el !== e.detail);
  572. this.registryHandler();
  573. e.stopPropagation();
  574. }
  575. //--------------------------------------------------------------------------
  576. //
  577. // Private Methods
  578. //
  579. //--------------------------------------------------------------------------
  580. /**
  581. *
  582. * Matches up elements from the internal `tabs` and `titles` to automatically
  583. * update the ARIA attributes and link `<calcite-tab>` and
  584. * `<calcite-tab-title>` components.
  585. */
  586. async registryHandler() {
  587. let tabIds;
  588. let titleIds;
  589. // determine if we are using `tab` based or `index` based tab identifiers.
  590. if (this.tabs.some((e) => e.tab) || this.titles.some((e) => e.tab)) {
  591. // if we are using `tab` based identifiers sort by `tab` to account for
  592. // possible out of order tabs and get the id of each tab
  593. tabIds = this.tabs.sort((a, b) => a.tab.localeCompare(b.tab)).map((e) => e.id);
  594. titleIds = this.titles.sort((a, b) => a.tab.localeCompare(b.tab)).map((e) => e.id);
  595. }
  596. else {
  597. // if we are using index based tabs then the `<calcite-tab>` and
  598. // `<calcite-tab-title>` might have been rendered out of order so the
  599. // order of `this.tabs` and `this.titles` might not reflect the DOM state,
  600. // and might not match each other so we need to get the index of all the
  601. // tabs and titles in the DOM order to match them up as a source of truth
  602. const tabDomIndexes = await Promise.all(this.tabs.map((el) => el.getTabIndex()));
  603. const titleDomIndexes = await Promise.all(this.titles.map((el) => el.getTabIndex()));
  604. // once we have the DOM order as a source of truth we can build the
  605. // matching tabIds and titleIds arrays
  606. tabIds = tabDomIndexes.reduce((ids, indexInDOM, registryIndex) => {
  607. ids[indexInDOM] = this.tabs[registryIndex].id;
  608. return ids;
  609. }, []);
  610. titleIds = titleDomIndexes.reduce((ids, indexInDOM, registryIndex) => {
  611. ids[indexInDOM] = this.titles[registryIndex].id;
  612. return ids;
  613. }, []);
  614. }
  615. // pass all our new aria information to each `<calcite-tab>` and
  616. // `<calcite-tab-title>` which will check if they can update their internal
  617. // `controlled` or `labeledBy` states and re-render if necessary
  618. this.tabs.forEach((el) => el.updateAriaInfo(tabIds, titleIds));
  619. this.titles.forEach((el) => el.updateAriaInfo(tabIds, titleIds));
  620. }
  621. get el() { return getElement(this); }
  622. };
  623. Tabs.style = tabsCss;
  624. export { Tab as calcite_tab, TabNav as calcite_tab_nav, TabTitle as calcite_tab_title, Tabs as calcite_tabs };