| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 | 
							- /*!
 
-  * 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, Element, Event, h, Host, Method, Prop, Watch } from "@stencil/core";
 
- import { focusElement, toAriaBoolean } from "../../utils/dom";
 
- import { connectLabel, disconnectLabel, getLabelText } from "../../utils/label";
 
- import { connectForm, disconnectForm, HiddenFormInputSlot } from "../../utils/form";
 
- import { updateHostInteraction } from "../../utils/interactive";
 
- export class Switch {
 
-   constructor() {
 
-     //--------------------------------------------------------------------------
 
-     //
 
-     //  Properties
 
-     //
 
-     //--------------------------------------------------------------------------
 
-     /** True if the switch is disabled */
 
-     this.disabled = false;
 
-     /** The scale of the switch */
 
-     this.scale = "m";
 
-     /** True if the switch is initially on
 
-      * @deprecated use 'checked' instead.
 
-      */
 
-     this.switched = false;
 
-     /** True if the switch is initially on */
 
-     this.checked = false;
 
-     //--------------------------------------------------------------------------
 
-     //
 
-     //  Private Methods
 
-     //
 
-     //--------------------------------------------------------------------------
 
-     this.keyDownHandler = (e) => {
 
-       const key = e.key;
 
-       if (!this.disabled && (key === " " || key === "Enter")) {
 
-         this.toggle();
 
-         e.preventDefault();
 
-       }
 
-     };
 
-     this.clickHandler = () => {
 
-       this.toggle();
 
-     };
 
-     this.setSwitchEl = (el) => {
 
-       this.switchEl = el;
 
-     };
 
-   }
 
-   switchedWatcher(switched) {
 
-     this.checked = switched;
 
-   }
 
-   //--------------------------------------------------------------------------
 
-   //
 
-   //  Public Methods
 
-   //
 
-   //--------------------------------------------------------------------------
 
-   /** Sets focus on the component. */
 
-   async setFocus() {
 
-     focusElement(this.switchEl);
 
-   }
 
-   onLabelClick() {
 
-     if (!this.disabled) {
 
-       this.toggle();
 
-       this.setFocus();
 
-     }
 
-   }
 
-   toggle() {
 
-     this.checked = !this.checked;
 
-     this.calciteSwitchChange.emit({
 
-       // todo: We should remove emmitting redudant props in event payload.
 
-       // https://github.com/Esri/calcite-components/issues/3163
 
-       switched: this.checked
 
-     });
 
-   }
 
-   //--------------------------------------------------------------------------
 
-   //
 
-   //  Lifecycle
 
-   //
 
-   //--------------------------------------------------------------------------
 
-   connectedCallback() {
 
-     const initiallyChecked = this.checked || this.switched;
 
-     if (initiallyChecked) {
 
-       // if either prop is set, we ensure both are synced initially
 
-       this.switched = this.checked = initiallyChecked;
 
-     }
 
-     connectLabel(this);
 
-     connectForm(this);
 
-   }
 
-   disconnectedCallback() {
 
-     disconnectLabel(this);
 
-     disconnectForm(this);
 
-   }
 
-   componentDidRender() {
 
-     updateHostInteraction(this);
 
-   }
 
-   // --------------------------------------------------------------------------
 
-   //
 
-   //  Render Methods
 
-   //
 
-   // --------------------------------------------------------------------------
 
-   render() {
 
-     return (h(Host, { onClick: this.clickHandler, onKeyDown: this.keyDownHandler },
 
-       h("div", { "aria-checked": toAriaBoolean(this.checked), "aria-label": getLabelText(this), class: "container", ref: this.setSwitchEl, role: "switch", tabIndex: 0 },
 
-         h("div", { class: "track" },
 
-           h("div", { class: "handle" })),
 
-         h(HiddenFormInputSlot, { component: this }))));
 
-   }
 
-   static get is() { return "calcite-switch"; }
 
-   static get encapsulation() { return "shadow"; }
 
-   static get originalStyleUrls() { return {
 
-     "$": ["switch.scss"]
 
-   }; }
 
-   static get styleUrls() { return {
 
-     "$": ["switch.css"]
 
-   }; }
 
-   static get properties() { return {
 
-     "disabled": {
 
-       "type": "boolean",
 
-       "mutable": false,
 
-       "complexType": {
 
-         "original": "boolean",
 
-         "resolved": "boolean",
 
-         "references": {}
 
-       },
 
-       "required": false,
 
-       "optional": false,
 
-       "docs": {
 
-         "tags": [],
 
-         "text": "True if the switch is disabled"
 
-       },
 
-       "attribute": "disabled",
 
-       "reflect": true,
 
-       "defaultValue": "false"
 
-     },
 
-     "label": {
 
-       "type": "string",
 
-       "mutable": false,
 
-       "complexType": {
 
-         "original": "string",
 
-         "resolved": "string",
 
-         "references": {}
 
-       },
 
-       "required": false,
 
-       "optional": true,
 
-       "docs": {
 
-         "tags": [],
 
-         "text": "Applies to the aria-label attribute on the switch"
 
-       },
 
-       "attribute": "label",
 
-       "reflect": false
 
-     },
 
-     "name": {
 
-       "type": "string",
 
-       "mutable": false,
 
-       "complexType": {
 
-         "original": "string",
 
-         "resolved": "string",
 
-         "references": {}
 
-       },
 
-       "required": false,
 
-       "optional": false,
 
-       "docs": {
 
-         "tags": [],
 
-         "text": "The name of the switch input"
 
-       },
 
-       "attribute": "name",
 
-       "reflect": true
 
-     },
 
-     "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 of the switch"
 
-       },
 
-       "attribute": "scale",
 
-       "reflect": true,
 
-       "defaultValue": "\"m\""
 
-     },
 
-     "switched": {
 
-       "type": "boolean",
 
-       "mutable": true,
 
-       "complexType": {
 
-         "original": "boolean",
 
-         "resolved": "boolean",
 
-         "references": {}
 
-       },
 
-       "required": false,
 
-       "optional": false,
 
-       "docs": {
 
-         "tags": [{
 
-             "name": "deprecated",
 
-             "text": "use 'checked' instead."
 
-           }],
 
-         "text": "True if the switch is initially on"
 
-       },
 
-       "attribute": "switched",
 
-       "reflect": false,
 
-       "defaultValue": "false"
 
-     },
 
-     "checked": {
 
-       "type": "boolean",
 
-       "mutable": true,
 
-       "complexType": {
 
-         "original": "boolean",
 
-         "resolved": "boolean",
 
-         "references": {}
 
-       },
 
-       "required": false,
 
-       "optional": false,
 
-       "docs": {
 
-         "tags": [],
 
-         "text": "True if the switch is initially on"
 
-       },
 
-       "attribute": "checked",
 
-       "reflect": true,
 
-       "defaultValue": "false"
 
-     },
 
-     "value": {
 
-       "type": "any",
 
-       "mutable": false,
 
-       "complexType": {
 
-         "original": "any",
 
-         "resolved": "any",
 
-         "references": {}
 
-       },
 
-       "required": false,
 
-       "optional": false,
 
-       "docs": {
 
-         "tags": [],
 
-         "text": "The value of the switch input"
 
-       },
 
-       "attribute": "value",
 
-       "reflect": false
 
-     }
 
-   }; }
 
-   static get events() { return [{
 
-       "method": "calciteSwitchChange",
 
-       "name": "calciteSwitchChange",
 
-       "bubbles": true,
 
-       "cancelable": true,
 
-       "composed": true,
 
-       "docs": {
 
-         "tags": [],
 
-         "text": "Fires when the checked value has changed."
 
-       },
 
-       "complexType": {
 
-         "original": "any",
 
-         "resolved": "any",
 
-         "references": {}
 
-       }
 
-     }]; }
 
-   static get methods() { return {
 
-     "setFocus": {
 
-       "complexType": {
 
-         "signature": "() => Promise<void>",
 
-         "parameters": [],
 
-         "references": {
 
-           "Promise": {
 
-             "location": "global"
 
-           }
 
-         },
 
-         "return": "Promise<void>"
 
-       },
 
-       "docs": {
 
-         "text": "Sets focus on the component.",
 
-         "tags": []
 
-       }
 
-     }
 
-   }; }
 
-   static get elementRef() { return "el"; }
 
-   static get watchers() { return [{
 
-       "propName": "switched",
 
-       "methodName": "switchedWatcher"
 
-     }]; }
 
- }
 
 
  |