@carbon/icons-angular
Version:
Angular components for icons in digital and software products using the Carbon Design System
174 lines (171 loc) • 13.4 kB
JavaScript
import { __decorate, __metadata } from 'tslib';
import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core';
import { getAttributes } from '@carbon/icon-helpers';
var SunDirective_1;
let SunComponent = class SunComponent {
constructor() {
this.focusable = false;
}
};
__decorate([
Input(),
__metadata("design:type", String)
], SunComponent.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SunComponent.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], SunComponent.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SunComponent.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], SunComponent.prototype, "focusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SunComponent.prototype, "innerClass", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SunComponent.prototype, "size", void 0);
SunComponent = __decorate([
Component({
selector: "ibm-icon-sun",
template: `
<svg
ibmIconSun
[size]="size"
[ariaLabel]="ariaLabel"
[ariaLabelledby]="ariaLabelledby"
[ariaHidden]="ariaHidden"
[title]="title"
[isFocusable]="focusable"
[attr.class]="innerClass">
</svg>
`
})
], SunComponent);
let SunDirective = SunDirective_1 = class SunDirective {
constructor(elementRef) {
this.elementRef = elementRef;
this.isFocusable = false;
this.icons = {
"32": {
metadata: { "moduleName": "Sun32", "filepath": "sun/32.js", "descriptor": { "elem": "svg", "attrs": { "xmlns": "http://www.w3.org/2000/svg", "viewBox": "0 0 32 32", "fill": "currentColor", "width": 32, "height": 32 }, "content": [{ "elem": "path", "attrs": { "d": "M16,12a4,4,0,1,1-4,4,4.0045,4.0045,0,0,1,4-4m0-2a6,6,0,1,0,6,6,6,6,0,0,0-6-6Z", "transform": "translate(0 .005)" } }, { "elem": "path", "attrs": { "d": "M6.854 5.375H8.854V10.333H6.854z", "transform": "rotate(-45 7.86 7.856)" } }, { "elem": "path", "attrs": { "d": "M2 15.005H7V17.005000000000003H2z" } }, { "elem": "path", "attrs": { "d": "M5.375 23.147H10.333V25.147H5.375z", "transform": "rotate(-45 7.86 24.149)" } }, { "elem": "path", "attrs": { "d": "M15 25.005H17V30.005H15z" } }, { "elem": "path", "attrs": { "d": "M23.147 21.668H25.147V26.625999999999998H23.147z", "transform": "rotate(-45 24.152 24.149)" } }, { "elem": "path", "attrs": { "d": "M25 15.005H30V17.005000000000003H25z" } }, { "elem": "path", "attrs": { "d": "M21.668 6.854H26.625999999999998V8.854H21.668z", "transform": "rotate(-45 24.152 7.856)" } }, { "elem": "path", "attrs": { "d": "M15 2.005H17V7.005H15z" } }], "name": "sun", "size": 32 }, "size": 32 },
svg: `<svg focusable="false" preserveAspectRatio="xMidYMid meet" xmlns="http://www.w3.org/2000/svg" fill="currentColor" width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><path d="M16,12a4,4,0,1,1-4,4,4.0045,4.0045,0,0,1,4-4m0-2a6,6,0,1,0,6,6,6,6,0,0,0-6-6Z" transform="translate(0 .005)"></path><path d="M6.854 5.375H8.854V10.333H6.854z" transform="rotate(-45 7.86 7.856)"></path><path d="M2 15.005H7V17.005000000000003H2z"></path><path d="M5.375 23.147H10.333V25.147H5.375z" transform="rotate(-45 7.86 24.149)"></path><path d="M15 25.005H17V30.005H15z"></path><path d="M23.147 21.668H25.147V26.625999999999998H23.147z" transform="rotate(-45 24.152 24.149)"></path><path d="M25 15.005H30V17.005000000000003H25z"></path><path d="M21.668 6.854H26.625999999999998V8.854H21.668z" transform="rotate(-45 24.152 7.856)"></path><path d="M15 2.005H17V7.005H15z"></path></svg>`
},
"24": {
metadata: { "moduleName": "Sun24", "filepath": "sun/24.js", "descriptor": { "elem": "svg", "attrs": { "xmlns": "http://www.w3.org/2000/svg", "viewBox": "0 0 32 32", "fill": "currentColor", "width": 24, "height": 24 }, "content": [{ "elem": "path", "attrs": { "d": "M16,12a4,4,0,1,1-4,4,4.0045,4.0045,0,0,1,4-4m0-2a6,6,0,1,0,6,6,6,6,0,0,0-6-6Z", "transform": "translate(0 .005)" } }, { "elem": "path", "attrs": { "d": "M6.854 5.375H8.854V10.333H6.854z", "transform": "rotate(-45 7.86 7.856)" } }, { "elem": "path", "attrs": { "d": "M2 15.005H7V17.005000000000003H2z" } }, { "elem": "path", "attrs": { "d": "M5.375 23.147H10.333V25.147H5.375z", "transform": "rotate(-45 7.86 24.149)" } }, { "elem": "path", "attrs": { "d": "M15 25.005H17V30.005H15z" } }, { "elem": "path", "attrs": { "d": "M23.147 21.668H25.147V26.625999999999998H23.147z", "transform": "rotate(-45 24.152 24.149)" } }, { "elem": "path", "attrs": { "d": "M25 15.005H30V17.005000000000003H25z" } }, { "elem": "path", "attrs": { "d": "M21.668 6.854H26.625999999999998V8.854H21.668z", "transform": "rotate(-45 24.152 7.856)" } }, { "elem": "path", "attrs": { "d": "M15 2.005H17V7.005H15z" } }], "name": "sun", "size": 24 }, "size": 24 },
svg: `<svg focusable="false" preserveAspectRatio="xMidYMid meet" xmlns="http://www.w3.org/2000/svg" fill="currentColor" width="24" height="24" viewBox="0 0 32 32" aria-hidden="true"><path d="M16,12a4,4,0,1,1-4,4,4.0045,4.0045,0,0,1,4-4m0-2a6,6,0,1,0,6,6,6,6,0,0,0-6-6Z" transform="translate(0 .005)"></path><path d="M6.854 5.375H8.854V10.333H6.854z" transform="rotate(-45 7.86 7.856)"></path><path d="M2 15.005H7V17.005000000000003H2z"></path><path d="M5.375 23.147H10.333V25.147H5.375z" transform="rotate(-45 7.86 24.149)"></path><path d="M15 25.005H17V30.005H15z"></path><path d="M23.147 21.668H25.147V26.625999999999998H23.147z" transform="rotate(-45 24.152 24.149)"></path><path d="M25 15.005H30V17.005000000000003H25z"></path><path d="M21.668 6.854H26.625999999999998V8.854H21.668z" transform="rotate(-45 24.152 7.856)"></path><path d="M15 2.005H17V7.005H15z"></path></svg>`
},
"20": {
metadata: { "moduleName": "Sun20", "filepath": "sun/20.js", "descriptor": { "elem": "svg", "attrs": { "xmlns": "http://www.w3.org/2000/svg", "viewBox": "0 0 32 32", "fill": "currentColor", "width": 20, "height": 20 }, "content": [{ "elem": "path", "attrs": { "d": "M16,12a4,4,0,1,1-4,4,4.0045,4.0045,0,0,1,4-4m0-2a6,6,0,1,0,6,6,6,6,0,0,0-6-6Z", "transform": "translate(0 .005)" } }, { "elem": "path", "attrs": { "d": "M6.854 5.375H8.854V10.333H6.854z", "transform": "rotate(-45 7.86 7.856)" } }, { "elem": "path", "attrs": { "d": "M2 15.005H7V17.005000000000003H2z" } }, { "elem": "path", "attrs": { "d": "M5.375 23.147H10.333V25.147H5.375z", "transform": "rotate(-45 7.86 24.149)" } }, { "elem": "path", "attrs": { "d": "M15 25.005H17V30.005H15z" } }, { "elem": "path", "attrs": { "d": "M23.147 21.668H25.147V26.625999999999998H23.147z", "transform": "rotate(-45 24.152 24.149)" } }, { "elem": "path", "attrs": { "d": "M25 15.005H30V17.005000000000003H25z" } }, { "elem": "path", "attrs": { "d": "M21.668 6.854H26.625999999999998V8.854H21.668z", "transform": "rotate(-45 24.152 7.856)" } }, { "elem": "path", "attrs": { "d": "M15 2.005H17V7.005H15z" } }], "name": "sun", "size": 20 }, "size": 20 },
svg: `<svg focusable="false" preserveAspectRatio="xMidYMid meet" xmlns="http://www.w3.org/2000/svg" fill="currentColor" width="20" height="20" viewBox="0 0 32 32" aria-hidden="true"><path d="M16,12a4,4,0,1,1-4,4,4.0045,4.0045,0,0,1,4-4m0-2a6,6,0,1,0,6,6,6,6,0,0,0-6-6Z" transform="translate(0 .005)"></path><path d="M6.854 5.375H8.854V10.333H6.854z" transform="rotate(-45 7.86 7.856)"></path><path d="M2 15.005H7V17.005000000000003H2z"></path><path d="M5.375 23.147H10.333V25.147H5.375z" transform="rotate(-45 7.86 24.149)"></path><path d="M15 25.005H17V30.005H15z"></path><path d="M23.147 21.668H25.147V26.625999999999998H23.147z" transform="rotate(-45 24.152 24.149)"></path><path d="M25 15.005H30V17.005000000000003H25z"></path><path d="M21.668 6.854H26.625999999999998V8.854H21.668z" transform="rotate(-45 24.152 7.856)"></path><path d="M15 2.005H17V7.005H15z"></path></svg>`
},
"16": {
metadata: { "moduleName": "Sun16", "filepath": "sun/16.js", "descriptor": { "elem": "svg", "attrs": { "xmlns": "http://www.w3.org/2000/svg", "viewBox": "0 0 32 32", "fill": "currentColor", "width": 16, "height": 16 }, "content": [{ "elem": "path", "attrs": { "d": "M16,12a4,4,0,1,1-4,4,4.0045,4.0045,0,0,1,4-4m0-2a6,6,0,1,0,6,6,6,6,0,0,0-6-6Z", "transform": "translate(0 .005)" } }, { "elem": "path", "attrs": { "d": "M6.854 5.375H8.854V10.333H6.854z", "transform": "rotate(-45 7.86 7.856)" } }, { "elem": "path", "attrs": { "d": "M2 15.005H7V17.005000000000003H2z" } }, { "elem": "path", "attrs": { "d": "M5.375 23.147H10.333V25.147H5.375z", "transform": "rotate(-45 7.86 24.149)" } }, { "elem": "path", "attrs": { "d": "M15 25.005H17V30.005H15z" } }, { "elem": "path", "attrs": { "d": "M23.147 21.668H25.147V26.625999999999998H23.147z", "transform": "rotate(-45 24.152 24.149)" } }, { "elem": "path", "attrs": { "d": "M25 15.005H30V17.005000000000003H25z" } }, { "elem": "path", "attrs": { "d": "M21.668 6.854H26.625999999999998V8.854H21.668z", "transform": "rotate(-45 24.152 7.856)" } }, { "elem": "path", "attrs": { "d": "M15 2.005H17V7.005H15z" } }], "name": "sun", "size": 16 }, "size": 16 },
svg: `<svg focusable="false" preserveAspectRatio="xMidYMid meet" xmlns="http://www.w3.org/2000/svg" fill="currentColor" width="16" height="16" viewBox="0 0 32 32" aria-hidden="true"><path d="M16,12a4,4,0,1,1-4,4,4.0045,4.0045,0,0,1,4-4m0-2a6,6,0,1,0,6,6,6,6,0,0,0-6-6Z" transform="translate(0 .005)"></path><path d="M6.854 5.375H8.854V10.333H6.854z" transform="rotate(-45 7.86 7.856)"></path><path d="M2 15.005H7V17.005000000000003H2z"></path><path d="M5.375 23.147H10.333V25.147H5.375z" transform="rotate(-45 7.86 24.149)"></path><path d="M15 25.005H17V30.005H15z"></path><path d="M23.147 21.668H25.147V26.625999999999998H23.147z" transform="rotate(-45 24.152 24.149)"></path><path d="M25 15.005H30V17.005000000000003H25z"></path><path d="M21.668 6.854H26.625999999999998V8.854H21.668z" transform="rotate(-45 24.152 7.856)"></path><path d="M15 2.005H17V7.005H15z"></path></svg>`
},
};
}
ngAfterViewInit() {
const svg = this.elementRef.nativeElement;
svg.setAttribute("xmlns", "http://www.w3.org/2000/svg");
const icon = this.icons[this.size];
const domParser = new DOMParser();
const rawSVG = icon.svg;
const svgElement = domParser.parseFromString(rawSVG, "image/svg+xml").documentElement;
let node = svgElement.firstChild;
while (node) {
// importNode makes a clone of the node
// this ensures we keep looping over the nodes in the parsed document
svg.appendChild(svg.ownerDocument.importNode(node, true));
node = node.nextSibling;
}
const attributes = getAttributes({
width: icon.metadata.descriptor.attrs.height,
height: icon.metadata.descriptor.attrs.height,
viewBox: icon.metadata.descriptor.attrs.viewBox,
title: this.title,
"aria-label": this.ariaLabel,
"aria-labelledby": this.ariaLabelledby,
"aria-hidden": this.ariaHidden,
focusable: this.isFocusable.toString()
});
const attrKeys = Object.keys(attributes);
for (let i = 0; i < attrKeys.length; i++) {
const key = attrKeys[i];
const value = attributes[key];
if (key === "title") {
continue;
}
if (value) {
svg.setAttribute(key, value);
}
}
if (attributes.title) {
const title = document.createElement("title");
title.textContent = attributes.title;
SunDirective_1.titleIdCounter++;
title.setAttribute("id", `sun-${SunDirective_1.titleIdCounter}`);
svg.appendChild(title);
svg.setAttribute("aria-labelledby", `sun-${SunDirective_1.titleIdCounter}`);
}
}
};
SunDirective.titleIdCounter = 0;
SunDirective.ctorParameters = () => [
{ type: ElementRef }
];
__decorate([
Input(),
__metadata("design:type", String)
], SunDirective.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SunDirective.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], SunDirective.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SunDirective.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], SunDirective.prototype, "isFocusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SunDirective.prototype, "size", void 0);
SunDirective = SunDirective_1 = __decorate([
Directive({
selector: "[ibmIconSun]"
}),
__metadata("design:paramtypes", [ElementRef])
], SunDirective);
let SunModule = class SunModule {
};
SunModule = __decorate([
NgModule({
declarations: [
SunComponent,
SunDirective,
],
exports: [
SunComponent,
SunDirective,
]
})
], SunModule);
export { SunComponent, SunDirective, SunModule };