radio-group-item.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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, h, Prop, Element, Event, Host, Watch } from "@stencil/core";
  7. import { getElementProp, toAriaBoolean } from "../../utils/dom";
  8. import { SLOTS, CSS } from "./resources";
  9. export class RadioGroupItem {
  10. constructor() {
  11. //--------------------------------------------------------------------------
  12. //
  13. // Properties
  14. //
  15. //--------------------------------------------------------------------------
  16. /** Indicates whether the control is checked. */
  17. this.checked = false;
  18. /** flip the icon in rtl */
  19. this.iconFlipRtl = false;
  20. /** optionally used with icon, select where to position the icon */
  21. this.iconPosition = "start";
  22. }
  23. handleCheckedChange() {
  24. this.calciteRadioGroupItemChange.emit();
  25. }
  26. render() {
  27. const { checked, value } = this;
  28. const scale = getElementProp(this.el, "scale", "m");
  29. const appearance = getElementProp(this.el, "appearance", "solid");
  30. const layout = getElementProp(this.el, "layout", "horizontal");
  31. const iconEl = (h("calcite-icon", { class: CSS.radioGroupItemIcon, flipRtl: this.iconFlipRtl, icon: this.icon, scale: "s" }));
  32. return (h(Host, { "aria-checked": toAriaBoolean(checked), role: "radio" },
  33. h("label", { class: {
  34. "label--scale-s": scale === "s",
  35. "label--scale-m": scale === "m",
  36. "label--scale-l": scale === "l",
  37. "label--horizontal": layout === "horizontal",
  38. "label--outline": appearance === "outline"
  39. } },
  40. this.icon && this.iconPosition === "start" ? iconEl : null,
  41. h("slot", null, value),
  42. h("slot", { name: SLOTS.input }),
  43. this.icon && this.iconPosition === "end" ? iconEl : null)));
  44. }
  45. static get is() { return "calcite-radio-group-item"; }
  46. static get encapsulation() { return "shadow"; }
  47. static get originalStyleUrls() { return {
  48. "$": ["radio-group-item.scss"]
  49. }; }
  50. static get styleUrls() { return {
  51. "$": ["radio-group-item.css"]
  52. }; }
  53. static get properties() { return {
  54. "checked": {
  55. "type": "boolean",
  56. "mutable": true,
  57. "complexType": {
  58. "original": "boolean",
  59. "resolved": "boolean",
  60. "references": {}
  61. },
  62. "required": false,
  63. "optional": false,
  64. "docs": {
  65. "tags": [],
  66. "text": "Indicates whether the control is checked."
  67. },
  68. "attribute": "checked",
  69. "reflect": true,
  70. "defaultValue": "false"
  71. },
  72. "icon": {
  73. "type": "string",
  74. "mutable": false,
  75. "complexType": {
  76. "original": "string",
  77. "resolved": "string",
  78. "references": {}
  79. },
  80. "required": false,
  81. "optional": true,
  82. "docs": {
  83. "tags": [],
  84. "text": "optionally pass an icon to display - accepts Calcite UI icon names"
  85. },
  86. "attribute": "icon",
  87. "reflect": true
  88. },
  89. "iconFlipRtl": {
  90. "type": "boolean",
  91. "mutable": false,
  92. "complexType": {
  93. "original": "boolean",
  94. "resolved": "boolean",
  95. "references": {}
  96. },
  97. "required": false,
  98. "optional": false,
  99. "docs": {
  100. "tags": [],
  101. "text": "flip the icon in rtl"
  102. },
  103. "attribute": "icon-flip-rtl",
  104. "reflect": true,
  105. "defaultValue": "false"
  106. },
  107. "iconPosition": {
  108. "type": "string",
  109. "mutable": false,
  110. "complexType": {
  111. "original": "Position",
  112. "resolved": "\"end\" | \"start\"",
  113. "references": {
  114. "Position": {
  115. "location": "import",
  116. "path": "../interfaces"
  117. }
  118. }
  119. },
  120. "required": false,
  121. "optional": true,
  122. "docs": {
  123. "tags": [],
  124. "text": "optionally used with icon, select where to position the icon"
  125. },
  126. "attribute": "icon-position",
  127. "reflect": true,
  128. "defaultValue": "\"start\""
  129. },
  130. "value": {
  131. "type": "any",
  132. "mutable": true,
  133. "complexType": {
  134. "original": "any | null",
  135. "resolved": "any",
  136. "references": {}
  137. },
  138. "required": false,
  139. "optional": false,
  140. "docs": {
  141. "tags": [],
  142. "text": "The control's value."
  143. },
  144. "attribute": "value",
  145. "reflect": false
  146. }
  147. }; }
  148. static get events() { return [{
  149. "method": "calciteRadioGroupItemChange",
  150. "name": "calciteRadioGroupItemChange",
  151. "bubbles": true,
  152. "cancelable": true,
  153. "composed": true,
  154. "docs": {
  155. "tags": [{
  156. "name": "internal",
  157. "text": undefined
  158. }],
  159. "text": "Fires when the item has been selected."
  160. },
  161. "complexType": {
  162. "original": "any",
  163. "resolved": "any",
  164. "references": {}
  165. }
  166. }]; }
  167. static get elementRef() { return "el"; }
  168. static get watchers() { return [{
  169. "propName": "checked",
  170. "methodName": "handleCheckedChange"
  171. }]; }
  172. }