radio-button-group.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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 { createObserver } from "../../utils/observers";
  8. /**
  9. * @slot - A slot for adding `calcite-radio-button`s.
  10. */
  11. export class RadioButtonGroup {
  12. constructor() {
  13. //--------------------------------------------------------------------------
  14. //
  15. // Properties
  16. //
  17. //--------------------------------------------------------------------------
  18. /** When `true`, interaction is prevented and the component is displayed with lower opacity. */
  19. this.disabled = false;
  20. /** When `true`, the component is not displayed and its `calcite-radio-button`s are not focusable or checkable. */
  21. this.hidden = false;
  22. /** Defines the layout of the component. */
  23. this.layout = "horizontal";
  24. /** When `true`, the component must have a value in order for the form to submit. */
  25. this.required = false;
  26. /** Specifies the size of the component. */
  27. this.scale = "m";
  28. // --------------------------------------------------------------------------
  29. //
  30. // Private Properties
  31. //
  32. // --------------------------------------------------------------------------
  33. this.mutationObserver = createObserver("mutation", () => this.passPropsToRadioButtons());
  34. //--------------------------------------------------------------------------
  35. //
  36. // Private Methods
  37. //
  38. //--------------------------------------------------------------------------
  39. this.passPropsToRadioButtons = () => {
  40. const radioButtons = this.el.querySelectorAll("calcite-radio-button");
  41. if (radioButtons.length > 0) {
  42. radioButtons.forEach((radioButton) => {
  43. radioButton.disabled = this.disabled || radioButton.disabled;
  44. radioButton.hidden = this.hidden;
  45. radioButton.name = this.name;
  46. radioButton.required = this.required;
  47. radioButton.scale = this.scale;
  48. });
  49. }
  50. };
  51. }
  52. onDisabledChange() {
  53. this.passPropsToRadioButtons();
  54. }
  55. onHiddenChange() {
  56. this.passPropsToRadioButtons();
  57. }
  58. onLayoutChange() {
  59. this.passPropsToRadioButtons();
  60. }
  61. onScaleChange() {
  62. this.passPropsToRadioButtons();
  63. }
  64. //--------------------------------------------------------------------------
  65. //
  66. // Lifecycle
  67. //
  68. //--------------------------------------------------------------------------
  69. connectedCallback() {
  70. var _a;
  71. this.passPropsToRadioButtons();
  72. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el, { childList: true, subtree: true });
  73. }
  74. disconnectedCallback() {
  75. var _a;
  76. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
  77. }
  78. //--------------------------------------------------------------------------
  79. //
  80. // Event Listeners
  81. //
  82. //--------------------------------------------------------------------------
  83. radioButtonChangeHandler(event) {
  84. this.calciteRadioButtonGroupChange.emit(event.target.value);
  85. }
  86. // --------------------------------------------------------------------------
  87. //
  88. // Render Methods
  89. //
  90. // --------------------------------------------------------------------------
  91. render() {
  92. return (h(Host, { role: "radiogroup" }, h("slot", null)));
  93. }
  94. static get is() { return "calcite-radio-button-group"; }
  95. static get encapsulation() { return "shadow"; }
  96. static get originalStyleUrls() {
  97. return {
  98. "$": ["radio-button-group.scss"]
  99. };
  100. }
  101. static get styleUrls() {
  102. return {
  103. "$": ["radio-button-group.css"]
  104. };
  105. }
  106. static get properties() {
  107. return {
  108. "disabled": {
  109. "type": "boolean",
  110. "mutable": false,
  111. "complexType": {
  112. "original": "boolean",
  113. "resolved": "boolean",
  114. "references": {}
  115. },
  116. "required": false,
  117. "optional": false,
  118. "docs": {
  119. "tags": [],
  120. "text": "When `true`, interaction is prevented and the component is displayed with lower opacity."
  121. },
  122. "attribute": "disabled",
  123. "reflect": true,
  124. "defaultValue": "false"
  125. },
  126. "hidden": {
  127. "type": "boolean",
  128. "mutable": false,
  129. "complexType": {
  130. "original": "boolean",
  131. "resolved": "boolean",
  132. "references": {}
  133. },
  134. "required": false,
  135. "optional": false,
  136. "docs": {
  137. "tags": [],
  138. "text": "When `true`, the component is not displayed and its `calcite-radio-button`s are not focusable or checkable."
  139. },
  140. "attribute": "hidden",
  141. "reflect": true,
  142. "defaultValue": "false"
  143. },
  144. "layout": {
  145. "type": "string",
  146. "mutable": false,
  147. "complexType": {
  148. "original": "Layout",
  149. "resolved": "\"grid\" | \"horizontal\" | \"vertical\"",
  150. "references": {
  151. "Layout": {
  152. "location": "import",
  153. "path": "../interfaces"
  154. }
  155. }
  156. },
  157. "required": false,
  158. "optional": false,
  159. "docs": {
  160. "tags": [],
  161. "text": "Defines the layout of the component."
  162. },
  163. "attribute": "layout",
  164. "reflect": true,
  165. "defaultValue": "\"horizontal\""
  166. },
  167. "name": {
  168. "type": "string",
  169. "mutable": false,
  170. "complexType": {
  171. "original": "string",
  172. "resolved": "string",
  173. "references": {}
  174. },
  175. "required": true,
  176. "optional": false,
  177. "docs": {
  178. "tags": [],
  179. "text": "Specifies the name of the component on form submission. Must be unique to other component instances."
  180. },
  181. "attribute": "name",
  182. "reflect": true
  183. },
  184. "required": {
  185. "type": "boolean",
  186. "mutable": false,
  187. "complexType": {
  188. "original": "boolean",
  189. "resolved": "boolean",
  190. "references": {}
  191. },
  192. "required": false,
  193. "optional": false,
  194. "docs": {
  195. "tags": [],
  196. "text": "When `true`, the component must have a value in order for the form to submit."
  197. },
  198. "attribute": "required",
  199. "reflect": true,
  200. "defaultValue": "false"
  201. },
  202. "scale": {
  203. "type": "string",
  204. "mutable": false,
  205. "complexType": {
  206. "original": "Scale",
  207. "resolved": "\"l\" | \"m\" | \"s\"",
  208. "references": {
  209. "Scale": {
  210. "location": "import",
  211. "path": "../interfaces"
  212. }
  213. }
  214. },
  215. "required": false,
  216. "optional": false,
  217. "docs": {
  218. "tags": [],
  219. "text": "Specifies the size of the component."
  220. },
  221. "attribute": "scale",
  222. "reflect": true,
  223. "defaultValue": "\"m\""
  224. }
  225. };
  226. }
  227. static get events() {
  228. return [{
  229. "method": "calciteRadioButtonGroupChange",
  230. "name": "calciteRadioButtonGroupChange",
  231. "bubbles": true,
  232. "cancelable": false,
  233. "composed": true,
  234. "docs": {
  235. "tags": [],
  236. "text": "Fires when the component has changed."
  237. },
  238. "complexType": {
  239. "original": "any",
  240. "resolved": "any",
  241. "references": {}
  242. }
  243. }];
  244. }
  245. static get elementRef() { return "el"; }
  246. static get watchers() {
  247. return [{
  248. "propName": "disabled",
  249. "methodName": "onDisabledChange"
  250. }, {
  251. "propName": "hidden",
  252. "methodName": "onHiddenChange"
  253. }, {
  254. "propName": "layout",
  255. "methodName": "onLayoutChange"
  256. }, {
  257. "propName": "scale",
  258. "methodName": "onScaleChange"
  259. }];
  260. }
  261. static get listeners() {
  262. return [{
  263. "name": "calciteRadioButtonChange",
  264. "method": "radioButtonChangeHandler",
  265. "target": undefined,
  266. "capture": false,
  267. "passive": false
  268. }];
  269. }
  270. }