@carbon/icons-angular
Version:
Angular components for icons in digital and software products using the Carbon Design System
174 lines (171 loc) • 12 kB
JavaScript
import { __decorate, __metadata } from 'tslib';
import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core';
import { getAttributes } from '@carbon/icon-helpers';
var JsonReferenceDirective_1;
let JsonReferenceComponent = class JsonReferenceComponent {
constructor() {
this.focusable = false;
}
};
__decorate([
Input(),
__metadata("design:type", String)
], JsonReferenceComponent.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], JsonReferenceComponent.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], JsonReferenceComponent.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], JsonReferenceComponent.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], JsonReferenceComponent.prototype, "focusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], JsonReferenceComponent.prototype, "innerClass", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], JsonReferenceComponent.prototype, "size", void 0);
JsonReferenceComponent = __decorate([
Component({
selector: "ibm-icon-json-reference",
template: `
<svg
ibmIconJsonReference
[size]="size"
[ariaLabel]="ariaLabel"
[ariaLabelledby]="ariaLabelledby"
[ariaHidden]="ariaHidden"
[title]="title"
[isFocusable]="focusable"
[attr.class]="innerClass">
</svg>
`
})
], JsonReferenceComponent);
let JsonReferenceDirective = JsonReferenceDirective_1 = class JsonReferenceDirective {
constructor(elementRef) {
this.elementRef = elementRef;
this.isFocusable = false;
this.icons = {
"32": {
metadata: { "moduleName": "JsonReference32", "filepath": "JSON--reference/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": "M4 20L4 22 8.586 22 2 28.586 3.414 30 10 23.414 10 28 12 28 12 20 4 20zM29 12L27 6 25 6 25 16 27 16 27 10 29 16 31 16 31 6 29 6 29 12zM21.3335 6h-2.667A1.6683 1.6683 0 0017 7.6665v6.667A1.6684 1.6684 0 0018.6665 16h2.667A1.6683 1.6683 0 0023 14.3335V7.6665A1.6683 1.6683 0 0021.3335 6zM21 14H19V8h2zM9 7.6665V10a2.002 2.002 0 002 2h2v2H9v2h4.3335A1.6683 1.6683 0 0015 14.3335V12a2.002 2.002 0 00-2-2H11V8h4V6H10.6665A1.6683 1.6683 0 009 7.6665zM5 14H3V12H1v2.3335A1.6684 1.6684 0 002.6665 16h2.667A1.6683 1.6683 0 007 14.3335V6H5z" } }], "name": "JSON--reference", "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="M4 20L4 22 8.586 22 2 28.586 3.414 30 10 23.414 10 28 12 28 12 20 4 20zM29 12L27 6 25 6 25 16 27 16 27 10 29 16 31 16 31 6 29 6 29 12zM21.3335 6h-2.667A1.6683 1.6683 0 0017 7.6665v6.667A1.6684 1.6684 0 0018.6665 16h2.667A1.6683 1.6683 0 0023 14.3335V7.6665A1.6683 1.6683 0 0021.3335 6zM21 14H19V8h2zM9 7.6665V10a2.002 2.002 0 002 2h2v2H9v2h4.3335A1.6683 1.6683 0 0015 14.3335V12a2.002 2.002 0 00-2-2H11V8h4V6H10.6665A1.6683 1.6683 0 009 7.6665zM5 14H3V12H1v2.3335A1.6684 1.6684 0 002.6665 16h2.667A1.6683 1.6683 0 007 14.3335V6H5z"></path></svg>`
},
"24": {
metadata: { "moduleName": "JsonReference24", "filepath": "JSON--reference/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": "M4 20L4 22 8.586 22 2 28.586 3.414 30 10 23.414 10 28 12 28 12 20 4 20zM29 12L27 6 25 6 25 16 27 16 27 10 29 16 31 16 31 6 29 6 29 12zM21.3335 6h-2.667A1.6683 1.6683 0 0017 7.6665v6.667A1.6684 1.6684 0 0018.6665 16h2.667A1.6683 1.6683 0 0023 14.3335V7.6665A1.6683 1.6683 0 0021.3335 6zM21 14H19V8h2zM9 7.6665V10a2.002 2.002 0 002 2h2v2H9v2h4.3335A1.6683 1.6683 0 0015 14.3335V12a2.002 2.002 0 00-2-2H11V8h4V6H10.6665A1.6683 1.6683 0 009 7.6665zM5 14H3V12H1v2.3335A1.6684 1.6684 0 002.6665 16h2.667A1.6683 1.6683 0 007 14.3335V6H5z" } }], "name": "JSON--reference", "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="M4 20L4 22 8.586 22 2 28.586 3.414 30 10 23.414 10 28 12 28 12 20 4 20zM29 12L27 6 25 6 25 16 27 16 27 10 29 16 31 16 31 6 29 6 29 12zM21.3335 6h-2.667A1.6683 1.6683 0 0017 7.6665v6.667A1.6684 1.6684 0 0018.6665 16h2.667A1.6683 1.6683 0 0023 14.3335V7.6665A1.6683 1.6683 0 0021.3335 6zM21 14H19V8h2zM9 7.6665V10a2.002 2.002 0 002 2h2v2H9v2h4.3335A1.6683 1.6683 0 0015 14.3335V12a2.002 2.002 0 00-2-2H11V8h4V6H10.6665A1.6683 1.6683 0 009 7.6665zM5 14H3V12H1v2.3335A1.6684 1.6684 0 002.6665 16h2.667A1.6683 1.6683 0 007 14.3335V6H5z"></path></svg>`
},
"20": {
metadata: { "moduleName": "JsonReference20", "filepath": "JSON--reference/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": "M4 20L4 22 8.586 22 2 28.586 3.414 30 10 23.414 10 28 12 28 12 20 4 20zM29 12L27 6 25 6 25 16 27 16 27 10 29 16 31 16 31 6 29 6 29 12zM21.3335 6h-2.667A1.6683 1.6683 0 0017 7.6665v6.667A1.6684 1.6684 0 0018.6665 16h2.667A1.6683 1.6683 0 0023 14.3335V7.6665A1.6683 1.6683 0 0021.3335 6zM21 14H19V8h2zM9 7.6665V10a2.002 2.002 0 002 2h2v2H9v2h4.3335A1.6683 1.6683 0 0015 14.3335V12a2.002 2.002 0 00-2-2H11V8h4V6H10.6665A1.6683 1.6683 0 009 7.6665zM5 14H3V12H1v2.3335A1.6684 1.6684 0 002.6665 16h2.667A1.6683 1.6683 0 007 14.3335V6H5z" } }], "name": "JSON--reference", "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="M4 20L4 22 8.586 22 2 28.586 3.414 30 10 23.414 10 28 12 28 12 20 4 20zM29 12L27 6 25 6 25 16 27 16 27 10 29 16 31 16 31 6 29 6 29 12zM21.3335 6h-2.667A1.6683 1.6683 0 0017 7.6665v6.667A1.6684 1.6684 0 0018.6665 16h2.667A1.6683 1.6683 0 0023 14.3335V7.6665A1.6683 1.6683 0 0021.3335 6zM21 14H19V8h2zM9 7.6665V10a2.002 2.002 0 002 2h2v2H9v2h4.3335A1.6683 1.6683 0 0015 14.3335V12a2.002 2.002 0 00-2-2H11V8h4V6H10.6665A1.6683 1.6683 0 009 7.6665zM5 14H3V12H1v2.3335A1.6684 1.6684 0 002.6665 16h2.667A1.6683 1.6683 0 007 14.3335V6H5z"></path></svg>`
},
"16": {
metadata: { "moduleName": "JsonReference16", "filepath": "JSON--reference/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": "M4 20L4 22 8.586 22 2 28.586 3.414 30 10 23.414 10 28 12 28 12 20 4 20zM29 12L27 6 25 6 25 16 27 16 27 10 29 16 31 16 31 6 29 6 29 12zM21.3335 6h-2.667A1.6683 1.6683 0 0017 7.6665v6.667A1.6684 1.6684 0 0018.6665 16h2.667A1.6683 1.6683 0 0023 14.3335V7.6665A1.6683 1.6683 0 0021.3335 6zM21 14H19V8h2zM9 7.6665V10a2.002 2.002 0 002 2h2v2H9v2h4.3335A1.6683 1.6683 0 0015 14.3335V12a2.002 2.002 0 00-2-2H11V8h4V6H10.6665A1.6683 1.6683 0 009 7.6665zM5 14H3V12H1v2.3335A1.6684 1.6684 0 002.6665 16h2.667A1.6683 1.6683 0 007 14.3335V6H5z" } }], "name": "JSON--reference", "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="M4 20L4 22 8.586 22 2 28.586 3.414 30 10 23.414 10 28 12 28 12 20 4 20zM29 12L27 6 25 6 25 16 27 16 27 10 29 16 31 16 31 6 29 6 29 12zM21.3335 6h-2.667A1.6683 1.6683 0 0017 7.6665v6.667A1.6684 1.6684 0 0018.6665 16h2.667A1.6683 1.6683 0 0023 14.3335V7.6665A1.6683 1.6683 0 0021.3335 6zM21 14H19V8h2zM9 7.6665V10a2.002 2.002 0 002 2h2v2H9v2h4.3335A1.6683 1.6683 0 0015 14.3335V12a2.002 2.002 0 00-2-2H11V8h4V6H10.6665A1.6683 1.6683 0 009 7.6665zM5 14H3V12H1v2.3335A1.6684 1.6684 0 002.6665 16h2.667A1.6683 1.6683 0 007 14.3335V6H5z"></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;
JsonReferenceDirective_1.titleIdCounter++;
title.setAttribute("id", `json-reference-${JsonReferenceDirective_1.titleIdCounter}`);
svg.appendChild(title);
svg.setAttribute("aria-labelledby", `json-reference-${JsonReferenceDirective_1.titleIdCounter}`);
}
}
};
JsonReferenceDirective.titleIdCounter = 0;
JsonReferenceDirective.ctorParameters = () => [
{ type: ElementRef }
];
__decorate([
Input(),
__metadata("design:type", String)
], JsonReferenceDirective.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], JsonReferenceDirective.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], JsonReferenceDirective.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], JsonReferenceDirective.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], JsonReferenceDirective.prototype, "isFocusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], JsonReferenceDirective.prototype, "size", void 0);
JsonReferenceDirective = JsonReferenceDirective_1 = __decorate([
Directive({
selector: "[ibmIconJsonReference]"
}),
__metadata("design:paramtypes", [ElementRef])
], JsonReferenceDirective);
let JsonReferenceModule = class JsonReferenceModule {
};
JsonReferenceModule = __decorate([
NgModule({
declarations: [
JsonReferenceComponent,
JsonReferenceDirective,
],
exports: [
JsonReferenceComponent,
JsonReferenceDirective,
]
})
], JsonReferenceModule);
export { JsonReferenceComponent, JsonReferenceDirective, JsonReferenceModule };