Telegram Web K with changes to work inside I2P
https://web.telegram.i2p/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.1 KiB
81 lines
2.1 KiB
4 years ago
|
//import { getRichValue } from "../helpers/dom";
|
||
|
import InputField from "./inputField";
|
||
|
|
||
|
export default class InputSearch {
|
||
4 years ago
|
public container: HTMLElement;
|
||
|
public input: HTMLInputElement;
|
||
|
public clearBtn: HTMLElement;
|
||
|
|
||
|
public prevValue = '';
|
||
|
public timeout = 0;
|
||
|
public onChange: (value: string) => void;
|
||
|
|
||
|
constructor(placeholder: string, onChange?: (value: string) => void) {
|
||
4 years ago
|
const inputField = InputField({
|
||
|
placeholder,
|
||
|
plainText: true
|
||
|
});
|
||
|
|
||
|
this.container = inputField.container;
|
||
|
this.container.classList.remove('input-field');
|
||
4 years ago
|
this.container.classList.add('input-search');
|
||
|
|
||
|
this.onChange = onChange;
|
||
|
|
||
4 years ago
|
this.input = inputField.input;
|
||
|
this.input.classList.add('input-search-input');
|
||
4 years ago
|
|
||
|
const searchIcon = document.createElement('span');
|
||
|
searchIcon.classList.add('tgico', 'tgico-search');
|
||
|
|
||
|
this.clearBtn = document.createElement('span');
|
||
|
this.clearBtn.classList.add('tgico', 'btn-icon', 'tgico-close');
|
||
|
|
||
|
this.input.addEventListener('input', this.onInput);
|
||
|
this.clearBtn.addEventListener('click', this.onClearClick);
|
||
|
|
||
|
this.container.append(this.input, searchIcon, this.clearBtn);
|
||
|
}
|
||
|
|
||
|
onInput = () => {
|
||
|
if(!this.onChange) return;
|
||
|
|
||
4 years ago
|
let value = this.value;
|
||
4 years ago
|
|
||
|
//this.input.classList.toggle('is-empty', !value.trim());
|
||
|
|
||
|
if(value != this.prevValue) {
|
||
|
this.prevValue = value;
|
||
|
clearTimeout(this.timeout);
|
||
4 years ago
|
this.timeout = window.setTimeout(() => {
|
||
4 years ago
|
this.onChange(value);
|
||
|
}, 200);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
onClearClick = () => {
|
||
|
this.value = '';
|
||
|
this.onChange && this.onChange('');
|
||
|
};
|
||
|
|
||
|
get value() {
|
||
|
return this.input.value;
|
||
4 years ago
|
//return getRichValue(this.input);
|
||
4 years ago
|
}
|
||
|
|
||
|
set value(value: string) {
|
||
4 years ago
|
//this.input.innerHTML = value;
|
||
4 years ago
|
this.input.value = value;
|
||
|
this.prevValue = value;
|
||
|
clearTimeout(this.timeout);
|
||
4 years ago
|
|
||
|
const event = new Event('input', {bubbles: true, cancelable: true});
|
||
|
this.input.dispatchEvent(event);
|
||
4 years ago
|
}
|
||
|
|
||
|
public remove() {
|
||
|
clearTimeout(this.timeout);
|
||
|
this.input.removeEventListener('input', this.onInput);
|
||
|
this.clearBtn.removeEventListener('click', this.onClearClick);
|
||
|
}
|
||
|
}
|