calcite-tip.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 { proxyCustomElement, HTMLElement, createEvent, h, Fragment } from '@stencil/core/internal/client/index.js';
  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 = "@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%}";
  34. const Tip = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  35. constructor() {
  36. super();
  37. this.__registerHost();
  38. this.__attachShadow();
  39. this.calciteTipDismiss = createEvent(this, "calciteTipDismiss", 6);
  40. // --------------------------------------------------------------------------
  41. //
  42. // Properties
  43. //
  44. // --------------------------------------------------------------------------
  45. /**
  46. * When `true`, the component does not display.
  47. */
  48. this.dismissed = false;
  49. /**
  50. * When `true`, the close button is not present on the component.
  51. */
  52. this.nonDismissible = false;
  53. /**
  54. * When `true`, the component is selected if it has a parent `calcite-tip-manager`.
  55. *
  56. * Only one tip can be selected within the `calcite-tip-manager` parent.
  57. */
  58. this.selected = false;
  59. // --------------------------------------------------------------------------
  60. //
  61. // Private Methods
  62. //
  63. // --------------------------------------------------------------------------
  64. this.hideTip = () => {
  65. this.dismissed = true;
  66. this.calciteTipDismiss.emit();
  67. };
  68. }
  69. // --------------------------------------------------------------------------
  70. //
  71. // Lifecycle
  72. //
  73. // --------------------------------------------------------------------------
  74. connectedCallback() {
  75. connectConditionalSlotComponent(this);
  76. }
  77. disconnectedCallback() {
  78. disconnectConditionalSlotComponent(this);
  79. }
  80. // --------------------------------------------------------------------------
  81. //
  82. // Render Methods
  83. //
  84. // --------------------------------------------------------------------------
  85. renderHeader() {
  86. var _a;
  87. const { heading, headingLevel, el } = this;
  88. const parentLevel = (_a = el.closest("calcite-tip-manager")) === null || _a === void 0 ? void 0 : _a.headingLevel;
  89. const relativeLevel = parentLevel ? constrainHeadingLevel(parentLevel + 1) : null;
  90. const level = headingLevel || relativeLevel || HEADING_LEVEL;
  91. return heading ? (h("header", { class: CSS.header }, h(Heading, { class: CSS.heading, level: level }, heading))) : null;
  92. }
  93. renderDismissButton() {
  94. const { nonDismissible, hideTip, intlClose } = this;
  95. const text = intlClose || TEXT.close;
  96. return !nonDismissible ? (h("calcite-action", { class: CSS.close, icon: ICONS.close, onClick: hideTip, scale: "l", text: text })) : null;
  97. }
  98. renderImageFrame() {
  99. const { el } = this;
  100. return getSlotted(el, SLOTS.thumbnail) ? (h("div", { class: CSS.imageFrame, key: "thumbnail" }, h("slot", { name: SLOTS.thumbnail }))) : null;
  101. }
  102. renderInfoNode() {
  103. return (h("div", { class: CSS.info }, h("slot", null)));
  104. }
  105. renderContent() {
  106. return (h("div", { class: CSS.content }, this.renderImageFrame(), this.renderInfoNode()));
  107. }
  108. render() {
  109. return (h(Fragment, null, h("article", { class: CSS.container }, this.renderHeader(), this.renderContent()), this.renderDismissButton()));
  110. }
  111. get el() { return this; }
  112. static get style() { return tipCss; }
  113. }, [1, "calcite-tip", {
  114. "dismissed": [1540],
  115. "nonDismissible": [516, "non-dismissible"],
  116. "heading": [1],
  117. "headingLevel": [514, "heading-level"],
  118. "selected": [516],
  119. "intlClose": [1, "intl-close"]
  120. }]);
  121. function defineCustomElement$1() {
  122. if (typeof customElements === "undefined") {
  123. return;
  124. }
  125. const components = ["calcite-tip", "calcite-action", "calcite-icon", "calcite-loader"];
  126. components.forEach(tagName => { switch (tagName) {
  127. case "calcite-tip":
  128. if (!customElements.get(tagName)) {
  129. customElements.define(tagName, Tip);
  130. }
  131. break;
  132. case "calcite-action":
  133. if (!customElements.get(tagName)) {
  134. defineCustomElement$4();
  135. }
  136. break;
  137. case "calcite-icon":
  138. if (!customElements.get(tagName)) {
  139. defineCustomElement$3();
  140. }
  141. break;
  142. case "calcite-loader":
  143. if (!customElements.get(tagName)) {
  144. defineCustomElement$2();
  145. }
  146. break;
  147. } });
  148. }
  149. defineCustomElement$1();
  150. const CalciteTip = Tip;
  151. const defineCustomElement = defineCustomElement$1;
  152. export { CalciteTip, defineCustomElement };