import { html, unsafeCSS } from "lit"; import { query, queryAssignedElements, state } from "lit/decorators.js"; import globalStyle from "./f-input-global.scss?inline"; import { FText } from "../f-text/f-text"; import { FDiv } from "../f-div/f-div"; import { FIcon } from "../f-icon/f-icon"; import { ifDefined } from "lit-html/directives/if-defined.js"; import { flowElement } from "./../../utils"; import { injectCss } from "@cldcvr/flow-core-config"; import { FInputBase, FInputCustomEvent } from "./f-input-base"; import { FInputLight } from "./f-input-light"; injectCss("f-input", globalStyle); export type { FInputState, FInputCustomEvent, FInputSuffixWhen } from "./f-input-base"; @flowElement("f-input") export class FInput extends FInputBase { /** * css loaded from scss file */ static styles = [ unsafeCSS(globalStyle), ...FText.styles, ...FDiv.styles, ...FIcon.styles, ...FInputLight.styles ]; @queryAssignedElements({ slot: "label" }) _labelNodes!: NodeListOf; @state() _hasLabel = false; @queryAssignedElements({ slot: "help" }) _helpNodes!: NodeListOf; @state() _hasHelperText = false; /** * input element reference */ @query("f-input-light") inputLight!: FInputLight; get inputElement() { return this.inputLight.inputElement; } get inputWrapperElement() { return this.inputLight.inputWrapperElement; } get clearIcon() { return this.inputLight.clearIcon; } _onLabelSlotChange() { this._hasLabel = this._labelNodes.length > 0; } _onHelpSlotChange() { this._hasHelperText = this._helpNodes.length > 0; } updateValue(e: CustomEvent) { if (e.detail) { this.value = e.detail.value; } } render() { /** * Final html to render */ return html` ${this.maxLength ? html` ${(this.value + "")?.length ?? 0} / ${this.maxLength}` : null} ) => this.updateValue(e)} > `; } } /** * Required for typescript */ declare global { interface HTMLElementTagNameMap { "f-input": FInput; } }