/** * Copyright Aquera Inc 2023 * * This source code is licensed under the BSD-3-Clause license found in the * LICENSE file in the root directory of this source tree. */ import { LitElement, html, CSSResultArray, TemplateResult, } from 'lit'; import { customElement, property } from 'lit/decorators.js'; import { styles } from './nile-input.css'; import '../nile-icon'; import { classMap } from 'lit/directives/class-map.js'; import { query, state } from 'lit/decorators.js'; import { defaultValue } from '../internal/default-value'; import { FormControlController } from '../internal/form'; import { HasSlotController } from '../internal/slot'; import { ifDefined } from 'lit/directives/if-defined.js'; import { live } from 'lit/directives/live.js'; import { watch } from '../internal/watch'; import type { CSSResultGroup } from 'lit'; import NileElement, { NileFormControl } from '../internal/nile-element'; import { unsafeHTML } from 'lit/directives/unsafe-html.js'; /** * Nile icon component. * * @tag nile-input * */ @customElement('nile-input') export class NileInput extends NileElement implements NileFormControl { static styles: CSSResultGroup = styles; private readonly formControlController = new FormControlController(this, { assumeInteractionOn: ['nile-blur', 'nile-input'], }); private readonly hasSlotController = new HasSlotController( this, 'help-text', 'label' ); @query('.input__control') input: HTMLInputElement; @state() private hasFocus = false; @property() title = ''; // make reactive to pass through /** * The type of input. Works the same as a native `` element, but only a subset of types are supported. Defaults * to `text`. */ @property({ reflect: true }) type: | 'date' | 'datetime-local' | 'email' | 'number' | 'password' | 'search' | 'tel' | 'text' | 'time' | 'url' = 'text'; /** The name of the input, submitted as a name/value pair with form data. */ @property() name = ''; /** The current value of the input, submitted as a name/value pair with form data. */ @property() value = ''; @property({ type: Boolean }) checkNonPrintableChar: boolean = false; /** The default value of the form control. Primarily used for resetting the form control. */ @defaultValue() defaultValue = ''; /** The input's size. */ @property({ reflect: true }) size: 'small' | 'medium' | 'large' = 'medium'; /** Draws a filled input. */ @property({ type: Boolean, reflect: true }) filled = false; /** Sets the input to a warning state, changing its visual appearance. */ @property({ type: Boolean }) warning = false; /** Sets the input to an error state, changing its visual appearance. */ @property({ type: Boolean }) error = false; /** Sets the input to a success state, changing its visual appearance. */ @property({ type: Boolean }) success = false; /** Sets the input to a Destructive state, changing its visual appearance. */ @property({ type: Boolean }) destructive = false; /** Draws a pill-style input with rounded edges. */ @property({ type: Boolean, reflect: true }) pill = false; /** The input's label. If you need to display HTML, use the `label` slot instead. */ @property() label = ''; @property({ attribute: 'help-text', reflect: true }) helpText = ''; @property({ attribute: 'error-message', reflect: true }) errorMessage = ''; /** Adds a clear button when the input is not empty. */ @property({ type: Boolean }) clearable = false; /** Disables the input. */ @property({ type: Boolean, reflect: true }) disabled = false; /** Placeholder text to show as a hint when the input is empty. */ @property() placeholder = ''; /** Makes the input readonly. */ @property({ type: Boolean, reflect: true }) readonly = false; /** Adds a button to toggle the password's visibility. Only applies to password types. */ @property({ attribute: 'password-toggle', type: Boolean }) passwordToggle = false; /** Determines whether or not the password is currently visible. Only applies to password input types. */ @property({ attribute: 'password-visible', type: Boolean }) passwordVisible = false; /** Hides the browser's built-in increment/decrement spin buttons for number inputs. */ @property({ attribute: 'no-spin-buttons', type: Boolean }) noSpinButtons = false; /** * By default, form controls are associated with the nearest containing `