diff --git a/src/utils/functions/cssProp.ts b/src/utils/functions/cssProp.ts index 5f169e3..12b8ae3 100644 --- a/src/utils/functions/cssProp.ts +++ b/src/utils/functions/cssProp.ts @@ -1,16 +1,27 @@ type CssVar = `--${string}`; -export function setCssProp(target: HTMLElement, name: CssVar, value: string) { +export function setCssProp(target: HTMLElement | null, name: CssVar, value: string) { + if (!target) { + return; + } target.style.setProperty(name, value); } -export function setCssProps(target: HTMLElement, vars: { [k in CssVar]: string }) { +export function setCssProps(target: HTMLElement | null, vars: { [k in CssVar]: string }) { + if (!target) { + return; + } + Object.entries(vars).forEach(([name, value]) => { setCssProp(target, name as CssVar, value); }); } -export function removeCssProps(target: HTMLElement, names: CssVar[]) { +export function removeCssProps(target: HTMLElement | null, names: CssVar[]) { + if (!target) { + return; + } + names.forEach((name) => { target.style.removeProperty(name); });