]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Refactor button components
authorChocobozzz <me@florianbigard.com>
Fri, 10 Jun 2022 08:46:20 +0000 (10:46 +0200)
committerChocobozzz <me@florianbigard.com>
Fri, 10 Jun 2022 11:51:12 +0000 (13:51 +0200)
client/src/app/shared/shared-main/buttons/button.component.html
client/src/app/shared/shared-main/buttons/button.component.scss
client/src/app/shared/shared-main/buttons/button.component.ts
client/src/app/shared/shared-main/buttons/delete-button.component.html [deleted file]
client/src/app/shared/shared-main/buttons/delete-button.component.ts
client/src/app/shared/shared-main/buttons/edit-button.component.html [deleted file]
client/src/app/shared/shared-main/buttons/edit-button.component.ts

index d1a4215e6e481b1533202f7461a1ca983e104a23..c0a4b21b8d93c47a6e06ec70783b5fce4ad28335 100644 (file)
@@ -1,8 +1,16 @@
-<span class="action-button" [ngClass]="getClasses()" [ngbTooltip]="title" tabindex="0">
+<span *ngIf="!routerLink" class="action-button" [ngClass]="getClasses()" [ngbTooltip]="title" tabindex="0">
+  <ng-container *ngTemplateOutlet="content"></ng-container>
+</span>
+
+<a *ngIf="routerLink" class="action-button" [ngClass]="getClasses()" [ngbTooltip]="title" [routerLink]="routerLink">
+  <ng-container *ngTemplateOutlet="content"></ng-container>
+</a>
+
+<ng-template #content>
   <my-small-loader [loading]="loading"></my-small-loader>
   <my-global-icon *ngIf="icon && !loading" [iconName]="icon"></my-global-icon>
 
   <span *ngIf="label" class="button-label">{{ label }}</span>
 
   <ng-content></ng-content>
-</span>
+</ng-template>
index c53b8f2e50a463dcae30e88c8e796738c68a8436..776f6622e6beb63abdf5b2aefa16cab9543f37d2 100644 (file)
@@ -9,6 +9,10 @@
   .button-label {
     display: none;
   }
+
+  my-global-icon {
+    margin: 0 !important;
+  }
 }
 
 :host {
@@ -30,35 +34,34 @@ span[class$=-button] {
 }
 
 .action-button {
-  @include peertube-button-link;
-  @include button-with-icon(21px);
-
   width: 100%; // useful for ellipsis, allow to define a max-width on host component
 
-  &.icon-only {
-    my-global-icon {
-      margin: 0;
-    }
+  &.has-icon {
+    @include button-with-icon(21px);
+  }
+
+  &.icon-only my-global-icon {
+    margin: 0 !important;
   }
 }
 
-.orange-button {
+.orange-button,
+.grey-button {
   @include peertube-button;
-  @include orange-button;
 }
 
-.orange-button-link {
+.orange-button-link,
+.grey-button-link {
   @include peertube-button-link;
-  @include orange-button;
 }
 
-.grey-button {
-  @include peertube-button;
-  @include grey-button;
+.orange-button,
+.orange-button-link {
+  @include orange-button;
 }
 
+.grey-button,
 .grey-button-link {
-  @include peertube-button-link;
   @include grey-button;
 }
 
index 52936a4d47076b4873ea5087efe037e4d70c49b6..47605782350966624b23227f7ff3d0685cd57ffd 100644 (file)
@@ -11,6 +11,7 @@ export class ButtonComponent {
   @Input() label = ''
   @Input() className = 'grey-button'
   @Input() icon: GlobalIconName = undefined
+  @Input() routerLink: string[] | string
   @Input() title: string = undefined
   @Input() loading = false
   @Input() disabled = false
@@ -21,6 +22,7 @@ export class ButtonComponent {
       [this.className]: true,
       disabled: this.disabled,
       'icon-only': !this.label,
+      'has-icon': !!this.icon,
       'responsive-label': this.responsiveLabel
     }
   }
diff --git a/client/src/app/shared/shared-main/buttons/delete-button.component.html b/client/src/app/shared/shared-main/buttons/delete-button.component.html
deleted file mode 100644 (file)
index d7a6702..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<span
-  class="action-button action-button-delete grey-button"
-  [ngClass]="{ 'responsive-label': responsiveLabel }" [ngbTooltip]="title" role="button" tabindex="0"
->
-  <my-global-icon iconName="delete" aria-hidden="true"></my-global-icon>
-
-  <span class="button-label" *ngIf="label">{{ label }}</span>
-</span>
index 90735852c31c52981ac3ca6284f237848b507dde..1cab10803437e0ff8a5875520af4218fb546850d 100644 (file)
@@ -2,17 +2,16 @@ import { Component, Input, OnInit } from '@angular/core'
 
 @Component({
   selector: 'my-delete-button',
-  styleUrls: [ './button.component.scss' ],
-  templateUrl: './delete-button.component.html'
+  template: `
+  <my-button icon="delete" className="grey-button" [label]="label" [title]="title" [responsiveLabel]="responsiveLabel"></my-button>
+  `
 })
-
 export class DeleteButtonComponent implements OnInit {
   @Input() label: string
   @Input() title: string
   @Input() responsiveLabel = false
 
   ngOnInit () {
-    // <my-delete-button /> No label
     if (this.label === undefined && !this.title) {
       this.title = $localize`Delete`
     }
diff --git a/client/src/app/shared/shared-main/buttons/edit-button.component.html b/client/src/app/shared/shared-main/buttons/edit-button.component.html
deleted file mode 100644 (file)
index 8beeee6..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<a
-  class="action-button action-button-edit grey-button"
-  [ngClass]="{ 'responsive-label': responsiveLabel }" [routerLink]="routerLink" [ngbTooltip]="title"
->
-  <my-global-icon iconName="edit" aria-hidden="true"></my-global-icon>
-
-  <span class="button-label" *ngIf="label">{{ label }}</span>
-</a>
index 24c8625ffa30d68cd1aa63d693f430fd78de335f..0049dfa640230de23ab612bc807823e87a8aa4ce 100644 (file)
@@ -2,8 +2,13 @@ import { Component, Input, OnInit } from '@angular/core'
 
 @Component({
   selector: 'my-edit-button',
-  styleUrls: [ './button.component.scss' ],
-  templateUrl: './edit-button.component.html'
+  template: `
+    <my-button
+      icon="edit" className="grey-button-link"
+      [label]="label" [title]="title" [responsiveLabel]="responsiveLabel"
+      [routerLink]="routerLink"
+    ></my-button>
+  `
 })
 export class EditButtonComponent implements OnInit {
   @Input() label: string