Skip to content

Commit a19d145

Browse files
authored
Merge pull request #7736 from IgniteUI/skrastev/grid-icons
Implementation of grid icon service and separate icons per feature.
2 parents d36e1bc + ecb8fa9 commit a19d145

17 files changed

+125
-80
lines changed

projects/igniteui-angular/src/lib/action-strip/grid-actions/grid-actions-base.directive.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { Directive, Inject } from '@angular/core';
22
import { IgxActionStripComponent } from '../action-strip.component';
33
import { IgxRowDirective } from '../../grids/public_api';
4+
import { IgxGridIconService } from '../../grids/common/grid-icon.service';
45

56
@Directive({
67
selector: '[igxGridActionsBase]'
78
})
89
export class IgxGridActionsBaseDirective {
9-
constructor(@Inject(IgxActionStripComponent) protected strip: IgxActionStripComponent) { }
10+
constructor(@Inject(IgxActionStripComponent) protected strip: IgxActionStripComponent, protected iconService: IgxGridIconService) { }
1011

1112
/**
1213
* Getter to be used in template
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* tslint:disable */
2+
export const PINNING_ACTIONS_ICONS_FONT_SET = 'pinning-actions-icons';
3+
export const PINNING_ACTIONS_ICONS = [
4+
{
5+
name: 'jump_up',
6+
value: `<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
7+
<path d="M6 8l4 4H7c0 3.31 2.69 6 6 6 1.01 0 1.97-.25 2.8-.7l1.46 1.46A7.93 7.93 0 0113 20c-4.42 0-8-3.58-8-8H2l4-4zm15-5v2H5V3h16z"/>
8+
</svg>`
9+
},
10+
{
11+
name: 'jump_down',
12+
value: `<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
13+
<path d="M21 19v2H5v-2h16zM13 4c1.57 0 3.03.46 4.26 1.24L15.8 6.7A5.87 5.87 0 0013 6c-3.31 0-6 2.69-6 6h3l-4 4-4-4h3c0-4.42 3.58-8 8-8z"/>
14+
</svg>`
15+
}
16+
];
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<ng-container *ngIf="isRowContext">
22
<button *ngIf="inPinnedArea && pinnedTop" igxRipple igxButton="icon" (click)="scrollToRow($event)">
3-
<igx-icon fontSet="filtering-icons" name="jump_down"></igx-icon>
3+
<igx-icon fontSet="pinning-actions-icons" name="jump_down"></igx-icon>
44
</button>
55
<button *ngIf="inPinnedArea && !pinnedTop" igxRipple igxButton="icon" (click)="scrollToRow($event)">
6-
<igx-icon fontSet="filtering-icons" name="jump_up"></igx-icon>
6+
<igx-icon fontSet="pinning-actions-icons" name="jump_up"></igx-icon>
77
</button>
88
<button *ngIf="!pinned" igxRipple igxButton="icon" (click)="pin($event)">
9-
<igx-icon fontSet="filtering-icons" name="pin"></igx-icon>
9+
<igx-icon fontSet="pinning-icons" name="pin"></igx-icon>
1010
</button>
1111
<button *ngIf="pinned" igxRipple igxButton="icon" (click)="unpin($event)">
12-
<igx-icon fontSet="filtering-icons" name="unpin"></igx-icon>
12+
<igx-icon fontSet="pinning-icons" name="unpin"></igx-icon>
1313
</button>
1414
</ng-container>

projects/igniteui-angular/src/lib/action-strip/grid-actions/grid-pinning-actions.component.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Component, HostBinding } from '@angular/core';
22
import { IgxGridActionsBaseDirective } from './grid-actions-base.directive';
3-
3+
import { GridIconsFeature } from '../../grids/common/enums';
4+
import { PINNING_ACTIONS_ICONS_FONT_SET, PINNING_ACTIONS_ICONS, } from './grid-pinning-actions-icons';
5+
import { PINNING_ICONS_FONT_SET, PINNING_ICONS } from '../../grids/pinning/pinning-icons';
46
@Component({
57
selector: 'igx-grid-pinning-actions',
68
templateUrl: 'grid-pinning-actions.component.html',
@@ -29,7 +31,7 @@ export class IgxGridPinningActionsComponent extends IgxGridActionsBaseDirective
2931
}
3032
const context = this.strip.context;
3133
if (context && !this.iconsRendered) {
32-
this.renderIcons();
34+
this.registerSVGIcons();
3335
this.iconsRendered = true;
3436
}
3537
return context && context.pinned;
@@ -110,14 +112,15 @@ export class IgxGridPinningActionsComponent extends IgxGridActionsBaseDirective
110112
this.strip.hide();
111113
}
112114

113-
private renderIcons(): void {
115+
private registerSVGIcons(): void {
114116
if (!this.isRow(this.strip.context)) {
115117
return;
116118
}
117119
const context = this.strip.context;
118120
const grid = context.grid;
119121
if (grid) {
120-
grid.filteringService.registerSVGIcons();
122+
this.iconService.registerSVGIcons(GridIconsFeature.RowPinning, PINNING_ICONS, PINNING_ICONS_FONT_SET);
123+
this.iconService.registerSVGIcons(GridIconsFeature.RowPinningActions, PINNING_ACTIONS_ICONS, PINNING_ACTIONS_ICONS_FONT_SET);
121124
}
122125
}
123126
}

projects/igniteui-angular/src/lib/grids/common/enums.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,9 @@ export enum GridPagingMode {
4747
local,
4848
remote
4949
}
50+
51+
export enum GridIconsFeature {
52+
Filtering,
53+
RowPinning,
54+
RowPinningActions
55+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Injectable } from '@angular/core';
2+
import { IgxIconService } from '../../icon/icon.service';
3+
import { GridIconsFeature } from './enums';
4+
import { GridSVGIcon } from './grid.interface';
5+
6+
/**
7+
* @hidden
8+
*/
9+
@Injectable({
10+
providedIn: 'root'
11+
})
12+
export class IgxGridIconService {
13+
14+
private iconsMap = new Map<GridIconsFeature, GridSVGIcon[]>();
15+
private fontSetMap = new Map<GridIconsFeature, string>();
16+
private registeredIcons = new Map<GridIconsFeature, boolean>();
17+
18+
constructor(private iconService: IgxIconService) { }
19+
20+
/**
21+
* Register filtering SVG icons in the icon service.
22+
*/
23+
public registerSVGIcons(feature: GridIconsFeature, icons: GridSVGIcon[], fontSet: string): void {
24+
if (!this.registeredIcons.has(feature) || !this.registeredIcons.get(feature)) {
25+
for (const icon of icons) {
26+
if (!this.iconService.isSvgIconCached(icon.name, fontSet)) {
27+
this.iconService.addSvgIconFromText(icon.name, icon.value, fontSet);
28+
}
29+
}
30+
this.iconsMap.set(feature, icons);
31+
this.fontSetMap.set(feature, fontSet);
32+
this.registeredIcons.set(feature, true);
33+
}
34+
}
35+
}

projects/igniteui-angular/src/lib/grids/common/grid.interface.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,8 @@ export interface GridType extends IGridDataBindable {
6767
isDetailRecord(rec: any): boolean;
6868
isGroupByRecord(rec: any): boolean;
6969
}
70+
71+
export interface GridSVGIcon {
72+
name: string;
73+
value: string;
74+
}

projects/igniteui-angular/src/lib/grids/common/shared.module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { IgxProgressBarModule } from '../../progressbar/progressbar.component';
2121
import { IgxSelectModule } from '../../select/select.module';
2222
import { IgxDropDownModule } from '../../drop-down/public_api';
2323
import { IgxGridStateModule } from '../state.directive';
24+
import { IgxGridIconService } from './grid-icon.service';
2425

2526

2627
@NgModule({
@@ -71,6 +72,9 @@ import { IgxGridStateModule } from '../state.directive';
7172
IgxButtonGroupModule,
7273
IgxProgressBarModule,
7374
IgxSelectModule
75+
],
76+
providers: [
77+
IgxGridIconService
7478
]
7579
})
7680
export class IgxGridSharedModules {}

projects/igniteui-angular/src/lib/grids/filtering/excel-style/grid.excel-style-filtering.component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
tabindex="0"
2424
*ngIf="!column.pinned">
2525
<span>{{ grid.resourceStrings.igx_grid_excel_pin }}</span>
26-
<igx-icon fontSet="filtering-icons" name="pin"></igx-icon>
26+
<igx-icon fontSet="pinning-icons" name="pin"></igx-icon>
2727
</div>
2828

2929
<div class="igx-excel-filter__actions-unpin"
3030
(click)="onPin()"
3131
tabindex="0"
3232
*ngIf="column.pinned">
3333
<span>{{ grid.resourceStrings.igx_grid_excel_unpin }}</span>
34-
<igx-icon fontSet="filtering-icons" name="unpin"></igx-icon>
34+
<igx-icon fontSet="pinning-icons" name="unpin"></igx-icon>
3535
</div>
3636
</ng-template>
3737

@@ -79,14 +79,14 @@ <h4>{{ column.header || column.field }}</h4>
7979
(click)="onPin()"
8080
[disabled]="!isColumnPinnable"
8181
tabindex="0">
82-
<igx-icon fontSet="filtering-icons" name="pin"></igx-icon>
82+
<igx-icon fontSet="pinning-icons" name="pin"></igx-icon>
8383
</button>
8484
<button *ngIf="!column.disablePinning && column.pinned"
8585
igxButton="icon"
8686
[displayDensity]="grid.displayDensity"
8787
(click)="onPin()"
8888
tabindex="0">
89-
<igx-icon fontSet="filtering-icons" name="unpin"></igx-icon>
89+
<igx-icon fontSet="pinning-icons" name="unpin"></igx-icon>
9090
</button>
9191
<button *ngIf="!column.disableHiding"
9292
igxButton="icon"

projects/igniteui-angular/src/lib/grids/filtering/svgIcons.ts renamed to projects/igniteui-angular/src/lib/grids/filtering/grid-filtering-icons.ts

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* tslint:disable */
2-
export default [
2+
export const FILTERING_ICONS_FONT_SET = 'filtering-icons';
3+
export const FILTERING_ICONS = [
34
{
45
name: 'add_filter',
56
value: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
@@ -206,19 +207,6 @@ export default [
206207
<path d="M19 4h-1V2h-2v2H8V2H6v2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2zm0 16H5V9h14z"/>
207208
</svg>`
208209
},
209-
{
210-
name: 'pin',
211-
value: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
212-
<path d="M15.18 2.25l7.07 7.07-2.83-.01-3.54 3.55.01 4.24-3.53-3.54-5.66 5.66H5.28V17.8l5.66-5.66L7.4 8.61l4.24.01 3.55-3.54-.01-2.83z"/>
213-
</svg>`
214-
},
215-
{
216-
name: 'unpin',
217-
value: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
218-
<path fill="none" d="M0 0h24v25H0V0z"/>
219-
<path d="M11.84 14.08L6.7 19.22H5.28V17.8l5.14-5.14L2 4.26 3.29 3l18 18L20 22.21zm4-.49l-5-5h.73l3.55-3.54v-2.8l7.07 7.07h-2.77l-3.54 3.54z" />
220-
</svg>`
221-
},
222210
{
223211
name: 'ungroup',
224212
value: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
@@ -228,17 +216,5 @@ export default [
228216
<rect x="7.5" y="7.5" width="3.75" height="3.75"/>
229217
<rect x="12.75" y="7.5" width="3.75" height="3.75"/>
230218
</svg>`
231-
},
232-
{
233-
name: 'jump_up',
234-
value: `<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
235-
<path d="M6 8l4 4H7c0 3.31 2.69 6 6 6 1.01 0 1.97-.25 2.8-.7l1.46 1.46A7.93 7.93 0 0113 20c-4.42 0-8-3.58-8-8H2l4-4zm15-5v2H5V3h16z"/>
236-
</svg>`
237-
},
238-
{
239-
name: 'jump_down',
240-
value: `<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
241-
<path d="M21 19v2H5v-2h16zM13 4c1.57 0 3.03.46 4.26 1.24L15.8 6.7A5.87 5.87 0 0013 6c-3.31 0-6 2.69-6 6h3l-4 4-4-4h3c0-4.42 3.58-8 8-8z"/>
242-
</svg>`
243219
}
244220
];

0 commit comments

Comments
 (0)