input-message.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 { Host, h } 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. /** When `true`, the component is active. */
  20. this.active = false;
  21. /** Specifies the size of the component. */
  22. this.scale = "m";
  23. /** Specifies the status of the input field, which 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 }, this.renderIcon(this.requestedIcon), h("slot", null)));
  42. }
  43. //--------------------------------------------------------------------------
  44. //
  45. // Private Methods
  46. //
  47. //--------------------------------------------------------------------------
  48. renderIcon(iconName) {
  49. if (iconName) {
  50. return h("calcite-icon", { class: "calcite-input-message-icon", icon: iconName, scale: "s" });
  51. }
  52. }
  53. static get is() { return "calcite-input-message"; }
  54. static get encapsulation() { return "shadow"; }
  55. static get originalStyleUrls() {
  56. return {
  57. "$": ["input-message.scss"]
  58. };
  59. }
  60. static get styleUrls() {
  61. return {
  62. "$": ["input-message.css"]
  63. };
  64. }
  65. static get properties() {
  66. return {
  67. "active": {
  68. "type": "boolean",
  69. "mutable": false,
  70. "complexType": {
  71. "original": "boolean",
  72. "resolved": "boolean",
  73. "references": {}
  74. },
  75. "required": false,
  76. "optional": false,
  77. "docs": {
  78. "tags": [],
  79. "text": "When `true`, the component is active."
  80. },
  81. "attribute": "active",
  82. "reflect": true,
  83. "defaultValue": "false"
  84. },
  85. "icon": {
  86. "type": "any",
  87. "mutable": false,
  88. "complexType": {
  89. "original": "boolean | string",
  90. "resolved": "boolean | string",
  91. "references": {}
  92. },
  93. "required": false,
  94. "optional": false,
  95. "docs": {
  96. "tags": [],
  97. "text": "Specifies an icon to display."
  98. },
  99. "attribute": "icon",
  100. "reflect": true
  101. },
  102. "scale": {
  103. "type": "string",
  104. "mutable": true,
  105. "complexType": {
  106. "original": "Scale",
  107. "resolved": "\"l\" | \"m\" | \"s\"",
  108. "references": {
  109. "Scale": {
  110. "location": "import",
  111. "path": "../interfaces"
  112. }
  113. }
  114. },
  115. "required": false,
  116. "optional": false,
  117. "docs": {
  118. "tags": [],
  119. "text": "Specifies the size of the component."
  120. },
  121. "attribute": "scale",
  122. "reflect": true,
  123. "defaultValue": "\"m\""
  124. },
  125. "status": {
  126. "type": "string",
  127. "mutable": true,
  128. "complexType": {
  129. "original": "Status",
  130. "resolved": "\"idle\" | \"invalid\" | \"valid\"",
  131. "references": {
  132. "Status": {
  133. "location": "import",
  134. "path": "../interfaces"
  135. }
  136. }
  137. },
  138. "required": false,
  139. "optional": false,
  140. "docs": {
  141. "tags": [],
  142. "text": "Specifies the status of the input field, which determines message and icons."
  143. },
  144. "attribute": "status",
  145. "reflect": true,
  146. "defaultValue": "\"idle\""
  147. },
  148. "type": {
  149. "type": "string",
  150. "mutable": false,
  151. "complexType": {
  152. "original": "\"default\"",
  153. "resolved": "\"default\"",
  154. "references": {}
  155. },
  156. "required": false,
  157. "optional": false,
  158. "docs": {
  159. "tags": [{
  160. "name": "deprecated",
  161. "text": "The `\"floating\"` type is no longer supported."
  162. }],
  163. "text": "Specifies the appearance of a slotted message - `\"default\"` (displayed under the component), or `\"floating\"` (positioned absolutely under the component)."
  164. },
  165. "attribute": "type",
  166. "reflect": true
  167. }
  168. };
  169. }
  170. static get elementRef() { return "el"; }
  171. static get watchers() {
  172. return [{
  173. "propName": "status",
  174. "methodName": "handleIconEl"
  175. }, {
  176. "propName": "icon",
  177. "methodName": "handleIconEl"
  178. }];
  179. }
  180. }