calcite-tab_4.entry.js 38 KB

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