@carbon/icons-angular
Version:
Angular components for icons in digital and software products using the Carbon Design System
174 lines (171 loc) • 12.8 kB
JavaScript
import { __decorate, __metadata } from 'tslib';
import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core';
import { getAttributes } from '@carbon/icon-helpers';
var HailDirective_1;
let HailComponent = class HailComponent {
constructor() {
this.focusable = false;
}
};
__decorate([
Input(),
__metadata("design:type", String)
], HailComponent.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], HailComponent.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], HailComponent.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], HailComponent.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], HailComponent.prototype, "focusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], HailComponent.prototype, "innerClass", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], HailComponent.prototype, "size", void 0);
HailComponent = __decorate([
Component({
selector: "ibm-icon-hail",
template: `
<svg
ibmIconHail
[size]="size"
[ariaLabel]="ariaLabel"
[ariaLabelledby]="ariaLabelledby"
[ariaHidden]="ariaHidden"
[title]="title"
[isFocusable]="focusable"
[attr.class]="innerClass">
</svg>
`
})
], HailComponent);
let HailDirective = HailDirective_1 = class HailDirective {
constructor(elementRef) {
this.elementRef = elementRef;
this.isFocusable = false;
this.icons = {
"32": {
metadata: { "moduleName": "Hail32", "filepath": "hail/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": "circle", "attrs": { "cx": "21.5", "cy": "29.5", "r": "1.5" } }, { "elem": "circle", "attrs": { "cx": "24.5", "cy": "25.5", "r": "1.5" } }, { "elem": "circle", "attrs": { "cx": "7.5", "cy": "25.5", "r": "1.5" } }, { "elem": "circle", "attrs": { "cx": "4.5", "cy": "29.5", "r": "1.5" } }, { "elem": "circle", "attrs": { "cx": "10.499", "cy": "29.5", "r": "1.5" } }, { "elem": "path", "attrs": { "d": "M15.868 30.496L14.132 29.504 17.276 24 11.277 24 16.132 15.504 17.868 16.496 14.723 22 20.724 22 15.868 30.496z" } }, { "elem": "path", "attrs": { "d": "M23.5,22H23V20h.5a4.4975,4.4975,0,0,0,.3564-8.981l-.8154-.0639-.0986-.812a6.9938,6.9938,0,0,0-13.8838,0l-.0991.812-.8155.0639A4.4975,4.4975,0,0,0,8.5,20H9v2H8.5A6.4973,6.4973,0,0,1,7.2,9.1362a8.9943,8.9943,0,0,1,17.6006,0A6.4974,6.4974,0,0,1,23.5,22Z" } }], "name": "hail", "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"><circle cx="21.5" cy="29.5" r="1.5"></circle><circle cx="24.5" cy="25.5" r="1.5"></circle><circle cx="7.5" cy="25.5" r="1.5"></circle><circle cx="4.5" cy="29.5" r="1.5"></circle><circle cx="10.499" cy="29.5" r="1.5"></circle><path d="M15.868 30.496L14.132 29.504 17.276 24 11.277 24 16.132 15.504 17.868 16.496 14.723 22 20.724 22 15.868 30.496z"></path><path d="M23.5,22H23V20h.5a4.4975,4.4975,0,0,0,.3564-8.981l-.8154-.0639-.0986-.812a6.9938,6.9938,0,0,0-13.8838,0l-.0991.812-.8155.0639A4.4975,4.4975,0,0,0,8.5,20H9v2H8.5A6.4973,6.4973,0,0,1,7.2,9.1362a8.9943,8.9943,0,0,1,17.6006,0A6.4974,6.4974,0,0,1,23.5,22Z"></path></svg>`
},
"24": {
metadata: { "moduleName": "Hail24", "filepath": "hail/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": "circle", "attrs": { "cx": "21.5", "cy": "29.5", "r": "1.5" } }, { "elem": "circle", "attrs": { "cx": "24.5", "cy": "25.5", "r": "1.5" } }, { "elem": "circle", "attrs": { "cx": "7.5", "cy": "25.5", "r": "1.5" } }, { "elem": "circle", "attrs": { "cx": "4.5", "cy": "29.5", "r": "1.5" } }, { "elem": "circle", "attrs": { "cx": "10.499", "cy": "29.5", "r": "1.5" } }, { "elem": "path", "attrs": { "d": "M15.868 30.496L14.132 29.504 17.276 24 11.277 24 16.132 15.504 17.868 16.496 14.723 22 20.724 22 15.868 30.496z" } }, { "elem": "path", "attrs": { "d": "M23.5,22H23V20h.5a4.4975,4.4975,0,0,0,.3564-8.981l-.8154-.0639-.0986-.812a6.9938,6.9938,0,0,0-13.8838,0l-.0991.812-.8155.0639A4.4975,4.4975,0,0,0,8.5,20H9v2H8.5A6.4973,6.4973,0,0,1,7.2,9.1362a8.9943,8.9943,0,0,1,17.6006,0A6.4974,6.4974,0,0,1,23.5,22Z" } }], "name": "hail", "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"><circle cx="21.5" cy="29.5" r="1.5"></circle><circle cx="24.5" cy="25.5" r="1.5"></circle><circle cx="7.5" cy="25.5" r="1.5"></circle><circle cx="4.5" cy="29.5" r="1.5"></circle><circle cx="10.499" cy="29.5" r="1.5"></circle><path d="M15.868 30.496L14.132 29.504 17.276 24 11.277 24 16.132 15.504 17.868 16.496 14.723 22 20.724 22 15.868 30.496z"></path><path d="M23.5,22H23V20h.5a4.4975,4.4975,0,0,0,.3564-8.981l-.8154-.0639-.0986-.812a6.9938,6.9938,0,0,0-13.8838,0l-.0991.812-.8155.0639A4.4975,4.4975,0,0,0,8.5,20H9v2H8.5A6.4973,6.4973,0,0,1,7.2,9.1362a8.9943,8.9943,0,0,1,17.6006,0A6.4974,6.4974,0,0,1,23.5,22Z"></path></svg>`
},
"20": {
metadata: { "moduleName": "Hail20", "filepath": "hail/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": "circle", "attrs": { "cx": "21.5", "cy": "29.5", "r": "1.5" } }, { "elem": "circle", "attrs": { "cx": "24.5", "cy": "25.5", "r": "1.5" } }, { "elem": "circle", "attrs": { "cx": "7.5", "cy": "25.5", "r": "1.5" } }, { "elem": "circle", "attrs": { "cx": "4.5", "cy": "29.5", "r": "1.5" } }, { "elem": "circle", "attrs": { "cx": "10.499", "cy": "29.5", "r": "1.5" } }, { "elem": "path", "attrs": { "d": "M15.868 30.496L14.132 29.504 17.276 24 11.277 24 16.132 15.504 17.868 16.496 14.723 22 20.724 22 15.868 30.496z" } }, { "elem": "path", "attrs": { "d": "M23.5,22H23V20h.5a4.4975,4.4975,0,0,0,.3564-8.981l-.8154-.0639-.0986-.812a6.9938,6.9938,0,0,0-13.8838,0l-.0991.812-.8155.0639A4.4975,4.4975,0,0,0,8.5,20H9v2H8.5A6.4973,6.4973,0,0,1,7.2,9.1362a8.9943,8.9943,0,0,1,17.6006,0A6.4974,6.4974,0,0,1,23.5,22Z" } }], "name": "hail", "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"><circle cx="21.5" cy="29.5" r="1.5"></circle><circle cx="24.5" cy="25.5" r="1.5"></circle><circle cx="7.5" cy="25.5" r="1.5"></circle><circle cx="4.5" cy="29.5" r="1.5"></circle><circle cx="10.499" cy="29.5" r="1.5"></circle><path d="M15.868 30.496L14.132 29.504 17.276 24 11.277 24 16.132 15.504 17.868 16.496 14.723 22 20.724 22 15.868 30.496z"></path><path d="M23.5,22H23V20h.5a4.4975,4.4975,0,0,0,.3564-8.981l-.8154-.0639-.0986-.812a6.9938,6.9938,0,0,0-13.8838,0l-.0991.812-.8155.0639A4.4975,4.4975,0,0,0,8.5,20H9v2H8.5A6.4973,6.4973,0,0,1,7.2,9.1362a8.9943,8.9943,0,0,1,17.6006,0A6.4974,6.4974,0,0,1,23.5,22Z"></path></svg>`
},
"16": {
metadata: { "moduleName": "Hail16", "filepath": "hail/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": "circle", "attrs": { "cx": "21.5", "cy": "29.5", "r": "1.5" } }, { "elem": "circle", "attrs": { "cx": "24.5", "cy": "25.5", "r": "1.5" } }, { "elem": "circle", "attrs": { "cx": "7.5", "cy": "25.5", "r": "1.5" } }, { "elem": "circle", "attrs": { "cx": "4.5", "cy": "29.5", "r": "1.5" } }, { "elem": "circle", "attrs": { "cx": "10.499", "cy": "29.5", "r": "1.5" } }, { "elem": "path", "attrs": { "d": "M15.868 30.496L14.132 29.504 17.276 24 11.277 24 16.132 15.504 17.868 16.496 14.723 22 20.724 22 15.868 30.496z" } }, { "elem": "path", "attrs": { "d": "M23.5,22H23V20h.5a4.4975,4.4975,0,0,0,.3564-8.981l-.8154-.0639-.0986-.812a6.9938,6.9938,0,0,0-13.8838,0l-.0991.812-.8155.0639A4.4975,4.4975,0,0,0,8.5,20H9v2H8.5A6.4973,6.4973,0,0,1,7.2,9.1362a8.9943,8.9943,0,0,1,17.6006,0A6.4974,6.4974,0,0,1,23.5,22Z" } }], "name": "hail", "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"><circle cx="21.5" cy="29.5" r="1.5"></circle><circle cx="24.5" cy="25.5" r="1.5"></circle><circle cx="7.5" cy="25.5" r="1.5"></circle><circle cx="4.5" cy="29.5" r="1.5"></circle><circle cx="10.499" cy="29.5" r="1.5"></circle><path d="M15.868 30.496L14.132 29.504 17.276 24 11.277 24 16.132 15.504 17.868 16.496 14.723 22 20.724 22 15.868 30.496z"></path><path d="M23.5,22H23V20h.5a4.4975,4.4975,0,0,0,.3564-8.981l-.8154-.0639-.0986-.812a6.9938,6.9938,0,0,0-13.8838,0l-.0991.812-.8155.0639A4.4975,4.4975,0,0,0,8.5,20H9v2H8.5A6.4973,6.4973,0,0,1,7.2,9.1362a8.9943,8.9943,0,0,1,17.6006,0A6.4974,6.4974,0,0,1,23.5,22Z"></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;
HailDirective_1.titleIdCounter++;
title.setAttribute("id", `hail-${HailDirective_1.titleIdCounter}`);
svg.appendChild(title);
svg.setAttribute("aria-labelledby", `hail-${HailDirective_1.titleIdCounter}`);
}
}
};
HailDirective.titleIdCounter = 0;
HailDirective.ctorParameters = () => [
{ type: ElementRef }
];
__decorate([
Input(),
__metadata("design:type", String)
], HailDirective.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], HailDirective.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], HailDirective.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], HailDirective.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], HailDirective.prototype, "isFocusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], HailDirective.prototype, "size", void 0);
HailDirective = HailDirective_1 = __decorate([
Directive({
selector: "[ibmIconHail]"
}),
__metadata("design:paramtypes", [ElementRef])
], HailDirective);
let HailModule = class HailModule {
};
HailModule = __decorate([
NgModule({
declarations: [
HailComponent,
HailDirective,
],
exports: [
HailComponent,
HailDirective,
]
})
], HailModule);
export { HailComponent, HailDirective, HailModule };