input-message.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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, Host, h, Prop, Watch } from "@stencil/core";
  7. import { getElementProp, setRequestedIcon } from "../../utils/dom";
  8. import { StatusIconDefaults } from "./interfaces";
  9. /**
  10. * @slot - A slot for adding text.
  11. */
  12. export class InputMessage {
  13. constructor() {
  14. //--------------------------------------------------------------------------
  15. //
  16. // Properties
  17. //
  18. //--------------------------------------------------------------------------
  19. /** Indicates whether the message is displayed. */
  20. this.active = false;
  21. /** specify the scale of the input, defaults to m */
  22. this.scale = "m";
  23. /** specify the status of the input field, determines message and icons */
  24. this.status = "idle";
  25. }
  26. handleIconEl() {
  27. this.requestedIcon = setRequestedIcon(StatusIconDefaults, this.icon, this.status);
  28. }
  29. //--------------------------------------------------------------------------
  30. //
  31. // Lifecycle
  32. //
  33. //--------------------------------------------------------------------------
  34. connectedCallback() {
  35. this.status = getElementProp(this.el, "status", this.status);
  36. this.scale = getElementProp(this.el, "scale", this.scale);
  37. this.requestedIcon = setRequestedIcon(StatusIconDefaults, this.icon, this.status);
  38. }
  39. render() {
  40. const hidden = !this.active;
  41. return (h(Host, { "calcite-hydrated-hidden": hidden },
  42. this.renderIcon(this.requestedIcon),
  43. h("slot", null)));
  44. }
  45. //--------------------------------------------------------------------------
  46. //
  47. // Private Methods
  48. //
  49. //--------------------------------------------------------------------------
  50. renderIcon(iconName) {
  51. if (iconName) {
  52. return h("calcite-icon", { class: "calcite-input-message-icon", icon: iconName, scale: "s" });
  53. }
  54. }
  55. static get is() { return "calcite-input-message"; }
  56. static get encapsulation() { return "shadow"; }
  57. static get originalStyleUrls() { return {
  58. "$": ["input-message.scss"]
  59. }; }
  60. static get styleUrls() { return {
  61. "$": ["input-message.css"]
  62. }; }
  63. static get properties() { return {
  64. "active": {
  65. "type": "boolean",
  66. "mutable": false,
  67. "complexType": {
  68. "original": "boolean",
  69. "resolved": "boolean",
  70. "references": {}
  71. },
  72. "required": false,
  73. "optional": false,
  74. "docs": {
  75. "tags": [],
  76. "text": "Indicates whether the message is displayed."
  77. },
  78. "attribute": "active",
  79. "reflect": true,
  80. "defaultValue": "false"
  81. },
  82. "icon": {
  83. "type": "any",
  84. "mutable": false,
  85. "complexType": {
  86. "original": "boolean | string",
  87. "resolved": "boolean | string",
  88. "references": {}
  89. },
  90. "required": false,
  91. "optional": false,
  92. "docs": {
  93. "tags": [],
  94. "text": "when used as a boolean set to true, show a default icon based on status. You can\nalso pass a calcite-ui-icon name to this prop to display a custom icon"
  95. },
  96. "attribute": "icon",
  97. "reflect": true
  98. },
  99. "scale": {
  100. "type": "string",
  101. "mutable": true,
  102. "complexType": {
  103. "original": "Scale",
  104. "resolved": "\"l\" | \"m\" | \"s\"",
  105. "references": {
  106. "Scale": {
  107. "location": "import",
  108. "path": "../interfaces"
  109. }
  110. }
  111. },
  112. "required": false,
  113. "optional": false,
  114. "docs": {
  115. "tags": [],
  116. "text": "specify the scale of the input, defaults to m"
  117. },
  118. "attribute": "scale",
  119. "reflect": true,
  120. "defaultValue": "\"m\""
  121. },
  122. "status": {
  123. "type": "string",
  124. "mutable": true,
  125. "complexType": {
  126. "original": "Status",
  127. "resolved": "\"idle\" | \"invalid\" | \"valid\"",
  128. "references": {
  129. "Status": {
  130. "location": "import",
  131. "path": "../interfaces"
  132. }
  133. }
  134. },
  135. "required": false,
  136. "optional": false,
  137. "docs": {
  138. "tags": [],
  139. "text": "specify the status of the input field, determines message and icons"
  140. },
  141. "attribute": "status",
  142. "reflect": true,
  143. "defaultValue": "\"idle\""
  144. },
  145. "type": {
  146. "type": "string",
  147. "mutable": false,
  148. "complexType": {
  149. "original": "\"default\"",
  150. "resolved": "\"default\"",
  151. "references": {}
  152. },
  153. "required": false,
  154. "optional": false,
  155. "docs": {
  156. "tags": [{
  157. "name": "deprecated",
  158. "text": "\"floating\" type is no longer supported"
  159. }],
  160. "text": "specify the appearance of any slotted message - default (displayed under input), or floating (positioned absolutely under input)"
  161. },
  162. "attribute": "type",
  163. "reflect": true
  164. }
  165. }; }
  166. static get elementRef() { return "el"; }
  167. static get watchers() { return [{
  168. "propName": "status",
  169. "methodName": "handleIconEl"
  170. }, {
  171. "propName": "icon",
  172. "methodName": "handleIconEl"
  173. }]; }
  174. }