tip.js 7.1 KB

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