Skip to content

Commit d35e1b5

Browse files
authored
Merge pull request ceph#64329 from afreen23/cd-icon
mgr/dashboard: Add generic component for icons Reviewed-by: Nizamudeen A <[email protected]>
2 parents 10b709d + 1dd42e1 commit d35e1b5

File tree

13 files changed

+168
-84
lines changed

13 files changed

+168
-84
lines changed

src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-snapshotschedule-list/cephfs-snapshotschedule-list.component.html

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,14 @@
3838
</ng-template>
3939

4040
<ng-template #fullpathForSelectionTpl>
41-
<span
42-
data-toggle="tooltip"
43-
[title]="row.pathForSelection"
44-
class="font-monospace"
45-
>{{ row.pathForSelection?.split?.("@")?.[0] }}
46-
<cd-copy-2-clipboard-button
47-
*ngIf="row.pathForSelection"
48-
[source]="row.pathForSelection?.split?.('@')?.[0]"
49-
[byId]="false"
50-
[showIconOnly]="true"
51-
>
52-
</cd-copy-2-clipboard-button>
53-
</span>
41+
<cd-copy-2-clipboard-button
42+
*ngIf="row.pathForSelection"
43+
[source]="row.pathForSelection?.split?.('@')?.[0]"
44+
[byId]="false"
45+
[size]="lg"
46+
[text]="row.pathForSelection?.split?.('@')?.[0]"
47+
>
48+
</cd-copy-2-clipboard-button>
5449
</ng-template>
5550
</ng-template>
5651

src/pybind/mgr/dashboard/frontend/src/app/shared/components/card-row/card-row.component.html

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,18 @@
5252
<span *ngIf="data.categoryPgAmount?.clean">
5353
{{ data.categoryPgAmount?.clean }}
5454
</span>
55-
<i class="text-success"
56-
[ngClass]="[icons.success]">
57-
</i>
55+
<cd-icon
56+
type="success">
57+
</cd-icon >
5858
</span>
5959
<span *ngIf="data.info"
6060
class="ms-2">
6161
<span *ngIf="data.info">
6262
{{ data.info }}
6363
</span>
64-
<i class="text-info"
65-
[ngClass]="[icons.danger]">
66-
</i>
64+
<cd-icon
65+
type="infoCircle">
66+
</cd-icon >
6767
</span>
6868
<span *ngIf="data.warn || data.categoryPgAmount?.warning"
6969
class="ms-2">
@@ -73,9 +73,9 @@
7373
<span *ngIf="data.categoryPgAmount?.warning">
7474
{{ data.categoryPgAmount?.warning }}
7575
</span>
76-
<i class="text-warning"
77-
[ngClass]="[icons.warning]">
78-
</i>
76+
<cd-icon
77+
type="warning">
78+
</cd-icon >
7979
</span>
8080
<span *ngIf="data.error || data.categoryPgAmount?.unknown"
8181
class="ms-2">
@@ -85,9 +85,9 @@
8585
<span *ngIf="data.categoryPgAmount?.unknown">
8686
{{ data.categoryPgAmount?.unknown }}
8787
</span>
88-
<i class="text-danger"
89-
[ngClass]="[icons.danger]">
90-
</i>
88+
<cd-icon
89+
type="danger">
90+
</cd-icon >
9191
</span>
9292
<span *ngIf="data.categoryPgAmount?.working"
9393
class="ms-2">
@@ -103,9 +103,9 @@
103103
<ng-template #osdSummary>
104104
<span *ngIf="data.up === data.in">
105105
{{ data.up }}
106-
<i class="text-success"
107-
[ngClass]="[icons.success]">
108-
</i>
106+
<cd-icon
107+
type="success">
108+
</cd-icon >
109109
</span>
110110
<span *ngIf="data.up !== data.in">
111111
{{ data.up }}
@@ -151,36 +151,36 @@
151151
<ng-template #iscsiSummary>
152152
<span>
153153
{{ data.up }}
154-
<i class="text-success"
154+
<cd-icon
155155
*ngIf="data.up || data.up === 0"
156-
[ngClass]="[icons.success]">
157-
</i>
156+
type="success">
157+
</cd-icon >
158158
</span>
159159
<span *ngIf="data.down"
160160
class="ms-2">
161161
{{ data.down }}
162-
<i class="text-danger"
163-
[ngClass]="[icons.danger]">
164-
</i>
162+
<cd-icon
163+
type="danger">
164+
</cd-icon >
165165
</span>
166166
</ng-template>
167167

168168
<ng-template #simplifiedSummary>
169169
<span *ngIf="!dropdownTotalError else showErrorNum">
170170
{{ data }}
171-
<i class="text-success"
172-
[ngClass]="[icons.success]"></i>
171+
<cd-icon
172+
type="success"></cd-icon >
173173
</span>
174174
<ng-template #showErrorNum>
175175
<span *ngIf="data - dropdownTotalError > 0">
176176
{{ data - dropdownTotalError }}
177-
<i class="text-success"
178-
[ngClass]="[icons.success]"></i>
177+
<cd-icon
178+
type="success"></cd-icon >
179179
</span>
180180
<span>
181181
{{ dropdownTotalError }}
182-
<i class="text-danger"
183-
[ngClass]="[icons.danger]"></i>
182+
<cd-icon
183+
type="danger"></cd-icon >
184184
</span>
185185
</ng-template>
186186
</ng-template>
@@ -211,17 +211,17 @@
211211
</div>
212212
<span [ngClass]="data.value.error ? 'me-2' : 'me-4'">
213213
{{ data.value.ok }}
214-
<i class="text-success"
214+
<cd-icon
215215
*ngIf="data.value.ok"
216-
[ngClass]="[icons.success]">
217-
</i>
216+
type="success">
217+
</cd-icon >
218218
</span>
219219
<span *ngIf="data.value.error"
220220
class="me-4 ms-2">
221221
{{ data.value.error }}
222-
<i class="text-danger"
223-
[ngClass]="[icons.danger]">
224-
</i>
222+
<cd-icon
223+
type="danger">
224+
</cd-icon >
225225
</span>
226226
</div>
227227
</li>

src/pybind/mgr/dashboard/frontend/src/app/shared/components/components.module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ import InfoIcon from '@carbon/icons/es/information/16';
8989
import CopyIcon from '@carbon/icons/es/copy/32';
9090
import downloadIcon from '@carbon/icons/es/download/16';
9191
import { ChartsModule } from '@carbon/charts-angular';
92+
import { IconComponent } from './icon/icon.component';
9293

9394
@NgModule({
9495
imports: [
@@ -172,7 +173,8 @@ import { ChartsModule } from '@carbon/charts-angular';
172173
FormAdvancedFieldsetComponent,
173174
UpgradableComponent,
174175
ProgressComponent,
175-
SidePanelComponent
176+
SidePanelComponent,
177+
IconComponent
176178
],
177179
providers: [provideCharts(withDefaultRegisterables())],
178180
exports: [
@@ -212,7 +214,8 @@ import { ChartsModule } from '@carbon/charts-angular';
212214
FormAdvancedFieldsetComponent,
213215
UpgradableComponent,
214216
ProgressComponent,
215-
SidePanelComponent
217+
SidePanelComponent,
218+
IconComponent
216219
]
217220
})
218221
export class ComponentsModule {
Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11

2-
<svg [cdsIcon]="icons.clipboard"
3-
[size]="icons.size16"
4-
(click)="onClick()"
5-
class="text-primary ms-2"
6-
title="Copy to Clipboard"
7-
i18n-title
8-
*ngIf="showIconOnly; else withButtonTpl"></svg>
9-
10-
<ng-template #withButtonTpl>
11-
12-
<cds-icon-button kind="tertiary"
13-
size="md"
14-
title="Copy to Clipboard"
15-
(click)="onClick()">
16-
<svg [cdsIcon]="icons.copy"
17-
[size]="icons.size16"
18-
class="cds--btn__icon"></svg>
19-
</cds-icon-button>
20-
</ng-template>
2+
<button cdsButton="ghost"
3+
class="clipboard-btn"
4+
[ngClass]="{'clipboard-btn-with-text': text}"
5+
[size]="size"
6+
description="Copy to Clipboard"
7+
i18n-description
8+
(click)="onClick()">
9+
@if(text) {
10+
<span data-toggle="tooltip"
11+
[title]="text"
12+
class="cds--type-mono">{{text}}</span>
13+
}
14+
<cd-icon type="copy"></cd-icon>
15+
</button>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.clipboard-btn {
2+
border: none;
3+
box-shadow: none;
4+
outline: none;
5+
}
6+
7+
.clipboard-btn-with-text {
8+
color: inherit;
9+
}

src/pybind/mgr/dashboard/frontend/src/app/shared/components/copy2clipboard-button/copy2clipboard-button.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,21 @@ import { Icons } from '~/app/shared/enum/icons.enum';
1111
styleUrls: ['./copy2clipboard-button.component.scss']
1212
})
1313
export class Copy2ClipboardButtonComponent {
14+
// The text to be copied
1415
@Input()
1516
private source: string;
1617

18+
// Optional: Extracts text to be copied by "id" attribute
1719
@Input()
1820
byId = true;
1921

22+
// Size of the button
2023
@Input()
21-
showIconOnly = false;
24+
size = 'md';
25+
26+
// Optional: Adds text to the left of copy icon
27+
@Input()
28+
text?: string;
2229

2330
icons = Icons;
2431

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<svg [cdsIcon]="icon"
2+
[size]="size"
3+
[class]="type+'-icon'"></svg>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@use '@carbon/styles/scss/theme';
2+
3+
.success-icon {
4+
color: theme.$support-success;
5+
}
6+
7+
.danger-icon {
8+
color: theme.$support-error;
9+
}
10+
11+
//@TODO: this naming needs to be changed
12+
// Do this after converting Icons enum to const
13+
.infoCircle-icon {
14+
color: theme.$support-info;
15+
}
16+
17+
.warning-icon {
18+
color: theme.$support-caution-major;
19+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { configureTestBed } from '~/testing/unit-test-helper';
4+
import { IconComponent } from './icon.component';
5+
6+
describe('IconComponent', () => {
7+
let component: IconComponent;
8+
let fixture: ComponentFixture<IconComponent>;
9+
10+
configureTestBed({
11+
declarations: [IconComponent],
12+
imports: []
13+
});
14+
15+
beforeEach(() => {
16+
fixture = TestBed.createComponent(IconComponent);
17+
component = fixture.componentInstance;
18+
fixture.detectChanges();
19+
});
20+
21+
it('should create', () => {
22+
expect(component).toBeTruthy();
23+
});
24+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Component, Input, OnInit } from '@angular/core';
2+
import { ICON_TYPE, Icons, IconSize } from '../../enum/icons.enum';
3+
4+
@Component({
5+
selector: 'cd-icon',
6+
templateUrl: './icon.component.html',
7+
styleUrl: './icon.component.scss'
8+
})
9+
export class IconComponent implements OnInit {
10+
@Input() type!: keyof typeof ICON_TYPE;
11+
@Input() size: IconSize = IconSize.size16;
12+
13+
icon: string;
14+
15+
ngOnInit() {
16+
this.icon = Icons[this.type];
17+
}
18+
}

0 commit comments

Comments
 (0)