calcite-tip_3.entry.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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, F as Fragment, g as getElement } from './index-1f9b54dc.js';
  7. import { g as getSlotted, a as getElementDir, t as toAriaBoolean } from './dom-8f0a9ff2.js';
  8. import { H as Heading, c as constrainHeadingLevel } from './Heading-e0abf8a2.js';
  9. import { c as connectConditionalSlotComponent, d as disconnectConditionalSlotComponent } from './conditionalSlot-a3e8c63a.js';
  10. import { c as createObserver } from './observers-9f44e9b3.js';
  11. import './resources-9c476cb6.js';
  12. import './guid-9f15e57a.js';
  13. const CSS$1 = {
  14. header: "header",
  15. heading: "heading",
  16. close: "close",
  17. container: "container",
  18. tipContainer: "tip-container",
  19. tipContainerAdvancing: "tip-container--advancing",
  20. tipContainerRetreating: "tip-container--retreating",
  21. pagination: "pagination",
  22. pagePosition: "page-position",
  23. pageNext: "page-next",
  24. pagePrevious: "page-previous"
  25. };
  26. const ICONS$1 = {
  27. chevronLeft: "chevron-left",
  28. chevronRight: "chevron-right",
  29. close: "x"
  30. };
  31. const TEXT$1 = {
  32. defaultGroupTitle: "Tips",
  33. defaultPaginationLabel: "Tip",
  34. close: "Close",
  35. previous: "Previous",
  36. next: "Next"
  37. };
  38. const HEADING_LEVEL$1 = 2;
  39. const CSS = {
  40. container: "container",
  41. header: "header",
  42. heading: "heading",
  43. close: "close",
  44. imageFrame: "image-frame",
  45. content: "content",
  46. info: "info"
  47. };
  48. const ICONS = {
  49. close: "x"
  50. };
  51. const SLOTS = {
  52. thumbnail: "thumbnail"
  53. };
  54. const TEXT = {
  55. close: "Close"
  56. };
  57. const HEADING_LEVEL = (HEADING_LEVEL$1 + 1);
  58. const tipCss = "@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;margin:1rem;box-sizing:border-box;display:flex;flex-direction:row;border-width:1px;border-style:solid;border-color:var(--calcite-ui-border-2);background-color:var(--calcite-ui-foreground-1);font-size:var(--calcite-font-size--1);line-height:1rem;color:var(--calcite-ui-text-2)}:host *{box-sizing:border-box}.container{inline-size:100%;padding:1rem}:host([dismissed]),:host([dismissed]) .container{display:none}:host([selected]) .container{margin:0px;border-style:none;padding:0px}.header{margin:0px;display:flex;align-content:space-between;align-items:center;fill:var(--calcite-ui-text-2);color:var(--calcite-ui-text-2)}.heading{margin:0px;padding:0px;font-weight:var(--calcite-font-weight-medium)}.header .heading{flex:1 1 auto;padding:0.5rem}.header{margin-block-end:0.5rem}.header .heading{padding:0px;font-size:var(--calcite-font-size-0);line-height:1.25rem;color:var(--calcite-ui-text-1)}.container[hidden]{display:none}.content{display:flex}.info{padding-block:0px;padding-inline:1rem;inline-size:70%}.info:only-child{inline-size:100%;padding-inline:0px}::slotted(p){margin-block-start:0px}::slotted(a){outline-color:transparent;color:var(--calcite-ui-brand)}::slotted(a:focus){outline:2px solid var(--calcite-ui-brand);outline-offset:2px}.image-frame{inline-size:25%}.image-frame img{max-inline-size:100%}::slotted(img){max-inline-size:100%}";
  59. const Tip = class {
  60. constructor(hostRef) {
  61. registerInstance(this, hostRef);
  62. this.calciteTipDismiss = createEvent(this, "calciteTipDismiss", 6);
  63. // --------------------------------------------------------------------------
  64. //
  65. // Properties
  66. //
  67. // --------------------------------------------------------------------------
  68. /**
  69. * When `true`, the component does not display.
  70. */
  71. this.dismissed = false;
  72. /**
  73. * When `true`, the close button is not present on the component.
  74. */
  75. this.nonDismissible = false;
  76. /**
  77. * When `true`, the component is selected if it has a parent `calcite-tip-manager`.
  78. *
  79. * Only one tip can be selected within the `calcite-tip-manager` parent.
  80. */
  81. this.selected = false;
  82. // --------------------------------------------------------------------------
  83. //
  84. // Private Methods
  85. //
  86. // --------------------------------------------------------------------------
  87. this.hideTip = () => {
  88. this.dismissed = true;
  89. this.calciteTipDismiss.emit();
  90. };
  91. }
  92. // --------------------------------------------------------------------------
  93. //
  94. // Lifecycle
  95. //
  96. // --------------------------------------------------------------------------
  97. connectedCallback() {
  98. connectConditionalSlotComponent(this);
  99. }
  100. disconnectedCallback() {
  101. disconnectConditionalSlotComponent(this);
  102. }
  103. // --------------------------------------------------------------------------
  104. //
  105. // Render Methods
  106. //
  107. // --------------------------------------------------------------------------
  108. renderHeader() {
  109. var _a;
  110. const { heading, headingLevel, el } = this;
  111. const parentLevel = (_a = el.closest("calcite-tip-manager")) === null || _a === void 0 ? void 0 : _a.headingLevel;
  112. const relativeLevel = parentLevel ? constrainHeadingLevel(parentLevel + 1) : null;
  113. const level = headingLevel || relativeLevel || HEADING_LEVEL;
  114. return heading ? (h("header", { class: CSS.header }, h(Heading, { class: CSS.heading, level: level }, heading))) : null;
  115. }
  116. renderDismissButton() {
  117. const { nonDismissible, hideTip, intlClose } = this;
  118. const text = intlClose || TEXT.close;
  119. return !nonDismissible ? (h("calcite-action", { class: CSS.close, icon: ICONS.close, onClick: hideTip, scale: "l", text: text })) : null;
  120. }
  121. renderImageFrame() {
  122. const { el } = this;
  123. return getSlotted(el, SLOTS.thumbnail) ? (h("div", { class: CSS.imageFrame, key: "thumbnail" }, h("slot", { name: SLOTS.thumbnail }))) : null;
  124. }
  125. renderInfoNode() {
  126. return (h("div", { class: CSS.info }, h("slot", null)));
  127. }
  128. renderContent() {
  129. return (h("div", { class: CSS.content }, this.renderImageFrame(), this.renderInfoNode()));
  130. }
  131. render() {
  132. return (h(Fragment, null, h("article", { class: CSS.container }, this.renderHeader(), this.renderContent()), this.renderDismissButton()));
  133. }
  134. get el() { return getElement(this); }
  135. };
  136. Tip.style = tipCss;
  137. const tipGroupCss = "@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{box-sizing:border-box;display:block;background-color:var(--calcite-ui-foreground-1);font-size:var(--calcite-font-size--1);line-height:1rem;color:var(--calcite-ui-text-2)}::slotted(calcite-tip){margin:0px;border-style:none}:host-context(calcite-tip-manager){margin-block:0.75rem}:host-context(calcite-tip-manager) ::slotted(calcite-tip){padding:1rem}";
  138. const TipGroup = class {
  139. constructor(hostRef) {
  140. registerInstance(this, hostRef);
  141. }
  142. render() {
  143. return h("slot", null);
  144. }
  145. };
  146. TipGroup.style = tipGroupCss;
  147. const tipManagerCss = "@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{box-sizing:border-box;display:block;background-color:var(--calcite-ui-foreground-1);font-size:var(--calcite-font-size--1);line-height:1rem;color:var(--calcite-ui-text-2);--calcite-tip-manager-height:19vh}:host *{box-sizing:border-box}:host([closed]){display:none}.header{margin:0px;display:flex;align-content:space-between;align-items:center;fill:var(--calcite-ui-text-2);color:var(--calcite-ui-text-2)}.heading{margin:0px;padding:0px;font-weight:var(--calcite-font-weight-medium)}.header .heading{flex:1 1 auto;padding:0.5rem}.header{border-width:0px;border-block-end-width:1px;border-style:solid;border-color:var(--calcite-ui-border-3);padding-block:0px;padding-inline-end:0px;padding-inline-start:1rem}.header .heading{padding:0px;font-size:var(--calcite-font-size-1);line-height:1.5rem;font-weight:var(--calcite-font-weight-bold);color:var(--calcite-ui-text-1)}.container{position:relative;overflow:hidden;outline-color:transparent;min-block-size:150px}.container:focus{outline:2px solid var(--calcite-ui-brand);outline-offset:2px}.tip-container{margin-block-start:1px;display:flex;align-items:flex-start;justify-content:center;overflow:auto;outline-color:transparent;animation-name:none;animation-duration:var(--calcite-animation-timing);block-size:var(--calcite-tip-manager-height)}.tip-container:focus{outline:2px solid var(--calcite-ui-brand);outline-offset:2px}::slotted(calcite-tip){border-style:none;padding:0.75rem;max-inline-size:var(--calcite-tip-max-width)}.tip-container--advancing{animation-name:tip-advance}.tip-container--retreating{animation-name:tip-retreat}.pagination{display:flex;align-items:center;justify-content:center;padding-inline:0px;padding-block:0.75rem 0.5rem}.page-position{margin-block:0px;margin-inline:0.5rem;font-size:var(--calcite-font-size--2);line-height:1rem}@keyframes tip-advance{0%{opacity:0;transform:translate3d(50px, 0, 0) scale(0.99)}100%{opacity:1;transform:translate3d(0, 0, 0) scale(1)}}@keyframes tip-retreat{0%{opacity:0;transform:translate3d(-50px, 0, 0) scale(0.99)}100%{opacity:1;transform:translate3d(0, 0, 0) scale(1)}}";
  148. const TipManager = class {
  149. constructor(hostRef) {
  150. registerInstance(this, hostRef);
  151. this.calciteTipManagerToggle = createEvent(this, "calciteTipManagerToggle", 6);
  152. this.calciteTipManagerClose = createEvent(this, "calciteTipManagerClose", 6);
  153. // --------------------------------------------------------------------------
  154. //
  155. // Properties
  156. //
  157. // --------------------------------------------------------------------------
  158. /**
  159. * When `true`, does not display or position the component.
  160. */
  161. this.closed = false;
  162. this.mutationObserver = createObserver("mutation", () => this.setUpTips());
  163. this.hideTipManager = () => {
  164. this.closed = true;
  165. this.calciteTipManagerToggle.emit();
  166. this.calciteTipManagerClose.emit();
  167. };
  168. this.previousClicked = () => {
  169. this.previousTip();
  170. };
  171. this.nextClicked = () => {
  172. this.nextTip();
  173. };
  174. this.tipManagerKeyDownHandler = (event) => {
  175. if (event.target !== this.container) {
  176. return;
  177. }
  178. switch (event.key) {
  179. case "ArrowRight":
  180. event.preventDefault();
  181. this.nextTip();
  182. break;
  183. case "ArrowLeft":
  184. event.preventDefault();
  185. this.previousTip();
  186. break;
  187. case "Home":
  188. event.preventDefault();
  189. this.selectedIndex = 0;
  190. break;
  191. case "End":
  192. event.preventDefault();
  193. this.selectedIndex = this.total - 1;
  194. break;
  195. }
  196. };
  197. this.storeContainerRef = (el) => {
  198. this.container = el;
  199. };
  200. }
  201. closedChangeHandler() {
  202. this.direction = null;
  203. this.calciteTipManagerToggle.emit();
  204. }
  205. selectedChangeHandler() {
  206. this.showSelectedTip();
  207. this.updateGroupTitle();
  208. }
  209. // --------------------------------------------------------------------------
  210. //
  211. // Lifecycle
  212. //
  213. // --------------------------------------------------------------------------
  214. connectedCallback() {
  215. var _a;
  216. this.setUpTips();
  217. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el, { childList: true, subtree: true });
  218. }
  219. disconnectedCallback() {
  220. var _a;
  221. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
  222. }
  223. // --------------------------------------------------------------------------
  224. //
  225. // Public Methods
  226. //
  227. // --------------------------------------------------------------------------
  228. /** Selects the next `calcite-tip` to display. */
  229. async nextTip() {
  230. this.direction = "advancing";
  231. const nextIndex = this.selectedIndex + 1;
  232. this.selectedIndex = (nextIndex + this.total) % this.total;
  233. }
  234. /** Selects the previous `calcite-tip` to display. */
  235. async previousTip() {
  236. this.direction = "retreating";
  237. const previousIndex = this.selectedIndex - 1;
  238. this.selectedIndex = (previousIndex + this.total) % this.total;
  239. }
  240. // --------------------------------------------------------------------------
  241. //
  242. // Private Methods
  243. //
  244. // --------------------------------------------------------------------------
  245. setUpTips() {
  246. const tips = Array.from(this.el.querySelectorAll("calcite-tip"));
  247. this.total = tips.length;
  248. if (this.total === 0) {
  249. return;
  250. }
  251. const selectedTip = this.el.querySelector("calcite-tip[selected]");
  252. this.tips = tips;
  253. this.selectedIndex = selectedTip ? tips.indexOf(selectedTip) : 0;
  254. tips.forEach((tip) => {
  255. tip.nonDismissible = true;
  256. });
  257. this.showSelectedTip();
  258. this.updateGroupTitle();
  259. }
  260. showSelectedTip() {
  261. this.tips.forEach((tip, index) => {
  262. const isSelected = this.selectedIndex === index;
  263. tip.selected = isSelected;
  264. tip.hidden = !isSelected;
  265. });
  266. }
  267. updateGroupTitle() {
  268. const selectedTip = this.tips[this.selectedIndex];
  269. const tipParent = selectedTip.closest("calcite-tip-group");
  270. this.groupTitle = (tipParent === null || tipParent === void 0 ? void 0 : tipParent.groupTitle) || this.intlDefaultTitle || TEXT$1.defaultGroupTitle;
  271. }
  272. // --------------------------------------------------------------------------
  273. //
  274. // Render Methods
  275. //
  276. // --------------------------------------------------------------------------
  277. renderPagination() {
  278. const dir = getElementDir(this.el);
  279. const { selectedIndex, tips, total, intlNext, intlPrevious, intlPaginationLabel } = this;
  280. const nextLabel = intlNext || TEXT$1.next;
  281. const previousLabel = intlPrevious || TEXT$1.previous;
  282. const paginationLabel = intlPaginationLabel || TEXT$1.defaultPaginationLabel;
  283. return tips.length > 1 ? (h("footer", { class: CSS$1.pagination }, h("calcite-action", { class: CSS$1.pagePrevious, icon: dir === "ltr" ? ICONS$1.chevronLeft : ICONS$1.chevronRight, onClick: this.previousClicked, scale: "m", text: previousLabel }), h("span", { class: CSS$1.pagePosition }, `${paginationLabel} ${selectedIndex + 1}/${total}`), h("calcite-action", { class: CSS$1.pageNext, icon: dir === "ltr" ? ICONS$1.chevronRight : ICONS$1.chevronLeft, onClick: this.nextClicked, scale: "m", text: nextLabel }))) : null;
  284. }
  285. render() {
  286. const { closed, direction, headingLevel, groupTitle, selectedIndex, intlClose, total } = this;
  287. const closeLabel = intlClose || TEXT$1.close;
  288. if (total === 0) {
  289. return null;
  290. }
  291. return (h("section", { "aria-hidden": toAriaBoolean(closed), class: CSS$1.container, hidden: closed, onKeyDown: this.tipManagerKeyDownHandler, ref: this.storeContainerRef, tabIndex: 0 }, h("header", { class: CSS$1.header }, h(Heading, { class: CSS$1.heading, level: headingLevel || HEADING_LEVEL$1 }, groupTitle), h("calcite-action", { class: CSS$1.close, onClick: this.hideTipManager, scale: "m", text: closeLabel }, h("calcite-icon", { icon: ICONS$1.close, scale: "m" }))), h("div", { class: {
  292. [CSS$1.tipContainer]: true,
  293. [CSS$1.tipContainerAdvancing]: !closed && direction === "advancing",
  294. [CSS$1.tipContainerRetreating]: !closed && direction === "retreating"
  295. }, key: selectedIndex, tabIndex: 0 }, h("slot", null)), this.renderPagination()));
  296. }
  297. get el() { return getElement(this); }
  298. static get watchers() { return {
  299. "closed": ["closedChangeHandler"],
  300. "selectedIndex": ["selectedChangeHandler"]
  301. }; }
  302. };
  303. TipManager.style = tipManagerCss;
  304. export { Tip as calcite_tip, TipGroup as calcite_tip_group, TipManager as calcite_tip_manager };