-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
167 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
projects/ng-cdbangular/src/lib/components/icon/icon.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<i #cdbicon class="cdb-icon {{class}} fa-{{ icon }}" [style]="style" [ngClass]="{ | ||
'fa-li': list, | ||
'fa-fw': fixed, | ||
'fa-border': border, | ||
'fa-spin' : spin, | ||
'fa-pulse' : pulse, | ||
'fa-inverse': inverse | ||
}"></i> |
7 changes: 7 additions & 0 deletions
7
projects/ng-cdbangular/src/lib/components/icon/icon.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@import url("https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css"); | ||
@import "../../styles/colors"; | ||
@import "../../styles/colorStyles"; | ||
|
||
.cdb-icon { | ||
padding: 0px 4px; | ||
} |
134 changes: 134 additions & 0 deletions
134
projects/ng-cdbangular/src/lib/components/icon/icon.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import { | ||
Component, | ||
OnInit, | ||
Input, | ||
AfterViewInit, | ||
ElementRef, | ||
Renderer2, | ||
ViewChild, | ||
ViewEncapsulation, | ||
} from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'CDBIcon', | ||
templateUrl: './icon.component.html', | ||
styleUrls: ['./icon.component.scss'], | ||
encapsulation: ViewEncapsulation.None, | ||
}) | ||
export class IconComponent implements OnInit, AfterViewInit { | ||
@ViewChild('cdbicon', { static: false }) cdbicon: ElementRef; | ||
|
||
@Input() border: boolean = false; | ||
@Input() brand: boolean = false; | ||
@Input() class: string; | ||
@Input() style: string; | ||
@Input() fab: boolean = false; | ||
@Input() duotone: boolean = false; | ||
@Input() fal: boolean = false; | ||
@Input() fad: boolean = false; | ||
@Input() far: boolean = false; | ||
@Input() solid: boolean = false; | ||
@Input() fixed: boolean = false; | ||
@Input() fas: boolean = false; | ||
@Input() flip: string; | ||
@Input() icon: string; | ||
@Input() inverse: boolean = false; | ||
@Input() light: boolean = false; | ||
@Input() list: boolean = false; | ||
@Input() pull: string; | ||
@Input() pulse: boolean = false; | ||
@Input() regular: boolean = false; | ||
@Input() rotate: string; | ||
@Input() size: string; | ||
@Input() spin: boolean = false; | ||
@Input() stack: string; | ||
|
||
iconClasses = {}; | ||
iconPrefix = ''; | ||
|
||
constructor(private elRef: ElementRef, private renderer: Renderer2) {} | ||
|
||
ngOnInit(): void { | ||
this.iconPrefix = | ||
this.regular || this.far | ||
? 'far' | ||
: this.solid || this.fas | ||
? 'fas' | ||
: this.light || this.fal | ||
? 'fal' | ||
: this.duotone || this.fad | ||
? 'fad' | ||
: this.brand || this.fab | ||
? 'fab' | ||
: 'fa'; | ||
|
||
this.renderer.removeAttribute(this.elRef.nativeElement, 'class') | ||
this.renderer.removeAttribute(this.elRef.nativeElement, 'style') | ||
|
||
} | ||
ngAfterViewInit() { | ||
|
||
this.renderer.addClass(this.cdbicon.nativeElement, this.iconPrefix); | ||
|
||
if (this.size) { | ||
this.renderer.addClass( | ||
this.cdbicon.nativeElement, | ||
`fa-${this.size}` | ||
) | ||
} | ||
if (this.pull) { | ||
this.renderer.addClass( | ||
this.cdbicon.nativeElement, | ||
`fa-pull-${this.pull}` | ||
) | ||
} | ||
if (this.rotate) { | ||
this.renderer.addClass( | ||
this.cdbicon.nativeElement, | ||
`fa-rotate-${this.rotate}` | ||
) | ||
} | ||
if (this.flip) { | ||
this.renderer.addClass( | ||
this.cdbicon.nativeElement, | ||
`fa-flip-${this.flip}` | ||
) | ||
} | ||
if (this.stack) { | ||
this.renderer.addClass( | ||
this.cdbicon.nativeElement, | ||
`fa-${this.stack}` | ||
) | ||
} | ||
|
||
|
||
// let iconClasses: {} = { | ||
// // icon: this.icon ? `fa-${this.icon}` : false, | ||
// // size: this.size ? `fa-${this.size}` : false, | ||
// // pull: this.pull ? `fa-pull-${this.pull}` : false, | ||
// // rotate: this.rotate ? `fa-rotate-${this.rotate}` : false, | ||
// // flip: this.flip ? `fa-flip-${this.flip}` : false, | ||
// // stack: this.stack ? `fa-${this.stack}` : false, | ||
// }; | ||
|
||
// const returnClasses = (classes) => { | ||
// const newClassesObject = Object.keys(classes).reduce( | ||
// (previousValue, currentElement) => { | ||
// if (classes[currentElement]) { | ||
// previousValue[currentElement] = classes[currentElement]; | ||
// } | ||
// return previousValue; | ||
// }, | ||
// {} | ||
// ); | ||
// return newClassesObject; | ||
// }; | ||
// this.iconClasses = returnClasses(iconClasses); | ||
// Object.keys(this.iconClasses).forEach((iconClass) => { | ||
// this.renderer.addClass( | ||
// this.cdbicon.nativeElement, | ||
// this.iconClasses[iconClass] | ||
// ); | ||
// }); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
projects/ng-cdbangular/src/lib/components/icon/icon.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { IconComponent } from './icon.component'; | ||
|
||
@NgModule({ | ||
declarations: [IconComponent], | ||
imports: [CommonModule], | ||
exports: [IconComponent], | ||
}) | ||
export class IconModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { IconModule } from './icon.module'; | ||
export { IconComponent } from './icon.component'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters