Lib: Add image preview helper

This commit is contained in:
2024-12-12 04:38:00 +01:00
parent 4089b58df1
commit 36cd9fbe8a

17
src/lib/image.ts Normal file
View File

@ -0,0 +1,17 @@
export const get_image_preview_event_handler = (id: string) => {
const handler = (event) => {
const target = event.target;
const files = target.files;
if (files.length > 0) {
const src = URL.createObjectURL(files[0]);
const preview = document.getElementById(id) as HTMLImageElement;
if (preview) {
preview.src = src;
preview.hidden = false;
}
}
};
return handler;
};