radio-group-item.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 { getElementProp, toAriaBoolean } from "../../utils/dom";
  8. import { SLOTS, CSS } from "./resources";
  9. export class RadioGroupItem {
  10. constructor() {
  11. //--------------------------------------------------------------------------
  12. //
  13. // Properties
  14. //
  15. //--------------------------------------------------------------------------
  16. /** When `true`, the component is checked. */
  17. this.checked = false;
  18. /** When `true`, the icon will be flipped when the element direction is right-to-left (`"rtl"`). */
  19. this.iconFlipRtl = false;
  20. /**
  21. * Specifies the placement of the icon.
  22. *
  23. * @deprecated Use either `iconStart` or `iconEnd` but do not combine them with `icon` and `iconPosition`.
  24. */
  25. this.iconPosition = "start";
  26. }
  27. handleCheckedChange() {
  28. this.calciteInternalRadioGroupItemChange.emit();
  29. }
  30. render() {
  31. const { checked, value } = this;
  32. const scale = getElementProp(this.el, "scale", "m");
  33. const appearance = getElementProp(this.el, "appearance", "solid");
  34. const layout = getElementProp(this.el, "layout", "horizontal");
  35. const iconStartEl = this.iconStart ? (h("calcite-icon", { class: CSS.radioGroupItemIcon, flipRtl: this.iconFlipRtl, icon: this.iconStart, key: "icon-start", scale: "s" })) : null;
  36. const iconEndEl = this.iconEnd ? (h("calcite-icon", { class: CSS.radioGroupItemIcon, flipRtl: this.iconFlipRtl, icon: this.iconEnd, key: "icon-end", scale: "s" })) : null;
  37. const iconEl = (h("calcite-icon", { class: CSS.radioGroupItemIcon, flipRtl: this.iconFlipRtl, icon: this.icon, key: "icon", scale: "s" }));
  38. const iconAtStart = this.icon && this.iconPosition === "start" && !this.iconStart ? iconEl : null;
  39. const iconAtEnd = this.icon && this.iconPosition === "end" && !this.iconEnd ? iconEl : null;
  40. return (h(Host, { "aria-checked": toAriaBoolean(checked), "aria-label": value, role: "radio" }, h("label", { class: {
  41. "label--scale-s": scale === "s",
  42. "label--scale-m": scale === "m",
  43. "label--scale-l": scale === "l",
  44. "label--horizontal": layout === "horizontal",
  45. "label--outline": appearance === "outline"
  46. } }, iconAtStart, this.iconStart ? iconStartEl : null, h("slot", null, value), h("slot", { name: SLOTS.input }), iconAtEnd, this.iconEnd ? iconEndEl : null)));
  47. }
  48. static get is() { return "calcite-radio-group-item"; }
  49. static get encapsulation() { return "shadow"; }
  50. static get originalStyleUrls() {
  51. return {
  52. "$": ["radio-group-item.scss"]
  53. };
  54. }
  55. static get styleUrls() {
  56. return {
  57. "$": ["radio-group-item.css"]
  58. };
  59. }
  60. static get properties() {
  61. return {
  62. "checked": {
  63. "type": "boolean",
  64. "mutable": true,
  65. "complexType": {
  66. "original": "boolean",
  67. "resolved": "boolean",
  68. "references": {}
  69. },
  70. "required": false,
  71. "optional": false,
  72. "docs": {
  73. "tags": [],
  74. "text": "When `true`, the component is checked."
  75. },
  76. "attribute": "checked",
  77. "reflect": true,
  78. "defaultValue": "false"
  79. },
  80. "icon": {
  81. "type": "string",
  82. "mutable": false,
  83. "complexType": {
  84. "original": "string",
  85. "resolved": "string",
  86. "references": {}
  87. },
  88. "required": false,
  89. "optional": true,
  90. "docs": {
  91. "tags": [{
  92. "name": "deprecated",
  93. "text": "Use either `iconStart` or `iconEnd` but do not combine them with `icon` and `iconPosition`."
  94. }],
  95. "text": "Specifies an icon to display."
  96. },
  97. "attribute": "icon",
  98. "reflect": true
  99. },
  100. "iconFlipRtl": {
  101. "type": "boolean",
  102. "mutable": false,
  103. "complexType": {
  104. "original": "boolean",
  105. "resolved": "boolean",
  106. "references": {}
  107. },
  108. "required": false,
  109. "optional": false,
  110. "docs": {
  111. "tags": [],
  112. "text": "When `true`, the icon will be flipped when the element direction is right-to-left (`\"rtl\"`)."
  113. },
  114. "attribute": "icon-flip-rtl",
  115. "reflect": true,
  116. "defaultValue": "false"
  117. },
  118. "iconPosition": {
  119. "type": "string",
  120. "mutable": false,
  121. "complexType": {
  122. "original": "Position",
  123. "resolved": "\"end\" | \"start\"",
  124. "references": {
  125. "Position": {
  126. "location": "import",
  127. "path": "../interfaces"
  128. }
  129. }
  130. },
  131. "required": false,
  132. "optional": true,
  133. "docs": {
  134. "tags": [{
  135. "name": "deprecated",
  136. "text": "Use either `iconStart` or `iconEnd` but do not combine them with `icon` and `iconPosition`."
  137. }],
  138. "text": "Specifies the placement of the icon."
  139. },
  140. "attribute": "icon-position",
  141. "reflect": true,
  142. "defaultValue": "\"start\""
  143. },
  144. "iconStart": {
  145. "type": "string",
  146. "mutable": false,
  147. "complexType": {
  148. "original": "string",
  149. "resolved": "string",
  150. "references": {}
  151. },
  152. "required": false,
  153. "optional": true,
  154. "docs": {
  155. "tags": [],
  156. "text": "Specifies an icon to display at the start of the component."
  157. },
  158. "attribute": "icon-start",
  159. "reflect": true
  160. },
  161. "iconEnd": {
  162. "type": "string",
  163. "mutable": false,
  164. "complexType": {
  165. "original": "string",
  166. "resolved": "string",
  167. "references": {}
  168. },
  169. "required": false,
  170. "optional": true,
  171. "docs": {
  172. "tags": [],
  173. "text": "Specifies an icon to display at the end of the component."
  174. },
  175. "attribute": "icon-end",
  176. "reflect": true
  177. },
  178. "value": {
  179. "type": "any",
  180. "mutable": true,
  181. "complexType": {
  182. "original": "any | null",
  183. "resolved": "any",
  184. "references": {}
  185. },
  186. "required": false,
  187. "optional": false,
  188. "docs": {
  189. "tags": [],
  190. "text": "The component's value."
  191. },
  192. "attribute": "value",
  193. "reflect": false
  194. }
  195. };
  196. }
  197. static get events() {
  198. return [{
  199. "method": "calciteInternalRadioGroupItemChange",
  200. "name": "calciteInternalRadioGroupItemChange",
  201. "bubbles": true,
  202. "cancelable": false,
  203. "composed": true,
  204. "docs": {
  205. "tags": [{
  206. "name": "internal",
  207. "text": undefined
  208. }],
  209. "text": "Fires when the item has been selected."
  210. },
  211. "complexType": {
  212. "original": "void",
  213. "resolved": "void",
  214. "references": {}
  215. }
  216. }];
  217. }
  218. static get elementRef() { return "el"; }
  219. static get watchers() {
  220. return [{
  221. "propName": "checked",
  222. "methodName": "handleCheckedChange"
  223. }];
  224. }
  225. }