Skip to content

Commit fa51604

Browse files
committed
mgr/dashboard: Add generic component for icons
Fixes https://tracker.ceph.com/issues/71947 Fixes https://tracker.ceph.com/issues/71933 Signed-off-by: Afreen Misbah <[email protected]>
1 parent bc76004 commit fa51604

File tree

8 files changed

+132
-41
lines changed

8 files changed

+132
-41
lines changed

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

Lines changed: 36 additions & 34 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="info">
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">
@@ -99,13 +99,15 @@
9999
</i>
100100
</span>
101101
</ng-template>
102-
102+
<cd-icon
103+
type="progress">
104+
</cd-icon >
103105
<ng-template #osdSummary>
104106
<span *ngIf="data.up === data.in">
105107
{{ data.up }}
106-
<i class="text-success"
107-
[ngClass]="[icons.success]">
108-
</i>
108+
<cd-icon
109+
type="success">
110+
</cd-icon >
109111
</span>
110112
<span *ngIf="data.up !== data.in">
111113
{{ data.up }}
@@ -151,36 +153,36 @@
151153
<ng-template #iscsiSummary>
152154
<span>
153155
{{ data.up }}
154-
<i class="text-success"
156+
<cd-icon
155157
*ngIf="data.up || data.up === 0"
156-
[ngClass]="[icons.success]">
157-
</i>
158+
type="success">
159+
</cd-icon >
158160
</span>
159161
<span *ngIf="data.down"
160162
class="ms-2">
161163
{{ data.down }}
162-
<i class="text-danger"
163-
[ngClass]="[icons.danger]">
164-
</i>
164+
<cd-icon
165+
type="danger">
166+
</cd-icon >
165167
</span>
166168
</ng-template>
167169

168170
<ng-template #simplifiedSummary>
169171
<span *ngIf="!dropdownTotalError else showErrorNum">
170172
{{ data }}
171-
<i class="text-success"
172-
[ngClass]="[icons.success]"></i>
173+
<cd-icon
174+
type="success"></cd-icon >
173175
</span>
174176
<ng-template #showErrorNum>
175177
<span *ngIf="data - dropdownTotalError > 0">
176178
{{ data - dropdownTotalError }}
177-
<i class="text-success"
178-
[ngClass]="[icons.success]"></i>
179+
<cd-icon
180+
type="success"></cd-icon >
179181
</span>
180182
<span>
181183
{{ dropdownTotalError }}
182-
<i class="text-danger"
183-
[ngClass]="[icons.danger]"></i>
184+
<cd-icon
185+
type="danger"></cd-icon >
184186
</span>
185187
</ng-template>
186188
</ng-template>
@@ -211,17 +213,17 @@
211213
</div>
212214
<span [ngClass]="data.value.error ? 'me-2' : 'me-4'">
213215
{{ data.value.ok }}
214-
<i class="text-success"
216+
<cd-icon
215217
*ngIf="data.value.ok"
216-
[ngClass]="[icons.success]">
217-
</i>
218+
type="success">
219+
</cd-icon >
218220
</span>
219221
<span *ngIf="data.value.error"
220222
class="me-4 ms-2">
221223
{{ data.value.error }}
222-
<i class="text-danger"
223-
[ngClass]="[icons.danger]">
224-
</i>
224+
<cd-icon
225+
type="danger">
226+
</cd-icon >
225227
</span>
226228
</div>
227229
</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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@if (type === ICON_TYPE.danger) {
2+
<svg class = "danger-icon"
3+
[cdsIcon]="ICONS.danger"
4+
[size]="size"></svg>
5+
}
6+
7+
@if (type === ICON_TYPE.info) {
8+
<svg class = "info-icon"
9+
[cdsIcon]="ICONS.infoCircle"
10+
[size]="size"></svg>
11+
}
12+
13+
@if (type === ICON_TYPE.success) {
14+
<svg class = "success-icon"
15+
[cdsIcon]="ICONS.success"
16+
[size]="size"></svg>
17+
}
18+
19+
@if (type === ICON_TYPE.warning) {
20+
<svg class = "warning-icon"
21+
[cdsIcon]="ICONS.warning"
22+
[size]="size"></svg>
23+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
.info-icon {
12+
color: theme.$support-info;
13+
}
14+
15+
.warning-icon {
16+
color: theme.$support-caution-major;
17+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { IconComponent } from './icon.component';
4+
5+
describe('IconComponent', () => {
6+
let component: IconComponent;
7+
let fixture: ComponentFixture<IconComponent>;
8+
9+
beforeEach(async () => {
10+
await TestBed.configureTestingModule({
11+
imports: [IconComponent]
12+
}).compileComponents();
13+
14+
fixture = TestBed.createComponent(IconComponent);
15+
component = fixture.componentInstance;
16+
fixture.detectChanges();
17+
});
18+
19+
it('should create', () => {
20+
expect(component).toBeTruthy();
21+
});
22+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Component, Input } from '@angular/core';
2+
import { ICON_TYPE, Icons, IconsSize } 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 {
10+
@Input() type!: keyof typeof ICON_TYPE;
11+
@Input() size: IconsSize = IconsSize.size16;
12+
13+
readonly ICONS = Icons;
14+
readonly ICON_TYPE = ICON_TYPE;
15+
}

src/pybind/mgr/dashboard/frontend/src/app/shared/enum/icons.enum.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export enum Icons {
3636
infoCircle = 'information--filled', // Info on landing page
3737
questionCircle = 'help',
3838
danger = 'warning--filled',
39-
// success = 'fa fa-check-circle',
4039
success = 'checkmark--filled',
4140
check = 'checkmark', // Notification check
4241
show = 'view', // Show
@@ -99,3 +98,17 @@ export enum Icons {
9998
spin = 'fa fa-spin', // To get any icon to rotate
10099
inverse = 'fa fa-inverse' // To get an alternative icon color
101100
}
101+
102+
export enum IconsSize {
103+
size16 = '16',
104+
size20 = '20',
105+
size24 = '24',
106+
size32 = '32'
107+
}
108+
109+
export const ICON_TYPE = {
110+
danger: 'danger',
111+
info: 'info',
112+
success: 'success',
113+
warning: 'warning'
114+
} as const;

src/pybind/mgr/dashboard/frontend/src/styles/_carbon-defaults.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,6 @@ Tabs
177177
background: var(--cds-layer-01);
178178
}
179179

180-
.cds-success-color {
181-
fill: theme.$support-success;
182-
}
183-
184180
.cds-danger-color {
185181
fill: theme.$support-error;
186182
}

0 commit comments

Comments
 (0)