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.

71 lines
1.9 KiB

import appStateManager from "../lib/appManagers/appStateManager";
import { getDeepProperty } from "../helpers/object";
export default class RadioField {
public input: HTMLInputElement;
public label: HTMLLabelElement;
public main: HTMLElement;
4 years ago
constructor(options: {
text?: string,
name: string,
value?: string,
stateKey?: string
}) {
const label = this.label = document.createElement('label');
label.classList.add('radio-field');
const input = this.input = document.createElement('input');
input.type = 'radio';
4 years ago
/* input.id = */input.name = 'input-radio-' + options.name;
4 years ago
if(options.value) {
input.value = options.value;
4 years ago
if(options.stateKey) {
appStateManager.getState().then(state => {
4 years ago
input.checked = getDeepProperty(state, options.stateKey) === options.value;
});
input.addEventListener('change', () => {
4 years ago
appStateManager.setByKey(options.stateKey, options.value);
});
}
}
const main = this.main = document.createElement('div');
main.classList.add('radio-field-main');
4 years ago
if(options.text) {
main.innerHTML = options.text;
/* const caption = document.createElement('div');
caption.classList.add('radio-field-main-caption');
caption.innerHTML = text;
if(subtitle) {
label.classList.add('radio-field-with-subtitle');
caption.insertAdjacentHTML('beforeend', `<div class="radio-field-main-subtitle">${subtitle}</div>`);
}
main.append(caption); */
}
label.append(input, main);
}
4 years ago
get checked() {
return this.input.checked;
}
set checked(checked: boolean) {
this.setValueSilently(checked);
const event = new Event('change', {bubbles: true, cancelable: true});
this.input.dispatchEvent(event);
}
public setValueSilently(checked: boolean) {
this.input.checked = checked;
}
};