Browse Source

fixed SVG icons in tab headers - fixes #5926

Eugene Pankov 3 years ago
parent
commit
90becada86

+ 9 - 0
tabby-core/src/components/profileIcon.component.pug

@@ -0,0 +1,9 @@
+i.icon(
+    class='fa-fw {{icon}}',
+    [style.color]='color',
+    *ngIf='!isHTML'
+)
+.icon(
+    [fastHtmlBind]='icon',
+    *ngIf='isHTML'
+)

+ 10 - 0
tabby-core/src/components/profileIcon.component.scss

@@ -0,0 +1,10 @@
+:host {
+    display: flex;
+    align-items: center;
+    max-width: 1.25rem;
+}
+
+::ng-deep img {
+    max-width: 100%;
+    max-height: 100%;
+}

+ 18 - 0
tabby-core/src/components/profileIcon.component.ts

@@ -0,0 +1,18 @@
+/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
+import { Component, Input } from '@angular/core'
+import { BaseComponent } from './base.component'
+
+/** @hidden */
+@Component({
+    selector: 'profile-icon',
+    template: require('./profileIcon.component.pug'),
+    styles: [require('./profileIcon.component.scss')],
+})
+export class ProfileIconComponent extends BaseComponent {
+    @Input() icon?: string
+    @Input() color?: string
+
+    get isHTML (): boolean {
+        return this.icon?.startsWith('<') ?? false
+    }
+}

+ 3 - 9
tabby-core/src/components/selectorModal.component.pug

@@ -17,15 +17,9 @@
                 (click)='selectOption(option)',
                 (click)='selectOption(option)',
                 [class.active]='selectedIndex == i'
                 [class.active]='selectedIndex == i'
             )
             )
-                i.icon(
-                    class='fa-fw {{option.icon}}',
-                    style='color: {{option.color}}',
-                    *ngIf='!iconIsSVG(option.icon)'
-                )
-                .icon(
-                    [fastHtmlBind]='option.icon',
-                    style='color: {{option.color}}',
-                    *ngIf='iconIsSVG(option.icon)'
+                profile-icon(
+                    [icon]='option.icon',
+                    [color]='option.color'
                 )
                 )
                 .title.mr-2 {{getOptionText(option)}}
                 .title.mr-2 {{getOptionText(option)}}
                 .description.no-wrap.text-muted {{option.description}}
                 .description.no-wrap.text-muted {{option.description}}

+ 0 - 4
tabby-core/src/components/selectorModal.component.ts

@@ -84,8 +84,4 @@ export class SelectorModalComponent<T> {
     close (): void {
     close (): void {
         this.modalInstance.dismiss()
         this.modalInstance.dismiss()
     }
     }
-
-    iconIsSVG (icon?: string): boolean {
-        return icon?.startsWith('<') ?? false
-    }
 }
 }

+ 3 - 3
tabby-core/src/components/tabHeader.component.pug

@@ -5,10 +5,10 @@
 .index(*ngIf='!config.store.terminal.hideTabIndex && hostApp.platform === Platform.macOS', cdkDragHandle) {{index + 1}}
 .index(*ngIf='!config.store.terminal.hideTabIndex && hostApp.platform === Platform.macOS', cdkDragHandle) {{index + 1}}
 .index(*ngIf='!config.store.terminal.hideTabIndex && hostApp.platform !== Platform.macOS') {{index + 1}}
 .index(*ngIf='!config.store.terminal.hideTabIndex && hostApp.platform !== Platform.macOS') {{index + 1}}
 
 
-.icon(
+profile-icon(
     *ngIf='config.store.terminal.showTabProfileIcon && tab.icon',
     *ngIf='config.store.terminal.showTabProfileIcon && tab.icon',
-    [ngClass]='tab.icon',
-    [style.color]='tab.color'
+    [icon]='tab.icon',
+    [color]='tab.color'
 )
 )
 
 
 .name(
 .name(

+ 2 - 3
tabby-core/src/components/tabHeader.component.scss

@@ -26,8 +26,7 @@ $tabs-height: 38px;
       height: $tabs-height;
       height: $tabs-height;
     }
     }
 
 
-    .index,
-    .icon {
+    .index {
         flex: none;
         flex: none;
         font-weight: bold;
         font-weight: bold;
         -webkit-app-region: no-drag;
         -webkit-app-region: no-drag;
@@ -41,7 +40,7 @@ $tabs-height: 38px;
         margin-top: 1px;
         margin-top: 1px;
     }
     }
 
 
-    .icon {
+    profile-icon {
         font-size: 13px;
         font-size: 13px;
         margin: 1px 4px 0 0;
         margin: 1px 4px 0 0;
     }
     }

+ 3 - 0
tabby-core/src/index.ts

@@ -29,6 +29,7 @@ import { SplitTabPaneLabelComponent } from './components/splitTabPaneLabel.compo
 import { UnlockVaultModalComponent } from './components/unlockVaultModal.component'
 import { UnlockVaultModalComponent } from './components/unlockVaultModal.component'
 import { WelcomeTabComponent } from './components/welcomeTab.component'
 import { WelcomeTabComponent } from './components/welcomeTab.component'
 import { TransfersMenuComponent } from './components/transfersMenu.component'
 import { TransfersMenuComponent } from './components/transfersMenu.component'
+import { ProfileIconComponent } from './components/profileIcon.component'
 
 
 import { AutofocusDirective } from './directives/autofocus.directive'
 import { AutofocusDirective } from './directives/autofocus.directive'
 import { AlwaysVisibleTypeaheadDirective } from './directives/alwaysVisibleTypeahead.directive'
 import { AlwaysVisibleTypeaheadDirective } from './directives/alwaysVisibleTypeahead.directive'
@@ -128,6 +129,7 @@ const PROVIDERS = [
         TransfersMenuComponent,
         TransfersMenuComponent,
         DropZoneDirective,
         DropZoneDirective,
         CdkAutoDropGroup,
         CdkAutoDropGroup,
+        ProfileIconComponent,
     ],
     ],
     entryComponents: [
     entryComponents: [
         PromptModalComponent,
         PromptModalComponent,
@@ -150,6 +152,7 @@ const PROVIDERS = [
         DragDropModule,
         DragDropModule,
         TranslateModule,
         TranslateModule,
         CdkAutoDropGroup,
         CdkAutoDropGroup,
+        ProfileIconComponent,
     ],
     ],
 })
 })
 export default class AppModule { // eslint-disable-line @typescript-eslint/no-extraneous-class
 export default class AppModule { // eslint-disable-line @typescript-eslint/no-extraneous-class

+ 4 - 1
tabby-settings/src/components/editProfileModal.component.pug

@@ -40,7 +40,10 @@
                     )
                     )
                     .input-group-append
                     .input-group-append
                         .input-group-text
                         .input-group-text
-                            i([class]='"fa-fw " + profile.icon')
+                            profile-icon(
+                                [icon]='profile.icon',
+                                [color]='profile.color'
+                            )
 
 
                 ng-template(#rt,let-r='result',let-t='term')
                 ng-template(#rt,let-r='result',let-t='term')
                     i([class]='"fa-fw " + r')
                     i([class]='"fa-fw " + r')

+ 3 - 8
tabby-settings/src/components/profilesSettingsTab.component.pug

@@ -58,14 +58,9 @@ ul.nav-tabs(ngbNav, #nav='ngbNav')
                                     [class.list-group-item-action]='!profile.isBuiltin',
                                     [class.list-group-item-action]='!profile.isBuiltin',
                                     (click)='profile.isBuiltin ? null : editProfile(profile)'
                                     (click)='profile.isBuiltin ? null : editProfile(profile)'
                                 )
                                 )
-                                    i.icon(
-                                        class='fa-fw {{profile.icon}}',
-                                        [style.color]='profile.color',
-                                        *ngIf='!iconIsSVG(profile.icon)'
-                                    )
-                                    .icon(
-                                        [fastHtmlBind]='profile.icon',
-                                        *ngIf='iconIsSVG(profile.icon)'
+                                    profile-icon(
+                                        [icon]='profile.icon',
+                                        [color]='profile.color'
                                     )
                                     )
 
 
                                     .no-wrap {{profile.name}}
                                     .no-wrap {{profile.name}}

+ 2 - 2
tabby-settings/src/components/profilesSettingsTab.component.scss

@@ -1,8 +1,8 @@
-.icon {
+profile-icon {
     width: 1.25rem;
     width: 1.25rem;
     margin-right: 0.25rem;
     margin-right: 0.25rem;
 }
 }
 
 
-.icon + * {
+profile-icon + * {
     margin-left: 10px;
     margin-left: 10px;
 }
 }

+ 0 - 4
tabby-settings/src/components/profilesSettingsTab.component.ts

@@ -225,10 +225,6 @@ export class ProfilesSettingsTabComponent extends BaseComponent {
         return !this.filter || (profile.name + '$' + (this.getDescription(profile) ?? '')).toLowerCase().includes(this.filter.toLowerCase())
         return !this.filter || (profile.name + '$' + (this.getDescription(profile) ?? '')).toLowerCase().includes(this.filter.toLowerCase())
     }
     }
 
 
-    iconIsSVG (icon?: string): boolean {
-        return icon?.startsWith('<') ?? false
-    }
-
     getDescription (profile: PartialProfile<Profile>): string|null {
     getDescription (profile: PartialProfile<Profile>): string|null {
         return this.profilesService.getDescription(profile)
         return this.profilesService.getDescription(profile)
     }
     }