diff options
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/Styles.ts | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/api/Styles.ts b/src/api/Styles.ts index 6b189ca..6b0ac2c 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<string, unknown>; +type ClassNameFactoryArg = string | string[] | Record<string, unknown> | 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<string, unknown>; export const classNameFactory = (prefix: string = "") => (...args: ClassNameFactoryArg[]) => { const classNames = new Set<string>(); 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(" "); }; |