calcite-tab_4.cjs.entry.js 38 KB

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