(icon: string, fw: boolean, opts?: { spin?: boolean; defaultIcon?: string })
| 120 | } |
| 121 | |
| 122 | function makeIconClass(icon: string, fw: boolean, opts?: { spin?: boolean; defaultIcon?: string }): string { |
| 123 | if (isBlank(icon)) { |
| 124 | if (opts?.defaultIcon != null) { |
| 125 | return makeIconClass(opts.defaultIcon, fw, { spin: opts?.spin }); |
| 126 | } |
| 127 | return null; |
| 128 | } |
| 129 | |
| 130 | let animation: string | null = null; |
| 131 | let hasFwModifier = false; |
| 132 | |
| 133 | while (icon.match(/\+(spin|beat|fade|fw)$/)) { |
| 134 | const modifierMatch = icon.match(/\+(spin|beat|fade|fw)$/); |
| 135 | if (modifierMatch) { |
| 136 | const modifier = modifierMatch[1]; |
| 137 | if (modifier === "fw") { |
| 138 | hasFwModifier = true; |
| 139 | } else { |
| 140 | animation = modifier; |
| 141 | } |
| 142 | icon = icon.replace(/\+(spin|beat|fade|fw)$/, ""); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | let baseClass: string; |
| 147 | if (icon.match(/^(solid@)?[a-z0-9-]+$/)) { |
| 148 | icon = icon.replace(/^solid@/, ""); |
| 149 | baseClass = `fa fa-solid fa-${icon}`; |
| 150 | } else if (icon.match(/^regular@[a-z0-9-]+$/)) { |
| 151 | icon = icon.replace(/^regular@/, ""); |
| 152 | baseClass = `fa fa-sharp fa-regular fa-${icon}`; |
| 153 | } else if (icon.match(/^brands@[a-z0-9-]+$/)) { |
| 154 | icon = icon.replace(/^brands@/, ""); |
| 155 | baseClass = `fa fa-brands fa-${icon}`; |
| 156 | } else if (icon.match(/^custom@[a-z0-9-]+$/)) { |
| 157 | icon = icon.replace(/^custom@/, ""); |
| 158 | baseClass = `fa fa-kit fa-${icon}`; |
| 159 | } else { |
| 160 | if (opts?.defaultIcon != null) { |
| 161 | return makeIconClass(opts.defaultIcon, fw, { spin: opts?.spin }); |
| 162 | } |
| 163 | return null; |
| 164 | } |
| 165 | |
| 166 | const shouldAddFw = fw || hasFwModifier; |
| 167 | const hasSpin = animation === "spin" || opts?.spin; |
| 168 | const animationClass = animation && animation !== "spin" ? `fa-${animation}` : null; |
| 169 | |
| 170 | return clsx(baseClass, shouldAddFw ? "fa-fw" : null, hasSpin ? "fa-spin" : null, animationClass); |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * A wrapper function for running a promise and catching any errors |
no test coverage detected