123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- /*!
- * 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 { h } from "@stencil/core";
- import { createObserver } from "../../utils/observers";
- export class Option {
- constructor() {
- //--------------------------------------------------------------------------
- //
- // Properties
- //
- //--------------------------------------------------------------------------
- /**
- * When `true`, interaction is prevented and the component is displayed with lower opacity.
- */
- this.disabled = false;
- this.mutationObserver = createObserver("mutation", () => {
- this.ensureTextContentDependentProps();
- this.calciteInternalOptionChange.emit();
- });
- }
- handlePropChange(_newValue, _oldValue, propName) {
- if (propName === "label" || propName === "value") {
- this.ensureTextContentDependentProps();
- }
- this.calciteInternalOptionChange.emit();
- }
- //--------------------------------------------------------------------------
- //
- // Private Methods
- //
- //--------------------------------------------------------------------------
- ensureTextContentDependentProps() {
- const { el: { textContent } } = this;
- if (!this.label || this.label === this.internallySetLabel) {
- this.label = textContent;
- this.internallySetLabel = textContent;
- }
- if (!this.value || this.value === this.internallySetValue) {
- this.value = textContent;
- this.internallySetValue = textContent;
- }
- }
- //--------------------------------------------------------------------------
- //
- // Lifecycle
- //
- //--------------------------------------------------------------------------
- connectedCallback() {
- var _a;
- this.ensureTextContentDependentProps();
- (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el, {
- attributeFilter: ["label", "value"],
- characterData: true,
- childList: true,
- subtree: true
- });
- }
- disconnectedCallback() {
- var _a;
- (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
- }
- //--------------------------------------------------------------------------
- //
- // Render Methods
- //
- //--------------------------------------------------------------------------
- render() {
- return h("slot", null, this.label);
- }
- static get is() { return "calcite-option"; }
- static get encapsulation() { return "shadow"; }
- static get originalStyleUrls() {
- return {
- "$": ["option.scss"]
- };
- }
- static get styleUrls() {
- return {
- "$": ["option.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"
- },
- "label": {
- "type": "string",
- "mutable": true,
- "complexType": {
- "original": "string",
- "resolved": "string",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "Accessible name for the component."
- },
- "attribute": "label",
- "reflect": false
- },
- "selected": {
- "type": "boolean",
- "mutable": false,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "When `true`, the component is selected."
- },
- "attribute": "selected",
- "reflect": true
- },
- "value": {
- "type": "any",
- "mutable": true,
- "complexType": {
- "original": "any",
- "resolved": "any",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "The component's value."
- },
- "attribute": "value",
- "reflect": false
- }
- };
- }
- static get events() {
- return [{
- "method": "calciteInternalOptionChange",
- "name": "calciteInternalOptionChange",
- "bubbles": true,
- "cancelable": false,
- "composed": true,
- "docs": {
- "tags": [{
- "name": "internal",
- "text": undefined
- }],
- "text": ""
- },
- "complexType": {
- "original": "void",
- "resolved": "void",
- "references": {}
- }
- }];
- }
- static get elementRef() { return "el"; }
- static get watchers() {
- return [{
- "propName": "disabled",
- "methodName": "handlePropChange"
- }, {
- "propName": "label",
- "methodName": "handlePropChange"
- }, {
- "propName": "selected",
- "methodName": "handlePropChange"
- }, {
- "propName": "value",
- "methodName": "handlePropChange"
- }];
- }
- }
|