UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

152 lines (151 loc) 4.26 kB
/*! * All material copyright ESRI, All Rights Reserved, unless otherwise specified. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details. * v1.5.0-next.4 */ import { h, Host } from "@stencil/core"; import { setRequestedIcon } from "../../utils/dom"; import { StatusIconDefaults } from "./interfaces"; /** * @slot - A slot for adding text. */ export class InputMessage { constructor() { this.icon = undefined; this.iconFlipRtl = false; this.scale = "m"; this.status = "idle"; } handleIconEl() { this.requestedIcon = setRequestedIcon(StatusIconDefaults, this.icon, this.status); } //-------------------------------------------------------------------------- // // Lifecycle // //-------------------------------------------------------------------------- connectedCallback() { this.requestedIcon = setRequestedIcon(StatusIconDefaults, this.icon, this.status); } render() { const hidden = this.el.hidden; return (h(Host, { "calcite-hydrated-hidden": hidden }, this.renderIcon(this.requestedIcon), h("slot", null))); } //-------------------------------------------------------------------------- // // Private Methods // //-------------------------------------------------------------------------- renderIcon(iconName) { if (iconName) { return (h("calcite-icon", { class: "calcite-input-message-icon", flipRtl: this.iconFlipRtl, icon: iconName, scale: "s" })); } } static get is() { return "calcite-input-message"; } static get encapsulation() { return "shadow"; } static get originalStyleUrls() { return { "$": ["input-message.scss"] }; } static get styleUrls() { return { "$": ["input-message.css"] }; } static get properties() { return { "icon": { "type": "any", "mutable": false, "complexType": { "original": "boolean | string", "resolved": "boolean | string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Specifies an icon to display." }, "attribute": "icon", "reflect": true }, "iconFlipRtl": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "When `true`, the icon will be flipped when the element direction is right-to-left (`\"rtl\"`)." }, "attribute": "icon-flip-rtl", "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\"" }, "status": { "type": "string", "mutable": false, "complexType": { "original": "Status", "resolved": "\"idle\" | \"invalid\" | \"valid\"", "references": { "Status": { "location": "import", "path": "../interfaces" } } }, "required": false, "optional": false, "docs": { "tags": [], "text": "Specifies the status of the input field, which determines message and icons." }, "attribute": "status", "reflect": true, "defaultValue": "\"idle\"" } }; } static get elementRef() { return "el"; } static get watchers() { return [{ "propName": "status", "methodName": "handleIconEl" }, { "propName": "icon", "methodName": "handleIconEl" }]; } }