tweb-i2p/src/components/avatarEdit.ts
2021-01-02 12:59:38 +04:00

31 lines
1004 B
TypeScript

import type { CancellablePromise } from "../helpers/cancellablePromise";
import type { InputFile } from "../layer";
import PopupAvatar from "./popups/avatar";
export default class AvatarEdit {
public container: HTMLElement;
private canvas: HTMLCanvasElement;
private icon: HTMLSpanElement;
constructor(onChange: (uploadAvatar: () => CancellablePromise<InputFile>) => void) {
this.container = document.createElement('div');
this.container.classList.add('avatar-edit');
this.canvas = document.createElement('canvas');
this.canvas.classList.add('avatar-edit-canvas');
this.icon = document.createElement('span');
this.icon.classList.add('tgico', 'tgico-cameraadd');
this.container.append(this.canvas, this.icon);
this.container.addEventListener('click', () => {
new PopupAvatar().open(this.canvas, onChange);
});
}
public clear() {
const ctx = this.canvas.getContext('2d');
ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
}
}