123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- /*!
- * 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.82
- */
- import { Component, Host, h, Element, Prop, Watch, Event, Listen } from "@stencil/core";
- import { createObserver } from "../../utils/observers";
- /**
- * @slot - A slot for adding `calcite-radio-button`s.
- */
- export class RadioButtonGroup {
- constructor() {
- //--------------------------------------------------------------------------
- //
- // Properties
- //
- //--------------------------------------------------------------------------
- /** The disabled state of the radio button group. */
- this.disabled = false;
- /** The radio button group's hidden status. When a radio button group is hidden none of its options are focusable or checkable. */
- this.hidden = false;
- /** The layout direction of the radio buttons in a group. */
- this.layout = "horizontal";
- /** Requires that a value is selected for the radio button group before the parent form will submit. */
- this.required = false;
- /** The scale (size) of the radio button group. */
- 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": "The disabled state of the radio button group."
- },
- "attribute": "disabled",
- "reflect": true,
- "defaultValue": "false"
- },
- "hidden": {
- "type": "boolean",
- "mutable": false,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "The radio button group's hidden status. When a radio button group is hidden none of its options are 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": "The layout direction of the radio buttons in a group."
- },
- "attribute": "layout",
- "reflect": true,
- "defaultValue": "\"horizontal\""
- },
- "name": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "string",
- "resolved": "string",
- "references": {}
- },
- "required": true,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "The name of the radio button group. `name` must be unique to other radio button group instances."
- },
- "attribute": "name",
- "reflect": true
- },
- "required": {
- "type": "boolean",
- "mutable": false,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "Requires that a value is selected for the radio button group before the parent form will 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": "The scale (size) of the radio button group."
- },
- "attribute": "scale",
- "reflect": true,
- "defaultValue": "\"m\""
- }
- }; }
- static get events() { return [{
- "method": "calciteRadioButtonGroupChange",
- "name": "calciteRadioButtonGroupChange",
- "bubbles": true,
- "cancelable": true,
- "composed": true,
- "docs": {
- "tags": [],
- "text": "Emitted when the radio button group 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
- }]; }
- }
|