Browse Source

iconClass => iconName conversion shim mostly removed; one special case

- the shim has been removed from the normal code path and incorporated into UNSTABLE_getReact
- still need the shim in two instances in the launcher pkg
telamonian 5 years ago
parent
commit
617c2bd6a1
3 changed files with 19 additions and 10 deletions
  1. 1 0
      .cleanignore
  2. 1 0
      .gitignore
  3. 17 10
      packages/ui-components/src/icon/labicon.tsx

+ 1 - 0
.cleanignore

@@ -20,4 +20,5 @@
 @.idea/
 
 # ms IDE stuff
+@*.code-workspace
 @.vscode

+ 1 - 0
.gitignore

@@ -57,4 +57,5 @@ junit.xml
 .idea/
 
 # ms IDE stuff
+*.code-workspace
 .vscode

+ 17 - 10
packages/ui-components/src/icon/labicon.tsx

@@ -32,11 +32,8 @@ export class LabIcon implements LabIcon.ILabIcon, LabIcon.IRenderer {
    * @returns A LabIcon instance
    */
   private static _get(name: string, fallback?: LabIcon): LabIcon | undefined {
-    // TODO: remove name-might-actually-be-className shim here
-    for (let className of name.split(/\s+/)) {
-      if (LabIcon._instances.has(className)) {
-        return LabIcon._instances.get(className);
-      }
+    if (LabIcon._instances.has(name)) {
+      return LabIcon._instances.get(name);
     }
 
     // lookup failed
@@ -62,14 +59,24 @@ export class LabIcon implements LabIcon.ILabIcon, LabIcon.IRenderer {
     fallback,
     ...props
   }: { name: string; fallback?: LabIcon } & LabIcon.IReactProps) {
-    const icon = LabIcon._get(name, fallback);
-    if (!icon) {
-      props.className = classes(name, props.className);
+    for (let className of name.split(/\s+/)) {
+      if (LabIcon._instances.has(className)) {
+        const icon = LabIcon._instances.get(className)!;
+        return <icon.react {...props} />;
+      }
+    }
+
+    // lookup failed if execution reached here
+    if (LabIcon._debug) {
+      // fail noisily
+      console.error(`Invalid icon name: ${name}`);
+      return <badIcon.react {...props} />;
+    } else if (fallback) {
+      return <fallback.react {...props} />;
+    } else {
       // try to render the icon as a css background image via iconClass
       return <Private.iconAsCssBackgroundReact {...props} />;
     }
-
-    return <icon.react {...props} />;
   }
 
   /**