calcite-tip_3.cjs.entry.js 19 KB

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