MCPcopy
hub / github.com/wavetermdev/waveterm / makeIconClass

Function makeIconClass

frontend/util/util.ts:122–171  ·  view source on GitHub ↗
(icon: string, fw: boolean, opts?: { spin?: boolean; defaultIcon?: string })

Source from the content-addressed store, hash-verified

120}
121
122function 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

Callers 15

renderIconFunction · 0.90
renderItemFunction · 0.90
treeview.tsxFile · 0.90
aimode.tsxFile · 0.90
FakeBlockFunction · 0.90
FakeTermBlockFunction · 0.90
widgets.tsxFile · 0.90
iconbutton.tsxFile · 0.90
EmojiButtonFunction · 0.90
SuggestionIconFunction · 0.90
LauncherViewFunction · 0.90

Calls 1

isBlankFunction · 0.70

Tested by

no test coverage detected