diff --git a/src/api/Styles.ts b/src/api/Styles.ts index 6b189cab..6b0ac2cd 100644 --- a/src/api/Styles.ts +++ b/src/api/Styles.ts @@ -141,7 +141,7 @@ export const compileStyle = (style: Style) => { */ export const classNameToSelector = (name: string, prefix = "") => name.split(" ").map(n => `.${prefix}${n}`).join(""); -type ClassNameFactoryArg = string | string[] | Record; +type ClassNameFactoryArg = string | string[] | Record | false | null | undefined | 0 | ""; /** * @param prefix The prefix to add to each class, defaults to `""` * @returns A classname generator function @@ -154,9 +154,9 @@ type ClassNameFactoryArg = string | string[] | Record; export const classNameFactory = (prefix: string = "") => (...args: ClassNameFactoryArg[]) => { const classNames = new Set(); for (const arg of args) { - if (typeof arg === "string") classNames.add(arg); + if (arg && typeof arg === "string") classNames.add(arg); else if (Array.isArray(arg)) arg.forEach(name => classNames.add(name)); - else if (typeof arg === "object") Object.entries(arg).forEach(([name, value]) => value && classNames.add(name)); + else if (arg && typeof arg === "object") Object.entries(arg).forEach(([name, value]) => value && classNames.add(name)); } return Array.from(classNames, name => prefix + name).join(" "); };