123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- /*!
- * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
- * v1.0.0-beta.97
- */
- import { Host, h } from "@stencil/core";
- import { createObserver } from "../../utils/observers";
- /**
- * @slot - A slot for adding `calcite-radio-button`s.
- */
- export class RadioButtonGroup {
- constructor() {
- //--------------------------------------------------------------------------
- //
- // Properties
- //
- //--------------------------------------------------------------------------
- /** When `true`, interaction is prevented and the component is displayed with lower opacity. */
- this.disabled = false;
- /** When `true`, the component is not displayed and its `calcite-radio-button`s are not focusable or checkable. */
- this.hidden = false;
- /** Defines the layout of the component. */
- this.layout = "horizontal";
- /** When `true`, the component must have a value in order for the form to submit. */
- this.required = false;
- /** Specifies the size of the component. */
- this.scale = "m";
- // --------------------------------------------------------------------------
- //
- // Private Properties
- //
- // --------------------------------------------------------------------------
- this.mutationObserver = createObserver("mutation", () => this.passPropsToRadioButtons());
- //--------------------------------------------------------------------------
- //
- // Private Methods
- //
- //--------------------------------------------------------------------------
- this.passPropsToRadioButtons = () => {
- const radioButtons = this.el.querySelectorAll("calcite-radio-button");
- if (radioButtons.length > 0) {
- radioButtons.forEach((radioButton) => {
- radioButton.disabled = this.disabled || radioButton.disabled;
- radioButton.hidden = this.hidden;
- radioButton.name = this.name;
- radioButton.required = this.required;
- radioButton.scale = this.scale;
- });
- }
- };
- }
- onDisabledChange() {
- this.passPropsToRadioButtons();
- }
- onHiddenChange() {
- this.passPropsToRadioButtons();
- }
- onLayoutChange() {
- this.passPropsToRadioButtons();
- }
- onScaleChange() {
- this.passPropsToRadioButtons();
- }
- //--------------------------------------------------------------------------
- //
- // Lifecycle
- //
- //--------------------------------------------------------------------------
- connectedCallback() {
- var _a;
- this.passPropsToRadioButtons();
- (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el, { childList: true, subtree: true });
- }
- disconnectedCallback() {
- var _a;
- (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
- }
- //--------------------------------------------------------------------------
- //
- // Event Listeners
- //
- //--------------------------------------------------------------------------
- radioButtonChangeHandler(event) {
- this.calciteRadioButtonGroupChange.emit(event.target.value);
- }
- // --------------------------------------------------------------------------
- //
- // Render Methods
- //
- // --------------------------------------------------------------------------
- render() {
- return (h(Host, { role: "radiogroup" }, h("slot", null)));
- }
- static get is() { return "calcite-radio-button-group"; }
- static get encapsulation() { return "shadow"; }
- static get originalStyleUrls() {
- return {
- "$": ["radio-button-group.scss"]
- };
- }
- static get styleUrls() {
- return {
- "$": ["radio-button-group.css"]
- };
- }
- static get properties() {
- return {
- "disabled": {
- "type": "boolean",
- "mutable": false,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "When `true`, interaction is prevented and the component is displayed with lower opacity."
- },
- "attribute": "disabled",
- "reflect": true,
- "defaultValue": "false"
- },
- "hidden": {
- "type": "boolean",
- "mutable": false,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "When `true`, the component is not displayed and its `calcite-radio-button`s are not focusable or checkable."
- },
- "attribute": "hidden",
- "reflect": true,
- "defaultValue": "false"
- },
- "layout": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "Layout",
- "resolved": "\"grid\" | \"horizontal\" | \"vertical\"",
- "references": {
- "Layout": {
- "location": "import",
- "path": "../interfaces"
- }
- }
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "Defines the layout of the component."
- },
- "attribute": "layout",
- "reflect": true,
- "defaultValue": "\"horizontal\""
- },
- "name": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "string",
- "resolved": "string",
- "references": {}
- },
- "required": true,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "Specifies the name of the component on form submission. Must be unique to other component instances."
- },
- "attribute": "name",
- "reflect": true
- },
- "required": {
- "type": "boolean",
- "mutable": false,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "When `true`, the component must have a value in order for the form to submit."
- },
- "attribute": "required",
- "reflect": true,
- "defaultValue": "false"
- },
- "scale": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "Scale",
- "resolved": "\"l\" | \"m\" | \"s\"",
- "references": {
- "Scale": {
- "location": "import",
- "path": "../interfaces"
- }
- }
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "Specifies the size of the component."
- },
- "attribute": "scale",
- "reflect": true,
- "defaultValue": "\"m\""
- }
- };
- }
- static get events() {
- return [{
- "method": "calciteRadioButtonGroupChange",
- "name": "calciteRadioButtonGroupChange",
- "bubbles": true,
- "cancelable": false,
- "composed": true,
- "docs": {
- "tags": [],
- "text": "Fires when the component has changed."
- },
- "complexType": {
- "original": "any",
- "resolved": "any",
- "references": {}
- }
- }];
- }
- static get elementRef() { return "el"; }
- static get watchers() {
- return [{
- "propName": "disabled",
- "methodName": "onDisabledChange"
- }, {
- "propName": "hidden",
- "methodName": "onHiddenChange"
- }, {
- "propName": "layout",
- "methodName": "onLayoutChange"
- }, {
- "propName": "scale",
- "methodName": "onScaleChange"
- }];
- }
- static get listeners() {
- return [{
- "name": "calciteRadioButtonChange",
- "method": "radioButtonChangeHandler",
- "target": undefined,
- "capture": false,
- "passive": false
- }];
- }
- }
|