@carbon/icons-angular
Version:
Angular components for icons in digital and software products using the Carbon Design System
174 lines (171 loc) • 8.51 kB
JavaScript
import { __decorate, __metadata } from 'tslib';
import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core';
import { getAttributes } from '@carbon/icon-helpers';
var NewTabDirective_1;
let NewTabComponent = class NewTabComponent {
constructor() {
this.focusable = false;
}
};
__decorate([
Input(),
__metadata("design:type", String)
], NewTabComponent.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], NewTabComponent.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], NewTabComponent.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], NewTabComponent.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], NewTabComponent.prototype, "focusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], NewTabComponent.prototype, "innerClass", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], NewTabComponent.prototype, "size", void 0);
NewTabComponent = __decorate([
Component({
selector: "ibm-icon-new-tab",
template: `
<svg
ibmIconNewTab
[size]="size"
[ariaLabel]="ariaLabel"
[ariaLabelledby]="ariaLabelledby"
[ariaHidden]="ariaHidden"
[title]="title"
[isFocusable]="focusable"
[attr.class]="innerClass">
</svg>
`
})
], NewTabComponent);
let NewTabDirective = NewTabDirective_1 = class NewTabDirective {
constructor(elementRef) {
this.elementRef = elementRef;
this.isFocusable = false;
this.icons = {
"32": {
metadata: { "moduleName": "NewTab32", "filepath": "new-tab/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 26H6V6h9V4H6A2 2 0 004 6V26a2 2 0 002 2H26a2 2 0 002-2V17H26zM26 6L26 2 24 2 24 6 20 6 20 8 24 8 24 12 26 12 26 8 30 8 30 6 26 6z" } }], "name": "new-tab", "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 26H6V6h9V4H6A2 2 0 004 6V26a2 2 0 002 2H26a2 2 0 002-2V17H26zM26 6L26 2 24 2 24 6 20 6 20 8 24 8 24 12 26 12 26 8 30 8 30 6 26 6z"></path></svg>`
},
"24": {
metadata: { "moduleName": "NewTab24", "filepath": "new-tab/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 26H6V6h9V4H6A2 2 0 004 6V26a2 2 0 002 2H26a2 2 0 002-2V17H26zM26 6L26 2 24 2 24 6 20 6 20 8 24 8 24 12 26 12 26 8 30 8 30 6 26 6z" } }], "name": "new-tab", "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 26H6V6h9V4H6A2 2 0 004 6V26a2 2 0 002 2H26a2 2 0 002-2V17H26zM26 6L26 2 24 2 24 6 20 6 20 8 24 8 24 12 26 12 26 8 30 8 30 6 26 6z"></path></svg>`
},
"20": {
metadata: { "moduleName": "NewTab20", "filepath": "new-tab/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 26H6V6h9V4H6A2 2 0 004 6V26a2 2 0 002 2H26a2 2 0 002-2V17H26zM26 6L26 2 24 2 24 6 20 6 20 8 24 8 24 12 26 12 26 8 30 8 30 6 26 6z" } }], "name": "new-tab", "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 26H6V6h9V4H6A2 2 0 004 6V26a2 2 0 002 2H26a2 2 0 002-2V17H26zM26 6L26 2 24 2 24 6 20 6 20 8 24 8 24 12 26 12 26 8 30 8 30 6 26 6z"></path></svg>`
},
"16": {
metadata: { "moduleName": "NewTab16", "filepath": "new-tab/16.js", "descriptor": { "elem": "svg", "attrs": { "xmlns": "http://www.w3.org/2000/svg", "viewBox": "0 0 16 16", "fill": "currentColor", "width": 16, "height": 16 }, "content": [{ "elem": "path", "attrs": { "d": "M13,13H3V3h5V2H3C2.4,2,2,2.4,2,3v10c0,0.6,0.4,1,1,1h10c0.6,0,1-0.4,1-1V8h-1V13z" } }, { "elem": "path", "attrs": { "d": "M13 3L13 1 12 1 12 3 10 3 10 4 12 4 12 6 13 6 13 4 15 4 15 3z" } }], "name": "new-tab", "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 16 16" aria-hidden="true"><path d="M13,13H3V3h5V2H3C2.4,2,2,2.4,2,3v10c0,0.6,0.4,1,1,1h10c0.6,0,1-0.4,1-1V8h-1V13z"></path><path d="M13 3L13 1 12 1 12 3 10 3 10 4 12 4 12 6 13 6 13 4 15 4 15 3z"></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;
NewTabDirective_1.titleIdCounter++;
title.setAttribute("id", `new-tab-${NewTabDirective_1.titleIdCounter}`);
svg.appendChild(title);
svg.setAttribute("aria-labelledby", `new-tab-${NewTabDirective_1.titleIdCounter}`);
}
}
};
NewTabDirective.titleIdCounter = 0;
NewTabDirective.ctorParameters = () => [
{ type: ElementRef }
];
__decorate([
Input(),
__metadata("design:type", String)
], NewTabDirective.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], NewTabDirective.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], NewTabDirective.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], NewTabDirective.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], NewTabDirective.prototype, "isFocusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], NewTabDirective.prototype, "size", void 0);
NewTabDirective = NewTabDirective_1 = __decorate([
Directive({
selector: "[ibmIconNewTab]"
}),
__metadata("design:paramtypes", [ElementRef])
], NewTabDirective);
let NewTabModule = class NewTabModule {
};
NewTabModule = __decorate([
NgModule({
declarations: [
NewTabComponent,
NewTabDirective,
],
exports: [
NewTabComponent,
NewTabDirective,
]
})
], NewTabModule);
export { NewTabComponent, NewTabDirective, NewTabModule };