radio-button-group.js 7.7 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.82
  5. */
  6. import { Component, Host, h, Element, Prop, Watch, Event, Listen } 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. /** The disabled state of the radio button group. */
  19. this.disabled = false;
  20. /** The radio button group's hidden status. When a radio button group is hidden none of its options are focusable or checkable. */
  21. this.hidden = false;
  22. /** The layout direction of the radio buttons in a group. */
  23. this.layout = "horizontal";
  24. /** Requires that a value is selected for the radio button group before the parent form will submit. */
  25. this.required = false;
  26. /** The scale (size) of the radio button group. */
  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" },
  93. h("slot", null)));
  94. }
  95. static get is() { return "calcite-radio-button-group"; }
  96. static get encapsulation() { return "shadow"; }
  97. static get originalStyleUrls() { return {
  98. "$": ["radio-button-group.scss"]
  99. }; }
  100. static get styleUrls() { return {
  101. "$": ["radio-button-group.css"]
  102. }; }
  103. static get properties() { return {
  104. "disabled": {
  105. "type": "boolean",
  106. "mutable": false,
  107. "complexType": {
  108. "original": "boolean",
  109. "resolved": "boolean",
  110. "references": {}
  111. },
  112. "required": false,
  113. "optional": false,
  114. "docs": {
  115. "tags": [],
  116. "text": "The disabled state of the radio button group."
  117. },
  118. "attribute": "disabled",
  119. "reflect": true,
  120. "defaultValue": "false"
  121. },
  122. "hidden": {
  123. "type": "boolean",
  124. "mutable": false,
  125. "complexType": {
  126. "original": "boolean",
  127. "resolved": "boolean",
  128. "references": {}
  129. },
  130. "required": false,
  131. "optional": false,
  132. "docs": {
  133. "tags": [],
  134. "text": "The radio button group's hidden status. When a radio button group is hidden none of its options are focusable or checkable."
  135. },
  136. "attribute": "hidden",
  137. "reflect": true,
  138. "defaultValue": "false"
  139. },
  140. "layout": {
  141. "type": "string",
  142. "mutable": false,
  143. "complexType": {
  144. "original": "Layout",
  145. "resolved": "\"grid\" | \"horizontal\" | \"vertical\"",
  146. "references": {
  147. "Layout": {
  148. "location": "import",
  149. "path": "../interfaces"
  150. }
  151. }
  152. },
  153. "required": false,
  154. "optional": false,
  155. "docs": {
  156. "tags": [],
  157. "text": "The layout direction of the radio buttons in a group."
  158. },
  159. "attribute": "layout",
  160. "reflect": true,
  161. "defaultValue": "\"horizontal\""
  162. },
  163. "name": {
  164. "type": "string",
  165. "mutable": false,
  166. "complexType": {
  167. "original": "string",
  168. "resolved": "string",
  169. "references": {}
  170. },
  171. "required": true,
  172. "optional": false,
  173. "docs": {
  174. "tags": [],
  175. "text": "The name of the radio button group. `name` must be unique to other radio button group instances."
  176. },
  177. "attribute": "name",
  178. "reflect": true
  179. },
  180. "required": {
  181. "type": "boolean",
  182. "mutable": false,
  183. "complexType": {
  184. "original": "boolean",
  185. "resolved": "boolean",
  186. "references": {}
  187. },
  188. "required": false,
  189. "optional": false,
  190. "docs": {
  191. "tags": [],
  192. "text": "Requires that a value is selected for the radio button group before the parent form will submit."
  193. },
  194. "attribute": "required",
  195. "reflect": true,
  196. "defaultValue": "false"
  197. },
  198. "scale": {
  199. "type": "string",
  200. "mutable": false,
  201. "complexType": {
  202. "original": "Scale",
  203. "resolved": "\"l\" | \"m\" | \"s\"",
  204. "references": {
  205. "Scale": {
  206. "location": "import",
  207. "path": "../interfaces"
  208. }
  209. }
  210. },
  211. "required": false,
  212. "optional": false,
  213. "docs": {
  214. "tags": [],
  215. "text": "The scale (size) of the radio button group."
  216. },
  217. "attribute": "scale",
  218. "reflect": true,
  219. "defaultValue": "\"m\""
  220. }
  221. }; }
  222. static get events() { return [{
  223. "method": "calciteRadioButtonGroupChange",
  224. "name": "calciteRadioButtonGroupChange",
  225. "bubbles": true,
  226. "cancelable": true,
  227. "composed": true,
  228. "docs": {
  229. "tags": [],
  230. "text": "Emitted when the radio button group has changed."
  231. },
  232. "complexType": {
  233. "original": "any",
  234. "resolved": "any",
  235. "references": {}
  236. }
  237. }]; }
  238. static get elementRef() { return "el"; }
  239. static get watchers() { return [{
  240. "propName": "disabled",
  241. "methodName": "onDisabledChange"
  242. }, {
  243. "propName": "hidden",
  244. "methodName": "onHiddenChange"
  245. }, {
  246. "propName": "layout",
  247. "methodName": "onLayoutChange"
  248. }, {
  249. "propName": "scale",
  250. "methodName": "onScaleChange"
  251. }]; }
  252. static get listeners() { return [{
  253. "name": "calciteRadioButtonChange",
  254. "method": "radioButtonChangeHandler",
  255. "target": undefined,
  256. "capture": false,
  257. "passive": false
  258. }]; }
  259. }