@carbon/icons-angular
Version:
Angular components for icons in digital and software products using the Carbon Design System
174 lines (171 loc) • 12.3 kB
JavaScript
import { __decorate, __metadata } from 'tslib';
import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core';
import { getAttributes } from '@carbon/icon-helpers';
var SunsetDirective_1;
let SunsetComponent = class SunsetComponent {
constructor() {
this.focusable = false;
}
};
__decorate([
Input(),
__metadata("design:type", String)
], SunsetComponent.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SunsetComponent.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], SunsetComponent.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SunsetComponent.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], SunsetComponent.prototype, "focusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SunsetComponent.prototype, "innerClass", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SunsetComponent.prototype, "size", void 0);
SunsetComponent = __decorate([
Component({
selector: "ibm-icon-sunset",
template: `
<svg
ibmIconSunset
[size]="size"
[ariaLabel]="ariaLabel"
[ariaLabelledby]="ariaLabelledby"
[ariaHidden]="ariaHidden"
[title]="title"
[isFocusable]="focusable"
[attr.class]="innerClass">
</svg>
`
})
], SunsetComponent);
let SunsetDirective = SunsetDirective_1 = class SunsetDirective {
constructor(elementRef) {
this.elementRef = elementRef;
this.isFocusable = false;
this.icons = {
"32": {
metadata: { "moduleName": "Sunset32", "filepath": "sunset/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": "M2 27.005H29.998V29.005H2z" } }, { "elem": "path", "attrs": { "d": "M16,20a4.0045,4.0045,0,0,1,4,4h2a6,6,0,0,0-12,0h2A4.0045,4.0045,0,0,1,16,20Z", "transform": "translate(0 .005)" } }, { "elem": "path", "attrs": { "d": "M25 22.005H30V24.005H25z" } }, { "elem": "path", "attrs": { "d": "M21.668 14.854H26.625999999999998V16.854H21.668z", "transform": "rotate(-45 24.152 15.856)" } }, { "elem": "path", "attrs": { "d": "M19.59 9.595L17 12.175 17 4.005 15 4.005 15 12.175 12.41 9.595 11 11.005 16 16.005 21 11.005 19.59 9.595z" } }, { "elem": "path", "attrs": { "d": "M6.854 13.374H8.854V18.332H6.854z", "transform": "rotate(-45 7.86 15.856)" } }, { "elem": "path", "attrs": { "d": "M2 22.005H7V24.005H2z" } }], "name": "sunset", "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="M2 27.005H29.998V29.005H2z"></path><path d="M16,20a4.0045,4.0045,0,0,1,4,4h2a6,6,0,0,0-12,0h2A4.0045,4.0045,0,0,1,16,20Z" transform="translate(0 .005)"></path><path d="M25 22.005H30V24.005H25z"></path><path d="M21.668 14.854H26.625999999999998V16.854H21.668z" transform="rotate(-45 24.152 15.856)"></path><path d="M19.59 9.595L17 12.175 17 4.005 15 4.005 15 12.175 12.41 9.595 11 11.005 16 16.005 21 11.005 19.59 9.595z"></path><path d="M6.854 13.374H8.854V18.332H6.854z" transform="rotate(-45 7.86 15.856)"></path><path d="M2 22.005H7V24.005H2z"></path></svg>`
},
"24": {
metadata: { "moduleName": "Sunset24", "filepath": "sunset/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": "M2 27.005H29.998V29.005H2z" } }, { "elem": "path", "attrs": { "d": "M16,20a4.0045,4.0045,0,0,1,4,4h2a6,6,0,0,0-12,0h2A4.0045,4.0045,0,0,1,16,20Z", "transform": "translate(0 .005)" } }, { "elem": "path", "attrs": { "d": "M25 22.005H30V24.005H25z" } }, { "elem": "path", "attrs": { "d": "M21.668 14.854H26.625999999999998V16.854H21.668z", "transform": "rotate(-45 24.152 15.856)" } }, { "elem": "path", "attrs": { "d": "M19.59 9.595L17 12.175 17 4.005 15 4.005 15 12.175 12.41 9.595 11 11.005 16 16.005 21 11.005 19.59 9.595z" } }, { "elem": "path", "attrs": { "d": "M6.854 13.374H8.854V18.332H6.854z", "transform": "rotate(-45 7.86 15.856)" } }, { "elem": "path", "attrs": { "d": "M2 22.005H7V24.005H2z" } }], "name": "sunset", "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="M2 27.005H29.998V29.005H2z"></path><path d="M16,20a4.0045,4.0045,0,0,1,4,4h2a6,6,0,0,0-12,0h2A4.0045,4.0045,0,0,1,16,20Z" transform="translate(0 .005)"></path><path d="M25 22.005H30V24.005H25z"></path><path d="M21.668 14.854H26.625999999999998V16.854H21.668z" transform="rotate(-45 24.152 15.856)"></path><path d="M19.59 9.595L17 12.175 17 4.005 15 4.005 15 12.175 12.41 9.595 11 11.005 16 16.005 21 11.005 19.59 9.595z"></path><path d="M6.854 13.374H8.854V18.332H6.854z" transform="rotate(-45 7.86 15.856)"></path><path d="M2 22.005H7V24.005H2z"></path></svg>`
},
"20": {
metadata: { "moduleName": "Sunset20", "filepath": "sunset/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": "M2 27.005H29.998V29.005H2z" } }, { "elem": "path", "attrs": { "d": "M16,20a4.0045,4.0045,0,0,1,4,4h2a6,6,0,0,0-12,0h2A4.0045,4.0045,0,0,1,16,20Z", "transform": "translate(0 .005)" } }, { "elem": "path", "attrs": { "d": "M25 22.005H30V24.005H25z" } }, { "elem": "path", "attrs": { "d": "M21.668 14.854H26.625999999999998V16.854H21.668z", "transform": "rotate(-45 24.152 15.856)" } }, { "elem": "path", "attrs": { "d": "M19.59 9.595L17 12.175 17 4.005 15 4.005 15 12.175 12.41 9.595 11 11.005 16 16.005 21 11.005 19.59 9.595z" } }, { "elem": "path", "attrs": { "d": "M6.854 13.374H8.854V18.332H6.854z", "transform": "rotate(-45 7.86 15.856)" } }, { "elem": "path", "attrs": { "d": "M2 22.005H7V24.005H2z" } }], "name": "sunset", "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="M2 27.005H29.998V29.005H2z"></path><path d="M16,20a4.0045,4.0045,0,0,1,4,4h2a6,6,0,0,0-12,0h2A4.0045,4.0045,0,0,1,16,20Z" transform="translate(0 .005)"></path><path d="M25 22.005H30V24.005H25z"></path><path d="M21.668 14.854H26.625999999999998V16.854H21.668z" transform="rotate(-45 24.152 15.856)"></path><path d="M19.59 9.595L17 12.175 17 4.005 15 4.005 15 12.175 12.41 9.595 11 11.005 16 16.005 21 11.005 19.59 9.595z"></path><path d="M6.854 13.374H8.854V18.332H6.854z" transform="rotate(-45 7.86 15.856)"></path><path d="M2 22.005H7V24.005H2z"></path></svg>`
},
"16": {
metadata: { "moduleName": "Sunset16", "filepath": "sunset/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": "M2 27.005H29.998V29.005H2z" } }, { "elem": "path", "attrs": { "d": "M16,20a4.0045,4.0045,0,0,1,4,4h2a6,6,0,0,0-12,0h2A4.0045,4.0045,0,0,1,16,20Z", "transform": "translate(0 .005)" } }, { "elem": "path", "attrs": { "d": "M25 22.005H30V24.005H25z" } }, { "elem": "path", "attrs": { "d": "M21.668 14.854H26.625999999999998V16.854H21.668z", "transform": "rotate(-45 24.152 15.856)" } }, { "elem": "path", "attrs": { "d": "M19.59 9.595L17 12.175 17 4.005 15 4.005 15 12.175 12.41 9.595 11 11.005 16 16.005 21 11.005 19.59 9.595z" } }, { "elem": "path", "attrs": { "d": "M6.854 13.374H8.854V18.332H6.854z", "transform": "rotate(-45 7.86 15.856)" } }, { "elem": "path", "attrs": { "d": "M2 22.005H7V24.005H2z" } }], "name": "sunset", "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="M2 27.005H29.998V29.005H2z"></path><path d="M16,20a4.0045,4.0045,0,0,1,4,4h2a6,6,0,0,0-12,0h2A4.0045,4.0045,0,0,1,16,20Z" transform="translate(0 .005)"></path><path d="M25 22.005H30V24.005H25z"></path><path d="M21.668 14.854H26.625999999999998V16.854H21.668z" transform="rotate(-45 24.152 15.856)"></path><path d="M19.59 9.595L17 12.175 17 4.005 15 4.005 15 12.175 12.41 9.595 11 11.005 16 16.005 21 11.005 19.59 9.595z"></path><path d="M6.854 13.374H8.854V18.332H6.854z" transform="rotate(-45 7.86 15.856)"></path><path d="M2 22.005H7V24.005H2z"></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;
SunsetDirective_1.titleIdCounter++;
title.setAttribute("id", `sunset-${SunsetDirective_1.titleIdCounter}`);
svg.appendChild(title);
svg.setAttribute("aria-labelledby", `sunset-${SunsetDirective_1.titleIdCounter}`);
}
}
};
SunsetDirective.titleIdCounter = 0;
SunsetDirective.ctorParameters = () => [
{ type: ElementRef }
];
__decorate([
Input(),
__metadata("design:type", String)
], SunsetDirective.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SunsetDirective.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], SunsetDirective.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SunsetDirective.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], SunsetDirective.prototype, "isFocusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SunsetDirective.prototype, "size", void 0);
SunsetDirective = SunsetDirective_1 = __decorate([
Directive({
selector: "[ibmIconSunset]"
}),
__metadata("design:paramtypes", [ElementRef])
], SunsetDirective);
let SunsetModule = class SunsetModule {
};
SunsetModule = __decorate([
NgModule({
declarations: [
SunsetComponent,
SunsetDirective,
],
exports: [
SunsetComponent,
SunsetDirective,
]
})
], SunsetModule);
export { SunsetComponent, SunsetDirective, SunsetModule };