label.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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, Host } from "@stencil/core";
  7. import { labelDisconnectedEvent, labelConnectedEvent } from "../../utils/label";
  8. import { CSS } from "./resources";
  9. /**
  10. * @slot - A slot for adding text and a component that can be labeled.
  11. */
  12. export class Label {
  13. constructor() {
  14. //--------------------------------------------------------------------------
  15. //
  16. // Properties
  17. //
  18. //--------------------------------------------------------------------------
  19. /** Specifies the text alignment of the component. */
  20. this.alignment = "start";
  21. /**
  22. * Specifies the status of the component and any child input, or input messages.
  23. *
  24. * @deprecated Set directly on the component the label is bound to instead.
  25. */
  26. this.status = "idle";
  27. /** Specifies the size of the component. */
  28. this.scale = "m";
  29. /** Defines the layout of the label in relation to the component. Use `"inline"` positions to wrap the label and component on the same line. */
  30. this.layout = "default";
  31. /**
  32. * When `true`, interaction is prevented and the component is displayed with lower opacity.
  33. *
  34. * @deprecated Use the `disabled` property on the component the label is bound to instead.
  35. */
  36. this.disabled = false;
  37. /**
  38. * When `true`, disables the component's spacing.
  39. *
  40. * @deprecated Set the `--calcite-label-margin-bottom` css variable to `0` instead.
  41. */
  42. this.disableSpacing = false;
  43. //--------------------------------------------------------------------------
  44. //
  45. // Private Methods
  46. //
  47. //--------------------------------------------------------------------------
  48. this.labelClickHandler = (event) => {
  49. this.calciteInternalLabelClick.emit({
  50. sourceEvent: event
  51. });
  52. };
  53. }
  54. //--------------------------------------------------------------------------
  55. //
  56. // Lifecycle
  57. //
  58. //--------------------------------------------------------------------------
  59. connectedCallback() {
  60. document.dispatchEvent(new CustomEvent(labelConnectedEvent));
  61. }
  62. disconnectedCallback() {
  63. document.dispatchEvent(new CustomEvent(labelDisconnectedEvent));
  64. }
  65. render() {
  66. return (h(Host, { onClick: this.labelClickHandler }, h("div", { class: CSS.container }, h("slot", null))));
  67. }
  68. static get is() { return "calcite-label"; }
  69. static get encapsulation() { return "shadow"; }
  70. static get originalStyleUrls() {
  71. return {
  72. "$": ["label.scss"]
  73. };
  74. }
  75. static get styleUrls() {
  76. return {
  77. "$": ["label.css"]
  78. };
  79. }
  80. static get properties() {
  81. return {
  82. "alignment": {
  83. "type": "string",
  84. "mutable": false,
  85. "complexType": {
  86. "original": "Alignment",
  87. "resolved": "\"center\" | \"end\" | \"start\"",
  88. "references": {
  89. "Alignment": {
  90. "location": "import",
  91. "path": "../interfaces"
  92. }
  93. }
  94. },
  95. "required": false,
  96. "optional": false,
  97. "docs": {
  98. "tags": [],
  99. "text": "Specifies the text alignment of the component."
  100. },
  101. "attribute": "alignment",
  102. "reflect": true,
  103. "defaultValue": "\"start\""
  104. },
  105. "status": {
  106. "type": "string",
  107. "mutable": false,
  108. "complexType": {
  109. "original": "Status",
  110. "resolved": "\"idle\" | \"invalid\" | \"valid\"",
  111. "references": {
  112. "Status": {
  113. "location": "import",
  114. "path": "../interfaces"
  115. }
  116. }
  117. },
  118. "required": false,
  119. "optional": false,
  120. "docs": {
  121. "tags": [{
  122. "name": "deprecated",
  123. "text": "Set directly on the component the label is bound to instead."
  124. }],
  125. "text": "Specifies the status of the component and any child input, or input messages."
  126. },
  127. "attribute": "status",
  128. "reflect": true,
  129. "defaultValue": "\"idle\""
  130. },
  131. "for": {
  132. "type": "string",
  133. "mutable": false,
  134. "complexType": {
  135. "original": "string",
  136. "resolved": "string",
  137. "references": {}
  138. },
  139. "required": false,
  140. "optional": false,
  141. "docs": {
  142. "tags": [],
  143. "text": "Specifies the `id` of the component the label is bound to. Use when the component the label is bound to does not reside within the component."
  144. },
  145. "attribute": "for",
  146. "reflect": true
  147. },
  148. "scale": {
  149. "type": "string",
  150. "mutable": false,
  151. "complexType": {
  152. "original": "Scale",
  153. "resolved": "\"l\" | \"m\" | \"s\"",
  154. "references": {
  155. "Scale": {
  156. "location": "import",
  157. "path": "../interfaces"
  158. }
  159. }
  160. },
  161. "required": false,
  162. "optional": false,
  163. "docs": {
  164. "tags": [],
  165. "text": "Specifies the size of the component."
  166. },
  167. "attribute": "scale",
  168. "reflect": true,
  169. "defaultValue": "\"m\""
  170. },
  171. "layout": {
  172. "type": "string",
  173. "mutable": false,
  174. "complexType": {
  175. "original": "\"inline\" | \"inline-space-between\" | \"default\"",
  176. "resolved": "\"default\" | \"inline\" | \"inline-space-between\"",
  177. "references": {}
  178. },
  179. "required": false,
  180. "optional": false,
  181. "docs": {
  182. "tags": [],
  183. "text": "Defines the layout of the label in relation to the component. Use `\"inline\"` positions to wrap the label and component on the same line."
  184. },
  185. "attribute": "layout",
  186. "reflect": true,
  187. "defaultValue": "\"default\""
  188. },
  189. "disabled": {
  190. "type": "boolean",
  191. "mutable": false,
  192. "complexType": {
  193. "original": "boolean",
  194. "resolved": "boolean",
  195. "references": {}
  196. },
  197. "required": false,
  198. "optional": false,
  199. "docs": {
  200. "tags": [{
  201. "name": "deprecated",
  202. "text": "Use the `disabled` property on the component the label is bound to instead."
  203. }],
  204. "text": "When `true`, interaction is prevented and the component is displayed with lower opacity."
  205. },
  206. "attribute": "disabled",
  207. "reflect": true,
  208. "defaultValue": "false"
  209. },
  210. "disableSpacing": {
  211. "type": "boolean",
  212. "mutable": false,
  213. "complexType": {
  214. "original": "boolean",
  215. "resolved": "boolean",
  216. "references": {}
  217. },
  218. "required": false,
  219. "optional": false,
  220. "docs": {
  221. "tags": [{
  222. "name": "deprecated",
  223. "text": "Set the `--calcite-label-margin-bottom` css variable to `0` instead."
  224. }],
  225. "text": "When `true`, disables the component's spacing."
  226. },
  227. "attribute": "disable-spacing",
  228. "reflect": true,
  229. "defaultValue": "false"
  230. }
  231. };
  232. }
  233. static get events() {
  234. return [{
  235. "method": "calciteInternalLabelClick",
  236. "name": "calciteInternalLabelClick",
  237. "bubbles": false,
  238. "cancelable": false,
  239. "composed": true,
  240. "docs": {
  241. "tags": [{
  242. "name": "internal",
  243. "text": undefined
  244. }],
  245. "text": ""
  246. },
  247. "complexType": {
  248. "original": "{\n sourceEvent: MouseEvent;\n }",
  249. "resolved": "{ sourceEvent: MouseEvent; }",
  250. "references": {
  251. "MouseEvent": {
  252. "location": "global"
  253. }
  254. }
  255. }
  256. }];
  257. }
  258. static get elementRef() { return "el"; }
  259. }