import { html, nothing, TemplateResult, unsafeCSS } from "lit"; import { query } from "lit/decorators.js"; import globalStyle from "./f-input-light-global.scss?inline"; import { classMap } from "lit-html/directives/class-map.js"; import { FIcon } from "../f-icon/f-icon"; import { unsafeSVG } from "lit-html/directives/unsafe-svg.js"; import loader from "../../mixins/svg/loader"; import { ifDefined } from "lit-html/directives/if-defined.js"; import { flowElement } from "./../../utils"; import { injectCss } from "@cldcvr/flow-core-config"; import { FInputBase } from "./f-input-base"; injectCss("f-input-light", globalStyle); @flowElement("f-input-light") export class FInputLight extends FInputBase { /** * css loaded from scss file */ static styles = [unsafeCSS(globalStyle)]; /** * native input element reference */ @query("input") inputElement!: HTMLInputElement; /** * native input element wrapper reference, (Used in f-suggest to display popover) */ @query(".f-input-wrapper") inputWrapperElement!: HTMLInputElement; /** * clear icon reference */ @query(".clear-icon") clearIcon?: FIcon; createRenderRoot() { return this; } get iconRightTemplate() { if (this.iconRight) { return html``; } return nothing; } get passwordToggle() { if (this.type === "password" || this.showPassword) { return html` `; } return nothing; } get suffixTextTemplate() { if (this.suffix && (this.suffixWhen ? this.suffixWhen(this.value) : true)) { return html` ${this.suffix} `; } return nothing; } get suffixTemplate() { let computedSuffix: TemplateResult<1> | symbol = nothing; /** * check if suffix available */ if (this.suffix || this.iconRight) { computedSuffix = html` ${this.suffixTextTemplate} ${this.iconRightTemplate} `; } let clearIcon: TemplateResult<1> | symbol = nothing; let loadingIcon: TemplateResult<1> | symbol = nothing; /** * cheak if clear icon needs to be display */ if ( this.value !== undefined && this.value !== null && this.value !== "" && this.clear && !this.loading ) { clearIcon = html``; } if (this.loading) { loadingIcon = html`
${unsafeSVG(loader)}
`; } return html`
${this.passwordToggle}${clearIcon}${computedSuffix}
${loadingIcon}`; } get iconleftTemplate() { if (this.iconLeft) { return html` `; } return nothing; } get prefixTemplate() { let textPrefixTemplate: TemplateResult<1> | symbol = nothing; if (this.prefix) { textPrefixTemplate = html` ${this.prefix} `; } if (this.prefix || this.iconLeft) { return html`
${textPrefixTemplate} ${this.iconleftTemplate}
`; } return nothing; } render() { /** * Final html to render */ return html`
${this.prefixTemplate} ${this.suffixTemplate}
`; } } /** * Required for typescript */ declare global { interface HTMLElementTagNameMap { "f-input-light": FInputLight; } }