Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 13, 2022. It is now read-only.

Commitd6cbabf

Browse files
committed
fix(icon): renfer svg before c-icon component
1 parentad45c31 commitd6cbabf

File tree

5 files changed

+100
-44
lines changed

5 files changed

+100
-44
lines changed

‎projects/coreui-icons-angular/src/lib/icon/icon.component.scss‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
:hostuse,:hostsvg {}
1+
:hostuse,:hostsvg {}
22

33
// Icon variables
4-
$icon-size-base:1rem!default;
5-
$icon-size-sm:$icon-size-base*.875!default;
6-
$icon-size-lg:$icon-size-base*1.25!default;
7-
$icon-size-xl:$icon-size-base*1.5!default;
8-
$icon-size-xxl:$icon-size-base*2!default;
4+
$icon-size-base:1rem!default;
5+
$icon-size-sm:$icon-size-base*.875!default;
6+
$icon-size-lg:$icon-size-base*1.25!default;
7+
$icon-size-xl:$icon-size-base*1.5!default;
8+
$icon-size-xxl:$icon-size-base*2!default;
99

1010
// Icon sizes
1111
@mixinicon-size($icon-size) {
Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,65 @@
11
import{ComponentFixture,TestBed}from'@angular/core/testing';
2-
import{HtmlAttributesDirective}from'../shared/html-attr.directive';
2+
import{Component,DebugElement,ViewChild}from'@angular/core';
33

4+
import{cilList}from'@coreui/icons';
5+
import{HtmlAttributesDirective}from'../shared/html-attr.directive';
46
import{IconComponent}from'./icon.component';
7+
import{IconSetService}from'../icon-set';
8+
import{By}from'@angular/platform-browser';
9+
10+
@Component({
11+
template:`
12+
<div>
13+
<c-icon #icon name="cilList" size="lg" class="test"></c-icon>
14+
</div>`
15+
})
16+
classTestComponent{
17+
@ViewChild('icon',{read:IconComponent})iconRef!:IconComponent;
18+
19+
constructor(
20+
publiciconSet:IconSetService
21+
){
22+
this.iconSet.icons={cilList};
23+
}
24+
}
25+
526

627
describe('IconComponent',()=>{
7-
letcomponent:IconComponent;
8-
letfixture:ComponentFixture<IconComponent>;
28+
letinputEl:DebugElement;
29+
letcomponent:TestComponent;
30+
letfixture:ComponentFixture<TestComponent>;
931

1032
beforeEach(async()=>{
1133
TestBed.configureTestingModule({
12-
declarations:[IconComponent,HtmlAttributesDirective]
34+
declarations:[TestComponent,IconComponent,HtmlAttributesDirective],
35+
providers:[IconSetService]
1336
}).compileComponents();
37+
1438
});
1539

1640
beforeEach(()=>{
17-
fixture=TestBed.createComponent(IconComponent);
41+
fixture=TestBed.createComponent(TestComponent);
1842
component=fixture.componentInstance;
1943
fixture.detectChanges();
44+
inputEl=fixture.debugElement.query(By.css('svg'));
2045
});
2146

2247
it('should create',()=>{
2348
expect(component).toBeTruthy();
2449
});
50+
51+
it('service should exist',()=>{
52+
expect(component.iconSet).toBeTruthy();
53+
});
54+
it('icon component should render',()=>{
55+
expect(component.iconRef).toBeTruthy();
56+
expect(component.iconRef.name).toBe('cilList');
57+
expect(component.iconRef.svgElementRef).toBeTruthy();
58+
});
59+
it('icon classes should be applied',()=>{
60+
expect(inputEl.nativeElement).toBeTruthy();
61+
expect(inputEl.nativeElement).toHaveClass('icon');
62+
expect(inputEl.nativeElement).toHaveClass('icon-lg');
63+
expect(inputEl.nativeElement).toHaveClass('test');
64+
});
2565
});

‎projects/coreui-icons-angular/src/lib/icon/icon.component.svg‎

Lines changed: 15 additions & 11 deletions
Loading

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

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import{Component,Input}from'@angular/core';
1+
import{AfterViewInit,Component,ElementRef,Input,Renderer2,ViewChild}from'@angular/core';
22
import{DomSanitizer,SafeHtml}from'@angular/platform-browser';
33
import{IconSetService}from'../icon-set/icon-set.service';
44

@@ -7,9 +7,9 @@ import { IconSetService } from '../icon-set/icon-set.service';
77
templateUrl:'./icon.component.svg',
88
styleUrls:['./icon.component.scss']
99
})
10-
exportclassIconComponent{
10+
exportclassIconComponentimplementsAfterViewInit{
1111

12-
@Input()attributes:any={role:'img'};
12+
@Input()attributes:any={role:'img'};
1313
@Input()content?:string|string[];
1414
@Input()size:'custom'|'custom-size'|'sm'|'lg'|'xl'|'2xl'|'3xl'|'4xl'|'5xl'|'6xl'|'7xl'|'8xl'|'9xl'|''='';
1515
@Input()src?:string;
@@ -19,34 +19,46 @@ export class IconComponent {
1919
@Input()width?:string;
2020
@Input()height?:string;
2121

22-
constructor(
23-
privatesanitizer:DomSanitizer,
24-
privateiconSet:IconSetService
25-
){}
26-
27-
// tslint:disable-next-line:variable-name
28-
private_name!:string;
22+
@Input()
23+
setname(name:string){
24+
constnameIsKebabCase=name.includes('-');
25+
this._name=nameIsKebabCase ?this.toCamelCase(name) :name;
26+
}
2927

3028
getname():string{
31-
constnameIsKebabCase=this._name?.includes('-');
32-
returnnameIsKebabCase ?this.toCamelCase(this._name) :this._name;
29+
returnthis._name;
3330
}
3431

32+
private_name!:string;
33+
3534
@Input()
36-
setname(name:string){
37-
this._name=name;
35+
setviewBox(viewBox:string){
36+
this._viewBox=viewBox;
37+
}
38+
getviewBox():string{
39+
returnthis._viewBox??`0 0${this.scale}`;
3840
}
39-
40-
// tslint:disable-next-line:variable-name
4141
private_viewBox!:string;
4242

43-
getviewBox():string{
44-
returnthis._viewBox||`0 0${this.scale}`;
43+
@ViewChild('svgElement',{read:ElementRef})svgElementRef!:ElementRef;
44+
45+
constructor(
46+
privaterenderer:Renderer2,
47+
privateelementRef:ElementRef,
48+
privatesanitizer:DomSanitizer,
49+
privateiconSet:IconSetService
50+
){
51+
this.renderer.setStyle(this.elementRef.nativeElement,'display','none');
4552
}
4653

47-
@Input()
48-
setviewBox(viewBox:string){
49-
this._viewBox=viewBox;
54+
ngAfterViewInit():void{
55+
this.elementRef.nativeElement.classList.forEach((item:string)=>{
56+
this.renderer.addClass(this.svgElementRef.nativeElement,item);
57+
});
58+
constparentElement=this.renderer.parentNode(this.elementRef.nativeElement);
59+
constsvgElement=this.svgElementRef.nativeElement;
60+
this.renderer.insertBefore(parentElement,svgElement,this.elementRef.nativeElement);
61+
this.renderer.removeChild(parentElement,this.elementRef.nativeElement);
5062
}
5163

5264
gettitleCode():string{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('HtmlAttributesDirective', () => {
4747

4848
it('should render an id attr',()=>{
4949
fixture.detectChanges();
50-
console.log(inputEl.nativeElement.attributes);
50+
//console.log(inputEl.nativeElement.attributes);
5151
expect(inputEl.nativeElement.getAttribute('id')).toBe('id-1');
5252
});
5353
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp