calcite-tab_4.cjs.entry.js 40 KB

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