import * as colors from './00colors.js'; import { DeesInputBase } from './dees-input-base.js'; import { demoFunc } from './dees-input-text.demo.js'; import { customElement, type TemplateResult, property, html, cssManager, css, } from '@design.estate/dees-element'; declare global { interface HTMLElementTagNameMap { 'dees-input-text': DeesInputText; } } @customElement('dees-input-text') export class DeesInputText extends DeesInputBase { public static demo = demoFunc; // INSTANCE @property({ type: String, reflect: true, }) public value: string = ''; @property({ type: Boolean, reflect: true, }) public isPasswordBool = false; @property({ type: Boolean, reflect: true, }) public showPasswordBool = false; @property({ type: Boolean, reflect: true, }) public validationState: 'valid' | 'warn' | 'invalid'; @property({ reflect: true, }) public validationText: string = ''; @property({}) validationFunction: (value: string) => boolean; public static styles = [ ...DeesInputBase.baseStyles, cssManager.defaultStyles, css` * { box-sizing: border-box; } :host { position: relative; z-index: auto; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif; } .maincontainer { position: relative; color: ${cssManager.bdTheme('hsl(0 0% 15%)', 'hsl(0 0% 90%)')}; } input { display: flex; height: 40px; width: 100%; padding: 0 12px; font-size: 14px; line-height: 40px; background: transparent; border: 1px solid ${cssManager.bdTheme('hsl(0 0% 89.8%)', 'hsl(0 0% 14.9%)')}; border-radius: 6px; transition: all 0.15s ease; outline: none; cursor: text; font-family: inherit; color: ${cssManager.bdTheme('hsl(0 0% 9%)', 'hsl(0 0% 95%)')}; } input::placeholder { color: ${cssManager.bdTheme('hsl(0 0% 63.9%)', 'hsl(0 0% 45.1%)')}; } input:hover:not(:disabled):not(:focus) { border-color: ${cssManager.bdTheme('hsl(0 0% 79.8%)', 'hsl(0 0% 20.9%)')}; } input:focus { outline: none; border-color: ${cssManager.bdTheme('hsl(222.2 47.4% 51.2%)', 'hsl(217.2 91.2% 59.8%)')}; box-shadow: 0 0 0 3px ${cssManager.bdTheme('hsl(222.2 47.4% 51.2% / 0.1)', 'hsl(217.2 91.2% 59.8% / 0.1)')}; } input:disabled { background: ${cssManager.bdTheme('hsl(0 0% 95.1%)', 'hsl(0 0% 14.9%)')}; border-color: ${cssManager.bdTheme('hsl(0 0% 89.8%)', 'hsl(0 0% 14.9%)')}; color: ${cssManager.bdTheme('hsl(0 0% 63.9%)', 'hsl(0 0% 45.1%)')}; cursor: not-allowed; opacity: 0.5; } /* Password toggle button */ .showPassword { position: absolute; right: 1px; top: 50%; transform: translateY(-50%); display: flex; align-items: center; justify-content: center; width: 38px; height: 38px; cursor: pointer; color: ${cssManager.bdTheme('hsl(0 0% 45.1%)', 'hsl(0 0% 63.9%)')}; transition: all 0.15s ease; border-radius: 0 5px 5px 0; } .showPassword:hover { background: ${cssManager.bdTheme('hsl(0 0% 95.1%)', 'hsl(0 0% 14.9%)')}; color: ${cssManager.bdTheme('hsl(0 0% 15%)', 'hsl(0 0% 93.9%)')}; } /* Validation styles */ .validationContainer { margin-top: 4px; padding: 4px 8px; font-size: 12px; font-weight: 500; border-radius: 4px; transition: all 0.2s ease; overflow: hidden; } .validationContainer.error { background: ${cssManager.bdTheme('hsl(0 84.2% 60.2% / 0.1)', 'hsl(0 72.2% 50.6% / 0.1)')}; color: ${cssManager.bdTheme('hsl(0 84.2% 60.2%)', 'hsl(0 72.2% 50.6%)')}; } .validationContainer.warn { background: ${cssManager.bdTheme('hsl(25 95% 53% / 0.1)', 'hsl(25 95% 63% / 0.1)')}; color: ${cssManager.bdTheme('hsl(25 95% 53%)', 'hsl(25 95% 63%)')}; } .validationContainer.valid { background: ${cssManager.bdTheme('hsl(142.1 76.2% 36.3% / 0.1)', 'hsl(142.1 70.6% 45.3% / 0.1)')}; color: ${cssManager.bdTheme('hsl(142.1 76.2% 36.3%)', 'hsl(142.1 70.6% 45.3%)')}; } /* Error state for input */ :host([validation-state="invalid"]) input { border-color: ${cssManager.bdTheme('hsl(0 84.2% 60.2%)', 'hsl(0 72.2% 50.6%)')}; } :host([validation-state="invalid"]) input:focus { box-shadow: 0 0 0 3px ${cssManager.bdTheme('hsl(0 84.2% 60.2% / 0.1)', 'hsl(0 72.2% 50.6% / 0.1)')}; } /* Warning state for input */ :host([validation-state="warn"]) input { border-color: ${cssManager.bdTheme('hsl(25 95% 53%)', 'hsl(25 95% 63%)')}; } :host([validation-state="warn"]) input:focus { box-shadow: 0 0 0 3px ${cssManager.bdTheme('hsl(25 95% 53% / 0.1)', 'hsl(25 95% 63% / 0.1)')}; } /* Valid state for input */ :host([validation-state="valid"]) input { border-color: ${cssManager.bdTheme('hsl(142.1 76.2% 36.3%)', 'hsl(142.1 70.6% 45.3%)')}; } :host([validation-state="valid"]) input:focus { box-shadow: 0 0 0 3px ${cssManager.bdTheme('hsl(142.1 76.2% 36.3% / 0.1)', 'hsl(142.1 70.6% 45.3% / 0.1)')}; } `, ]; public render(): TemplateResult { return html`
${this.isPasswordBool ? html`
` : html``} ${this.validationText ? html`
${this.validationText}
` : html`
`}
`; } firstUpdated() { // Input event handling is already done in updateValue method } public async updateValue(eventArg: Event) { const target: any = eventArg.target; this.value = target.value; this.changeSubject.next(this); } public getValue(): string { return this.value; } public setValue(value: string): void { this.value = value; } public async togglePasswordView() { this.showPasswordBool = !this.showPasswordBool; } public async focus() { const textInput = this.shadowRoot.querySelector('input'); textInput.focus(); } public async blur() { const textInput = this.shadowRoot.querySelector('input'); textInput.blur(); } }