@carbon/icons-angular
Version:
Angular components for icons in digital and software products using the Carbon Design System
174 lines (171 loc) • 11.9 kB
JavaScript
import { __decorate, __metadata } from 'tslib';
import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core';
import { getAttributes } from '@carbon/icon-helpers';
var TagEditDirective_1;
let TagEditComponent = class TagEditComponent {
constructor() {
this.focusable = false;
}
};
__decorate([
Input(),
__metadata("design:type", String)
], TagEditComponent.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], TagEditComponent.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], TagEditComponent.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], TagEditComponent.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], TagEditComponent.prototype, "focusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], TagEditComponent.prototype, "innerClass", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], TagEditComponent.prototype, "size", void 0);
TagEditComponent = __decorate([
Component({
selector: "ibm-icon-tag-edit",
template: `
<svg
ibmIconTagEdit
[size]="size"
[ariaLabel]="ariaLabel"
[ariaLabelledby]="ariaLabelledby"
[ariaHidden]="ariaHidden"
[title]="title"
[isFocusable]="focusable"
[attr.class]="innerClass">
</svg>
`
})
], TagEditComponent);
let TagEditDirective = TagEditDirective_1 = class TagEditDirective {
constructor(elementRef) {
this.elementRef = elementRef;
this.isFocusable = false;
this.icons = {
"32": {
metadata: { "moduleName": "TagEdit32", "filepath": "tag--edit/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": "M29.707 7.293l-3-3a.9994.9994 0 00-1.414 0L16 13.5859V18h4.4141L29.707 8.707A.9994.9994 0 0029.707 7.293zM19.5859 16H18V14.4141l5-5L24.5859 11zM26 9.5859L24.4141 8 26 6.4141 27.5859 8zM10 14a4 4 0 114-4A4.0045 4.0045 0 0110 14zm0-6a2 2 0 102 2A2.002 2.002 0 0010 8z" } }, { "elem": "path", "attrs": { "d": "M29.4155,16.5859,27.0364,14.207l-1.4141,1.4141L28,18,18,28,4,14V4H14l4.3774,4.376,1.4141-1.4141L15.4138,2.584A2.0023,2.0023,0,0,0,14,2H4A2.0034,2.0034,0,0,0,2,4V14a2.0025,2.0025,0,0,0,.5842,1.4136l14,14a2.0019,2.0019,0,0,0,2.831,0l10-9.9995A2,2,0,0,0,29.4155,16.5859Z" } }], "name": "tag--edit", "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="M29.707 7.293l-3-3a.9994.9994 0 00-1.414 0L16 13.5859V18h4.4141L29.707 8.707A.9994.9994 0 0029.707 7.293zM19.5859 16H18V14.4141l5-5L24.5859 11zM26 9.5859L24.4141 8 26 6.4141 27.5859 8zM10 14a4 4 0 114-4A4.0045 4.0045 0 0110 14zm0-6a2 2 0 102 2A2.002 2.002 0 0010 8z"></path><path d="M29.4155,16.5859,27.0364,14.207l-1.4141,1.4141L28,18,18,28,4,14V4H14l4.3774,4.376,1.4141-1.4141L15.4138,2.584A2.0023,2.0023,0,0,0,14,2H4A2.0034,2.0034,0,0,0,2,4V14a2.0025,2.0025,0,0,0,.5842,1.4136l14,14a2.0019,2.0019,0,0,0,2.831,0l10-9.9995A2,2,0,0,0,29.4155,16.5859Z"></path></svg>`
},
"24": {
metadata: { "moduleName": "TagEdit24", "filepath": "tag--edit/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": "M29.707 7.293l-3-3a.9994.9994 0 00-1.414 0L16 13.5859V18h4.4141L29.707 8.707A.9994.9994 0 0029.707 7.293zM19.5859 16H18V14.4141l5-5L24.5859 11zM26 9.5859L24.4141 8 26 6.4141 27.5859 8zM10 14a4 4 0 114-4A4.0045 4.0045 0 0110 14zm0-6a2 2 0 102 2A2.002 2.002 0 0010 8z" } }, { "elem": "path", "attrs": { "d": "M29.4155,16.5859,27.0364,14.207l-1.4141,1.4141L28,18,18,28,4,14V4H14l4.3774,4.376,1.4141-1.4141L15.4138,2.584A2.0023,2.0023,0,0,0,14,2H4A2.0034,2.0034,0,0,0,2,4V14a2.0025,2.0025,0,0,0,.5842,1.4136l14,14a2.0019,2.0019,0,0,0,2.831,0l10-9.9995A2,2,0,0,0,29.4155,16.5859Z" } }], "name": "tag--edit", "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="M29.707 7.293l-3-3a.9994.9994 0 00-1.414 0L16 13.5859V18h4.4141L29.707 8.707A.9994.9994 0 0029.707 7.293zM19.5859 16H18V14.4141l5-5L24.5859 11zM26 9.5859L24.4141 8 26 6.4141 27.5859 8zM10 14a4 4 0 114-4A4.0045 4.0045 0 0110 14zm0-6a2 2 0 102 2A2.002 2.002 0 0010 8z"></path><path d="M29.4155,16.5859,27.0364,14.207l-1.4141,1.4141L28,18,18,28,4,14V4H14l4.3774,4.376,1.4141-1.4141L15.4138,2.584A2.0023,2.0023,0,0,0,14,2H4A2.0034,2.0034,0,0,0,2,4V14a2.0025,2.0025,0,0,0,.5842,1.4136l14,14a2.0019,2.0019,0,0,0,2.831,0l10-9.9995A2,2,0,0,0,29.4155,16.5859Z"></path></svg>`
},
"20": {
metadata: { "moduleName": "TagEdit20", "filepath": "tag--edit/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": "M29.707 7.293l-3-3a.9994.9994 0 00-1.414 0L16 13.5859V18h4.4141L29.707 8.707A.9994.9994 0 0029.707 7.293zM19.5859 16H18V14.4141l5-5L24.5859 11zM26 9.5859L24.4141 8 26 6.4141 27.5859 8zM10 14a4 4 0 114-4A4.0045 4.0045 0 0110 14zm0-6a2 2 0 102 2A2.002 2.002 0 0010 8z" } }, { "elem": "path", "attrs": { "d": "M29.4155,16.5859,27.0364,14.207l-1.4141,1.4141L28,18,18,28,4,14V4H14l4.3774,4.376,1.4141-1.4141L15.4138,2.584A2.0023,2.0023,0,0,0,14,2H4A2.0034,2.0034,0,0,0,2,4V14a2.0025,2.0025,0,0,0,.5842,1.4136l14,14a2.0019,2.0019,0,0,0,2.831,0l10-9.9995A2,2,0,0,0,29.4155,16.5859Z" } }], "name": "tag--edit", "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="M29.707 7.293l-3-3a.9994.9994 0 00-1.414 0L16 13.5859V18h4.4141L29.707 8.707A.9994.9994 0 0029.707 7.293zM19.5859 16H18V14.4141l5-5L24.5859 11zM26 9.5859L24.4141 8 26 6.4141 27.5859 8zM10 14a4 4 0 114-4A4.0045 4.0045 0 0110 14zm0-6a2 2 0 102 2A2.002 2.002 0 0010 8z"></path><path d="M29.4155,16.5859,27.0364,14.207l-1.4141,1.4141L28,18,18,28,4,14V4H14l4.3774,4.376,1.4141-1.4141L15.4138,2.584A2.0023,2.0023,0,0,0,14,2H4A2.0034,2.0034,0,0,0,2,4V14a2.0025,2.0025,0,0,0,.5842,1.4136l14,14a2.0019,2.0019,0,0,0,2.831,0l10-9.9995A2,2,0,0,0,29.4155,16.5859Z"></path></svg>`
},
"16": {
metadata: { "moduleName": "TagEdit16", "filepath": "tag--edit/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": "M29.707 7.293l-3-3a.9994.9994 0 00-1.414 0L16 13.5859V18h4.4141L29.707 8.707A.9994.9994 0 0029.707 7.293zM19.5859 16H18V14.4141l5-5L24.5859 11zM26 9.5859L24.4141 8 26 6.4141 27.5859 8zM10 14a4 4 0 114-4A4.0045 4.0045 0 0110 14zm0-6a2 2 0 102 2A2.002 2.002 0 0010 8z" } }, { "elem": "path", "attrs": { "d": "M29.4155,16.5859,27.0364,14.207l-1.4141,1.4141L28,18,18,28,4,14V4H14l4.3774,4.376,1.4141-1.4141L15.4138,2.584A2.0023,2.0023,0,0,0,14,2H4A2.0034,2.0034,0,0,0,2,4V14a2.0025,2.0025,0,0,0,.5842,1.4136l14,14a2.0019,2.0019,0,0,0,2.831,0l10-9.9995A2,2,0,0,0,29.4155,16.5859Z" } }], "name": "tag--edit", "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="M29.707 7.293l-3-3a.9994.9994 0 00-1.414 0L16 13.5859V18h4.4141L29.707 8.707A.9994.9994 0 0029.707 7.293zM19.5859 16H18V14.4141l5-5L24.5859 11zM26 9.5859L24.4141 8 26 6.4141 27.5859 8zM10 14a4 4 0 114-4A4.0045 4.0045 0 0110 14zm0-6a2 2 0 102 2A2.002 2.002 0 0010 8z"></path><path d="M29.4155,16.5859,27.0364,14.207l-1.4141,1.4141L28,18,18,28,4,14V4H14l4.3774,4.376,1.4141-1.4141L15.4138,2.584A2.0023,2.0023,0,0,0,14,2H4A2.0034,2.0034,0,0,0,2,4V14a2.0025,2.0025,0,0,0,.5842,1.4136l14,14a2.0019,2.0019,0,0,0,2.831,0l10-9.9995A2,2,0,0,0,29.4155,16.5859Z"></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;
TagEditDirective_1.titleIdCounter++;
title.setAttribute("id", `tag-edit-${TagEditDirective_1.titleIdCounter}`);
svg.appendChild(title);
svg.setAttribute("aria-labelledby", `tag-edit-${TagEditDirective_1.titleIdCounter}`);
}
}
};
TagEditDirective.titleIdCounter = 0;
TagEditDirective.ctorParameters = () => [
{ type: ElementRef }
];
__decorate([
Input(),
__metadata("design:type", String)
], TagEditDirective.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], TagEditDirective.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], TagEditDirective.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], TagEditDirective.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], TagEditDirective.prototype, "isFocusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], TagEditDirective.prototype, "size", void 0);
TagEditDirective = TagEditDirective_1 = __decorate([
Directive({
selector: "[ibmIconTagEdit]"
}),
__metadata("design:paramtypes", [ElementRef])
], TagEditDirective);
let TagEditModule = class TagEditModule {
};
TagEditModule = __decorate([
NgModule({
declarations: [
TagEditComponent,
TagEditDirective,
],
exports: [
TagEditComponent,
TagEditDirective,
]
})
], TagEditModule);
export { TagEditComponent, TagEditDirective, TagEditModule };