/** * EDC Search Bar Component * * Reusable search input with debounced search functionality. * * @customElement edc-search-bar */ import { css, html, LitElement } from 'lit'; import { customElement, property, state } from 'lit/decorators.js'; @customElement('edc-search-bar') export class EdcSearchBar extends LitElement { @property({ type: String }) placeholder: string = 'Search...'; @property({ type: String }) value: string = ''; @property({ type: Number }) debounce: number = 300; // milliseconds @state() private localValue: string = ''; private debounceTimer?: number; connectedCallback() { super.connectedCallback(); this.localValue = this.value; } updated(changedProperties: Map) { if (changedProperties.has('value') && this.value !== this.localValue) { this.localValue = this.value; } } private handleInput(e: Event) { const input = e.target as HTMLInputElement; this.localValue = input.value; // Clear existing timer if (this.debounceTimer) { clearTimeout(this.debounceTimer); } // Set new timer this.debounceTimer = window.setTimeout(() => { this.dispatchEvent(new CustomEvent('search', { detail: { value: this.localValue }, bubbles: true, composed: true })); }, this.debounce); } private handleClear() { this.localValue = ''; this.dispatchEvent(new CustomEvent('search', { detail: { value: '' }, bubbles: true, composed: true })); } render() { return html` `; } static styles = css` :host { display: block; } .search-bar { position: relative; display: flex; align-items: center; gap: 0.5rem; padding: 0.75rem; border: 1px solid #ddd; border-radius: 6px; background: white; transition: border-color 0.2s; } .search-bar:focus-within { border-color: var(--tems-color-primary, #e91e63); outline: none; box-shadow: 0 0 0 3px rgba(233, 30, 99, 0.1); } .search-icon { font-size: 1rem; opacity: 0.5; } .search-input { flex: 1; border: none; outline: none; font-size: 1rem; font-family: inherit; background: transparent; } .search-input::placeholder { color: #999; } .search-clear { background: transparent; border: none; font-size: 1rem; cursor: pointer; padding: 0.25rem; opacity: 0.5; transition: opacity 0.2s; } .search-clear:hover { opacity: 1; } `; } declare global { interface HTMLElementTagNameMap { 'edc-search-bar': EdcSearchBar; } }