feat: add typescript

This commit is contained in:
2025-06-12 10:39:19 -03:00
parent f6f3c77c61
commit 15fec548d5
9 changed files with 533 additions and 426 deletions
+38
View File
@@ -0,0 +1,38 @@
export const getInputById = (elementId: string): HTMLInputElement => {
const el = document.getElementById(elementId) as HTMLInputElement;
if (!el) {
throw new Error(`Input Element id ${elementId} not found!`);
}
return el;
};
export const getDivById = (elementId: string): HTMLElement => {
const el = document.getElementById(elementId) as HTMLElement;
if (!el) {
throw new Error(`HTML Element id ${elementId} not found!`);
}
return el;
}
export const getButtonById = (elementId: string): HTMLButtonElement => {
const el = document.getElementById(elementId) as HTMLButtonElement;
if (!el) {
throw new Error(`HTML Button Element id ${elementId} not found!`);
}
return el;
}
export const getButtonListByClassName = (name: string): Array<HTMLButtonElement> => {
const el = document.getElementsByClassName(name);
if (!el) {
throw new Error(`HTML Button List Elements not found for class ${name}!`);
}
return Array.from(el) as Array<HTMLButtonElement>;
}
export const showFoodPreview = (show: boolean) => {
if (!show) {
getDivById('food-preview').innerHTML = '';
}
getDivById('food-preview').classList = `add-food-form-item ${show ? 'display-block' : 'display-none'}`;
}