tip.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 { Component, Element, Event, Prop, h, Fragment } from "@stencil/core";
  7. import { CSS, ICONS, SLOTS, TEXT, HEADING_LEVEL } from "./resources";
  8. import { getSlotted } from "../../utils/dom";
  9. import { Heading, constrainHeadingLevel } from "../functional/Heading";
  10. import { connectConditionalSlotComponent, disconnectConditionalSlotComponent } from "../../utils/conditionalSlot";
  11. /**
  12. * @slot - A slot for adding text and a hyperlink.
  13. * @slot thumbnail - A slot for adding an HTML image element to the tip.
  14. */
  15. export class Tip {
  16. constructor() {
  17. // --------------------------------------------------------------------------
  18. //
  19. // Properties
  20. //
  21. // --------------------------------------------------------------------------
  22. /**
  23. * No longer displays the tip.
  24. */
  25. this.dismissed = false;
  26. /**
  27. * Indicates whether the tip can be dismissed.
  28. */
  29. this.nonDismissible = false;
  30. /**
  31. * The selected state of the tip if it is being used inside a `calcite-tip-manager`.
  32. */
  33. this.selected = false;
  34. // --------------------------------------------------------------------------
  35. //
  36. // Private Methods
  37. //
  38. // --------------------------------------------------------------------------
  39. this.hideTip = () => {
  40. this.dismissed = true;
  41. this.calciteTipDismiss.emit();
  42. };
  43. }
  44. // --------------------------------------------------------------------------
  45. //
  46. // Lifecycle
  47. //
  48. // --------------------------------------------------------------------------
  49. connectedCallback() {
  50. connectConditionalSlotComponent(this);
  51. }
  52. disconnectedCallback() {
  53. disconnectConditionalSlotComponent(this);
  54. }
  55. // --------------------------------------------------------------------------
  56. //
  57. // Render Methods
  58. //
  59. // --------------------------------------------------------------------------
  60. renderHeader() {
  61. var _a;
  62. const { heading, headingLevel, el } = this;
  63. const parentLevel = (_a = el.closest("calcite-tip-manager")) === null || _a === void 0 ? void 0 : _a.headingLevel;
  64. const relativeLevel = parentLevel ? constrainHeadingLevel(parentLevel + 1) : null;
  65. const level = headingLevel || relativeLevel || HEADING_LEVEL;
  66. return heading ? (h("header", { class: CSS.header },
  67. h(Heading, { class: CSS.heading, level: level }, heading))) : null;
  68. }
  69. renderDismissButton() {
  70. const { nonDismissible, hideTip, intlClose } = this;
  71. const text = intlClose || TEXT.close;
  72. return !nonDismissible ? (h("calcite-action", { class: CSS.close, icon: ICONS.close, onClick: hideTip, scale: "l", text: text })) : null;
  73. }
  74. renderImageFrame() {
  75. const { el } = this;
  76. return getSlotted(el, SLOTS.thumbnail) ? (h("div", { class: CSS.imageFrame, key: "thumbnail" },
  77. h("slot", { name: SLOTS.thumbnail }))) : null;
  78. }
  79. renderInfoNode() {
  80. return (h("div", { class: CSS.info },
  81. h("slot", null)));
  82. }
  83. renderContent() {
  84. return (h("div", { class: CSS.content },
  85. this.renderImageFrame(),
  86. this.renderInfoNode()));
  87. }
  88. render() {
  89. return (h(Fragment, null,
  90. h("article", { class: CSS.container },
  91. this.renderHeader(),
  92. this.renderContent()),
  93. this.renderDismissButton()));
  94. }
  95. static get is() { return "calcite-tip"; }
  96. static get encapsulation() { return "shadow"; }
  97. static get originalStyleUrls() { return {
  98. "$": ["tip.scss"]
  99. }; }
  100. static get styleUrls() { return {
  101. "$": ["tip.css"]
  102. }; }
  103. static get properties() { return {
  104. "dismissed": {
  105. "type": "boolean",
  106. "mutable": true,
  107. "complexType": {
  108. "original": "boolean",
  109. "resolved": "boolean",
  110. "references": {}
  111. },
  112. "required": false,
  113. "optional": false,
  114. "docs": {
  115. "tags": [],
  116. "text": "No longer displays the tip."
  117. },
  118. "attribute": "dismissed",
  119. "reflect": true,
  120. "defaultValue": "false"
  121. },
  122. "nonDismissible": {
  123. "type": "boolean",
  124. "mutable": false,
  125. "complexType": {
  126. "original": "boolean",
  127. "resolved": "boolean",
  128. "references": {}
  129. },
  130. "required": false,
  131. "optional": false,
  132. "docs": {
  133. "tags": [],
  134. "text": "Indicates whether the tip can be dismissed."
  135. },
  136. "attribute": "non-dismissible",
  137. "reflect": true,
  138. "defaultValue": "false"
  139. },
  140. "heading": {
  141. "type": "string",
  142. "mutable": false,
  143. "complexType": {
  144. "original": "string",
  145. "resolved": "string",
  146. "references": {}
  147. },
  148. "required": false,
  149. "optional": true,
  150. "docs": {
  151. "tags": [],
  152. "text": "The heading of the tip."
  153. },
  154. "attribute": "heading",
  155. "reflect": false
  156. },
  157. "headingLevel": {
  158. "type": "number",
  159. "mutable": false,
  160. "complexType": {
  161. "original": "HeadingLevel",
  162. "resolved": "1 | 2 | 3 | 4 | 5 | 6",
  163. "references": {
  164. "HeadingLevel": {
  165. "location": "import",
  166. "path": "../functional/Heading"
  167. }
  168. }
  169. },
  170. "required": false,
  171. "optional": false,
  172. "docs": {
  173. "tags": [],
  174. "text": "Number at which section headings should start for this component."
  175. },
  176. "attribute": "heading-level",
  177. "reflect": false
  178. },
  179. "selected": {
  180. "type": "boolean",
  181. "mutable": false,
  182. "complexType": {
  183. "original": "boolean",
  184. "resolved": "boolean",
  185. "references": {}
  186. },
  187. "required": false,
  188. "optional": false,
  189. "docs": {
  190. "tags": [],
  191. "text": "The selected state of the tip if it is being used inside a `calcite-tip-manager`."
  192. },
  193. "attribute": "selected",
  194. "reflect": true,
  195. "defaultValue": "false"
  196. },
  197. "intlClose": {
  198. "type": "string",
  199. "mutable": false,
  200. "complexType": {
  201. "original": "string",
  202. "resolved": "string",
  203. "references": {}
  204. },
  205. "required": false,
  206. "optional": true,
  207. "docs": {
  208. "tags": [],
  209. "text": "Alternate text for closing the tip."
  210. },
  211. "attribute": "intl-close",
  212. "reflect": false
  213. }
  214. }; }
  215. static get events() { return [{
  216. "method": "calciteTipDismiss",
  217. "name": "calciteTipDismiss",
  218. "bubbles": true,
  219. "cancelable": true,
  220. "composed": true,
  221. "docs": {
  222. "tags": [],
  223. "text": "Emitted when the component has been dismissed."
  224. },
  225. "complexType": {
  226. "original": "any",
  227. "resolved": "any",
  228. "references": {}
  229. }
  230. }]; }
  231. static get elementRef() { return "el"; }
  232. }