calcite-tip.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*!
  2. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  4. * v1.0.0-beta.82
  5. */
  6. import { proxyCustomElement, HTMLElement, createEvent, h, Fragment } from '@stencil/core/internal/client';
  7. import { H as HEADING_LEVEL$1 } from './resources3.js';
  8. import { b as getSlotted } from './dom.js';
  9. import { H as Heading, c as constrainHeadingLevel } from './Heading.js';
  10. import { c as connectConditionalSlotComponent, d as disconnectConditionalSlotComponent } from './conditionalSlot.js';
  11. import { d as defineCustomElement$4 } from './action.js';
  12. import { d as defineCustomElement$3 } from './icon.js';
  13. import { d as defineCustomElement$2 } from './loader.js';
  14. const CSS = {
  15. container: "container",
  16. header: "header",
  17. heading: "heading",
  18. close: "close",
  19. imageFrame: "image-frame",
  20. content: "content",
  21. info: "info"
  22. };
  23. const ICONS = {
  24. close: "x"
  25. };
  26. const SLOTS = {
  27. thumbnail: "thumbnail"
  28. };
  29. const TEXT = {
  30. close: "Close"
  31. };
  32. const HEADING_LEVEL = (HEADING_LEVEL$1 + 1);
  33. const tipCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{position:relative;margin:1rem;-webkit-box-sizing:border-box;box-sizing:border-box;display:-ms-flexbox;display:flex;-ms-flex-direction:row;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 *{-webkit-box-sizing:border-box;box-sizing:border-box}.container{width:100%;padding:1rem}:host([dismissed]),:host([dismissed]) .container{display:none}:host([selected]) .container{margin:0px;border-style:none;padding:0px}.header{margin:0px;display:-ms-flexbox;display:flex;-ms-flex-line-pack:justify;align-content:space-between;-ms-flex-align:center;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{-ms-flex:1 1 auto;flex:1 1 auto;padding:0.5rem}h1.heading{font-size:var(--calcite-font-size-2);line-height:1.5rem}h2.heading{font-size:var(--calcite-font-size-1);line-height:1.5rem}h3.heading{font-size:var(--calcite-font-size-0);line-height:1.25rem}h4.heading,h5.heading{font-size:var(--calcite-font-size--1);line-height:1rem}.header{margin-bottom:0.5rem}.header .heading{padding:0px;color:var(--calcite-ui-text-1)}.container[hidden]{display:none}.content{display:-ms-flexbox;display:flex}.info{padding-top:0px;padding-bottom:0px;padding-left:1rem;padding-right:1rem;width:70%}.info:only-child{width:100%;padding-left:0px;padding-right:0px}::slotted(p){margin-top:0px}::slotted(a){outline-offset:0;outline-color:transparent;-webkit-transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;color:var(--calcite-ui-brand)}::slotted(a:focus){outline:2px solid var(--calcite-ui-brand);outline-offset:2px}.image-frame{width:25%}.image-frame img{max-width:100%}::slotted(img){max-width:100%}";
  34. const Tip = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  35. constructor() {
  36. super();
  37. this.__registerHost();
  38. this.__attachShadow();
  39. this.calciteTipDismiss = createEvent(this, "calciteTipDismiss", 7);
  40. // --------------------------------------------------------------------------
  41. //
  42. // Properties
  43. //
  44. // --------------------------------------------------------------------------
  45. /**
  46. * No longer displays the tip.
  47. */
  48. this.dismissed = false;
  49. /**
  50. * Indicates whether the tip can be dismissed.
  51. */
  52. this.nonDismissible = false;
  53. /**
  54. * The selected state of the tip if it is being used inside a `calcite-tip-manager`.
  55. */
  56. this.selected = false;
  57. // --------------------------------------------------------------------------
  58. //
  59. // Private Methods
  60. //
  61. // --------------------------------------------------------------------------
  62. this.hideTip = () => {
  63. this.dismissed = true;
  64. this.calciteTipDismiss.emit();
  65. };
  66. }
  67. // --------------------------------------------------------------------------
  68. //
  69. // Lifecycle
  70. //
  71. // --------------------------------------------------------------------------
  72. connectedCallback() {
  73. connectConditionalSlotComponent(this);
  74. }
  75. disconnectedCallback() {
  76. disconnectConditionalSlotComponent(this);
  77. }
  78. // --------------------------------------------------------------------------
  79. //
  80. // Render Methods
  81. //
  82. // --------------------------------------------------------------------------
  83. renderHeader() {
  84. var _a;
  85. const { heading, headingLevel, el } = this;
  86. const parentLevel = (_a = el.closest("calcite-tip-manager")) === null || _a === void 0 ? void 0 : _a.headingLevel;
  87. const relativeLevel = parentLevel ? constrainHeadingLevel(parentLevel + 1) : null;
  88. const level = headingLevel || relativeLevel || HEADING_LEVEL;
  89. return heading ? (h("header", { class: CSS.header }, h(Heading, { class: CSS.heading, level: level }, heading))) : null;
  90. }
  91. renderDismissButton() {
  92. const { nonDismissible, hideTip, intlClose } = this;
  93. const text = intlClose || TEXT.close;
  94. return !nonDismissible ? (h("calcite-action", { class: CSS.close, icon: ICONS.close, onClick: hideTip, scale: "l", text: text })) : null;
  95. }
  96. renderImageFrame() {
  97. const { el } = this;
  98. return getSlotted(el, SLOTS.thumbnail) ? (h("div", { class: CSS.imageFrame, key: "thumbnail" }, h("slot", { name: SLOTS.thumbnail }))) : null;
  99. }
  100. renderInfoNode() {
  101. return (h("div", { class: CSS.info }, h("slot", null)));
  102. }
  103. renderContent() {
  104. return (h("div", { class: CSS.content }, this.renderImageFrame(), this.renderInfoNode()));
  105. }
  106. render() {
  107. return (h(Fragment, null, h("article", { class: CSS.container }, this.renderHeader(), this.renderContent()), this.renderDismissButton()));
  108. }
  109. get el() { return this; }
  110. static get style() { return tipCss; }
  111. }, [1, "calcite-tip", {
  112. "dismissed": [1540],
  113. "nonDismissible": [516, "non-dismissible"],
  114. "heading": [1],
  115. "headingLevel": [2, "heading-level"],
  116. "selected": [516],
  117. "intlClose": [1, "intl-close"]
  118. }]);
  119. function defineCustomElement$1() {
  120. if (typeof customElements === "undefined") {
  121. return;
  122. }
  123. const components = ["calcite-tip", "calcite-action", "calcite-icon", "calcite-loader"];
  124. components.forEach(tagName => { switch (tagName) {
  125. case "calcite-tip":
  126. if (!customElements.get(tagName)) {
  127. customElements.define(tagName, Tip);
  128. }
  129. break;
  130. case "calcite-action":
  131. if (!customElements.get(tagName)) {
  132. defineCustomElement$4();
  133. }
  134. break;
  135. case "calcite-icon":
  136. if (!customElements.get(tagName)) {
  137. defineCustomElement$3();
  138. }
  139. break;
  140. case "calcite-loader":
  141. if (!customElements.get(tagName)) {
  142. defineCustomElement$2();
  143. }
  144. break;
  145. } });
  146. }
  147. defineCustomElement$1();
  148. const CalciteTip = Tip;
  149. const defineCustomElement = defineCustomElement$1;
  150. export { CalciteTip, defineCustomElement };