@carbon/icons-angular
Version:
Angular components for icons in digital and software products using the Carbon Design System
174 lines (171 loc) • 10.9 kB
JavaScript
import { __decorate, __metadata } from 'tslib';
import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core';
import { getAttributes } from '@carbon/icon-helpers';
var NotificationNewDirective_1;
let NotificationNewComponent = class NotificationNewComponent {
constructor() {
this.focusable = false;
}
};
__decorate([
Input(),
__metadata("design:type", String)
], NotificationNewComponent.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], NotificationNewComponent.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], NotificationNewComponent.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], NotificationNewComponent.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], NotificationNewComponent.prototype, "focusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], NotificationNewComponent.prototype, "innerClass", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], NotificationNewComponent.prototype, "size", void 0);
NotificationNewComponent = __decorate([
Component({
selector: "ibm-icon-notification-new",
template: `
<svg
ibmIconNotificationNew
[size]="size"
[ariaLabel]="ariaLabel"
[ariaLabelledby]="ariaLabelledby"
[ariaHidden]="ariaHidden"
[title]="title"
[isFocusable]="focusable"
[attr.class]="innerClass">
</svg>
`
})
], NotificationNewComponent);
let NotificationNewDirective = NotificationNewDirective_1 = class NotificationNewDirective {
constructor(elementRef) {
this.elementRef = elementRef;
this.isFocusable = false;
this.icons = {
"32": {
metadata: { "moduleName": "NotificationNew32", "filepath": "notification--new/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": "M26,17.6V15H24v3a.91.91,0,0,0,.3.7L27,21.4V23H5V21.4l2.7-2.7A.91.91,0,0,0,8,18V13a8,8,0,0,1,8-8,7.89,7.89,0,0,1,4,1.09V3.8A9.71,9.71,0,0,0,17,3V1H15V3A10.15,10.15,0,0,0,6,13v4.6L3.3,20.3A.91.91,0,0,0,3,21v3a.94.94,0,0,0,1,1h7a5,5,0,0,0,10,0h7a.94.94,0,0,0,1-1V21a.91.91,0,0,0-.3-.7ZM16,28a3,3,0,0,1-3-3h6A3,3,0,0,1,16,28Z" } }, { "elem": "circle", "attrs": { "cx": "26", "cy": "8", "r": "4" } }], "name": "notification--new", "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="M26,17.6V15H24v3a.91.91,0,0,0,.3.7L27,21.4V23H5V21.4l2.7-2.7A.91.91,0,0,0,8,18V13a8,8,0,0,1,8-8,7.89,7.89,0,0,1,4,1.09V3.8A9.71,9.71,0,0,0,17,3V1H15V3A10.15,10.15,0,0,0,6,13v4.6L3.3,20.3A.91.91,0,0,0,3,21v3a.94.94,0,0,0,1,1h7a5,5,0,0,0,10,0h7a.94.94,0,0,0,1-1V21a.91.91,0,0,0-.3-.7ZM16,28a3,3,0,0,1-3-3h6A3,3,0,0,1,16,28Z"></path><circle cx="26" cy="8" r="4"></circle></svg>`
},
"24": {
metadata: { "moduleName": "NotificationNew24", "filepath": "notification--new/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": "M26,17.6V15H24v3a.91.91,0,0,0,.3.7L27,21.4V23H5V21.4l2.7-2.7A.91.91,0,0,0,8,18V13a8,8,0,0,1,8-8,7.89,7.89,0,0,1,4,1.09V3.8A9.71,9.71,0,0,0,17,3V1H15V3A10.15,10.15,0,0,0,6,13v4.6L3.3,20.3A.91.91,0,0,0,3,21v3a.94.94,0,0,0,1,1h7a5,5,0,0,0,10,0h7a.94.94,0,0,0,1-1V21a.91.91,0,0,0-.3-.7ZM16,28a3,3,0,0,1-3-3h6A3,3,0,0,1,16,28Z" } }, { "elem": "circle", "attrs": { "cx": "26", "cy": "8", "r": "4" } }], "name": "notification--new", "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="M26,17.6V15H24v3a.91.91,0,0,0,.3.7L27,21.4V23H5V21.4l2.7-2.7A.91.91,0,0,0,8,18V13a8,8,0,0,1,8-8,7.89,7.89,0,0,1,4,1.09V3.8A9.71,9.71,0,0,0,17,3V1H15V3A10.15,10.15,0,0,0,6,13v4.6L3.3,20.3A.91.91,0,0,0,3,21v3a.94.94,0,0,0,1,1h7a5,5,0,0,0,10,0h7a.94.94,0,0,0,1-1V21a.91.91,0,0,0-.3-.7ZM16,28a3,3,0,0,1-3-3h6A3,3,0,0,1,16,28Z"></path><circle cx="26" cy="8" r="4"></circle></svg>`
},
"20": {
metadata: { "moduleName": "NotificationNew20", "filepath": "notification--new/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": "M26,17.6V15H24v3a.91.91,0,0,0,.3.7L27,21.4V23H5V21.4l2.7-2.7A.91.91,0,0,0,8,18V13a8,8,0,0,1,8-8,7.89,7.89,0,0,1,4,1.09V3.8A9.71,9.71,0,0,0,17,3V1H15V3A10.15,10.15,0,0,0,6,13v4.6L3.3,20.3A.91.91,0,0,0,3,21v3a.94.94,0,0,0,1,1h7a5,5,0,0,0,10,0h7a.94.94,0,0,0,1-1V21a.91.91,0,0,0-.3-.7ZM16,28a3,3,0,0,1-3-3h6A3,3,0,0,1,16,28Z" } }, { "elem": "circle", "attrs": { "cx": "26", "cy": "8", "r": "4" } }], "name": "notification--new", "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="M26,17.6V15H24v3a.91.91,0,0,0,.3.7L27,21.4V23H5V21.4l2.7-2.7A.91.91,0,0,0,8,18V13a8,8,0,0,1,8-8,7.89,7.89,0,0,1,4,1.09V3.8A9.71,9.71,0,0,0,17,3V1H15V3A10.15,10.15,0,0,0,6,13v4.6L3.3,20.3A.91.91,0,0,0,3,21v3a.94.94,0,0,0,1,1h7a5,5,0,0,0,10,0h7a.94.94,0,0,0,1-1V21a.91.91,0,0,0-.3-.7ZM16,28a3,3,0,0,1-3-3h6A3,3,0,0,1,16,28Z"></path><circle cx="26" cy="8" r="4"></circle></svg>`
},
"16": {
metadata: { "moduleName": "NotificationNew16", "filepath": "notification--new/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": "M26,17.6V15H24v3a.91.91,0,0,0,.3.7L27,21.4V23H5V21.4l2.7-2.7A.91.91,0,0,0,8,18V13a8,8,0,0,1,8-8,7.89,7.89,0,0,1,4,1.09V3.8A9.71,9.71,0,0,0,17,3V1H15V3A10.15,10.15,0,0,0,6,13v4.6L3.3,20.3A.91.91,0,0,0,3,21v3a.94.94,0,0,0,1,1h7a5,5,0,0,0,10,0h7a.94.94,0,0,0,1-1V21a.91.91,0,0,0-.3-.7ZM16,28a3,3,0,0,1-3-3h6A3,3,0,0,1,16,28Z" } }, { "elem": "circle", "attrs": { "cx": "26", "cy": "8", "r": "4" } }], "name": "notification--new", "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="M26,17.6V15H24v3a.91.91,0,0,0,.3.7L27,21.4V23H5V21.4l2.7-2.7A.91.91,0,0,0,8,18V13a8,8,0,0,1,8-8,7.89,7.89,0,0,1,4,1.09V3.8A9.71,9.71,0,0,0,17,3V1H15V3A10.15,10.15,0,0,0,6,13v4.6L3.3,20.3A.91.91,0,0,0,3,21v3a.94.94,0,0,0,1,1h7a5,5,0,0,0,10,0h7a.94.94,0,0,0,1-1V21a.91.91,0,0,0-.3-.7ZM16,28a3,3,0,0,1-3-3h6A3,3,0,0,1,16,28Z"></path><circle cx="26" cy="8" r="4"></circle></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;
NotificationNewDirective_1.titleIdCounter++;
title.setAttribute("id", `notification-new-${NotificationNewDirective_1.titleIdCounter}`);
svg.appendChild(title);
svg.setAttribute("aria-labelledby", `notification-new-${NotificationNewDirective_1.titleIdCounter}`);
}
}
};
NotificationNewDirective.titleIdCounter = 0;
NotificationNewDirective.ctorParameters = () => [
{ type: ElementRef }
];
__decorate([
Input(),
__metadata("design:type", String)
], NotificationNewDirective.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], NotificationNewDirective.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], NotificationNewDirective.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], NotificationNewDirective.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], NotificationNewDirective.prototype, "isFocusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], NotificationNewDirective.prototype, "size", void 0);
NotificationNewDirective = NotificationNewDirective_1 = __decorate([
Directive({
selector: "[ibmIconNotificationNew]"
}),
__metadata("design:paramtypes", [ElementRef])
], NotificationNewDirective);
let NotificationNewModule = class NotificationNewModule {
};
NotificationNewModule = __decorate([
NgModule({
declarations: [
NotificationNewComponent,
NotificationNewDirective,
],
exports: [
NotificationNewComponent,
NotificationNewDirective,
]
})
], NotificationNewModule);
export { NotificationNewComponent, NotificationNewDirective, NotificationNewModule };