feat: organize functions and add type to foods

This commit is contained in:
2025-09-07 16:33:56 -03:00
parent 3b09e33b2d
commit f8f2c98d49
8 changed files with 224 additions and 244 deletions
+35
View File
@@ -0,0 +1,35 @@
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) => {
getDivById('food-preview').classList = `add-food-form-item ${show ? 'display-block' : 'display-none'}`;
}