Skip to content

Commit 15ce7ef

Browse files
committed
feat(cIcon): standalone directive
1 parent 67c61b6 commit 15ce7ef

File tree

7 files changed

+26
-18
lines changed

7 files changed

+26
-18
lines changed

projects/coreui-icons-angular/src/lib/icon/icon.component.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ describe('IconComponent', () => {
3131

3232
beforeEach(async () => {
3333
TestBed.configureTestingModule({
34-
declarations: [TestComponent, IconComponent, HtmlAttributesDirective],
34+
declarations: [TestComponent],
35+
imports: [IconComponent, HtmlAttributesDirective],
3536
providers: [IconSetService]
3637
}).compileComponents();
3738

projects/coreui-icons-angular/src/lib/icon/icon.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
import { CommonModule } from '@angular/common';
12
import { AfterViewInit, Component, ElementRef, Input, Renderer2, ViewChild } from '@angular/core';
23
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
4+
5+
import { HtmlAttributesDirective } from '../shared/html-attr.directive';
36
import { IconSetService } from '../icon-set';
47
import { IconSize, IIcon } from './icon.interface';
58

69
@Component({
710
selector: 'c-icon',
811
templateUrl: './icon.component.svg',
9-
styleUrls: ['./icon.component.scss']
12+
styleUrls: ['./icon.component.scss'],
13+
standalone: true,
14+
imports: [CommonModule, HtmlAttributesDirective]
1015
})
1116
export class IconComponent implements IIcon, AfterViewInit {
1217

projects/coreui-icons-angular/src/lib/icon/icon.directive.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ import { cilList } from '@coreui/icons';
1111
<svg [cIcon]="this.iconSet.icons.cilList" size="lg" class="test" title="Test"></svg>`
1212
})
1313
class TestComponent {
14-
@ViewChild(IconDirective, {read: IconDirective}) iconRef!: IconDirective;
15-
1614
constructor(
1715
public iconSet: IconSetService
1816
) {
19-
this.iconSet.icons = {cilList};
17+
this.iconSet.icons = { cilList };
2018
}
21-
}
2219

20+
@ViewChild(IconDirective, { read: IconDirective }) iconRef!: IconDirective;
21+
}
2322

2423
describe('IconDirective', () => {
2524
let component: TestComponent;
@@ -31,8 +30,9 @@ describe('IconDirective', () => {
3130

3231
beforeEach(() => {
3332
TestBed.configureTestingModule({
34-
declarations: [TestComponent, IconDirective],
35-
providers: [IconSetService]
33+
declarations: [TestComponent],
34+
providers: [IconSetService],
35+
imports: [IconDirective]
3636
}).compileComponents();
3737

3838
fixture = TestBed.createComponent(TestComponent);

projects/coreui-icons-angular/src/lib/icon/icon.directive.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { IconSize, IIcon } from './icon.interface';
66

77
@Directive({
88
selector: 'svg[cIcon]',
9-
exportAs: 'cIcon'
9+
exportAs: 'cIcon',
10+
standalone: true
1011
})
1112
export class IconDirective implements IIcon {
1213

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
import { NgModule } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33

4+
import { HtmlAttributesDirective } from '../shared/html-attr.directive';
45
import { IconComponent } from './icon.component';
56
import { IconDirective } from './icon.directive';
6-
import { HtmlAttributesDirective } from '../shared/html-attr.directive';
77

88
@NgModule({
9-
declarations: [
10-
IconComponent,
11-
HtmlAttributesDirective,
12-
IconDirective
13-
],
9+
declarations: [],
1410
imports: [
1511
CommonModule,
12+
HtmlAttributesDirective,
13+
IconComponent,
14+
IconDirective
1615
],
1716
exports: [
1817
IconComponent,
1918
IconDirective
20-
],
19+
]
2120
})
2221
export class IconModule {
2322
}

projects/coreui-icons-angular/src/lib/shared/html-attr.directive.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ describe('HtmlAttributesDirective', () => {
2020

2121
beforeEach(() => {
2222
TestBed.configureTestingModule({
23-
declarations: [TestComponent, HtmlAttributesDirective]
23+
declarations: [TestComponent],
24+
imports: [HtmlAttributesDirective]
2425
});
2526
fixture = TestBed.createComponent(TestComponent);
2627
component = fixture.componentInstance;

projects/coreui-icons-angular/src/lib/shared/html-attr.directive.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { Directive, ElementRef, Input, OnInit, Renderer2 } from '@angular/core';
22

33
@Directive({
44
selector: '[cHtmlAttr]',
5-
exportAs: 'cHtmlAttr'
5+
exportAs: 'cHtmlAttr',
6+
standalone: true
67
})
78
export class HtmlAttributesDirective implements OnInit {
89

0 commit comments

Comments
 (0)