@carbon/icons-angular
Version:
Angular components for icons in digital and software products using the Carbon Design System
169 lines (166 loc) • 9.37 kB
JavaScript
import { __decorate, __metadata } from 'tslib';
import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core';
import { getAttributes } from '@carbon/icon-helpers';
var LaunchComponent = /** @class */ (function () {
function LaunchComponent() {
this.focusable = false;
}
__decorate([
Input(),
__metadata("design:type", String)
], LaunchComponent.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], LaunchComponent.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], LaunchComponent.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], LaunchComponent.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], LaunchComponent.prototype, "focusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], LaunchComponent.prototype, "innerClass", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], LaunchComponent.prototype, "size", void 0);
LaunchComponent = __decorate([
Component({
selector: "ibm-icon-launch",
template: "\n <svg\n ibmIconLaunch\n [size]=\"size\"\n [ariaLabel]=\"ariaLabel\"\n [ariaLabelledby]=\"ariaLabelledby\"\n [ariaHidden]=\"ariaHidden\"\n [title]=\"title\"\n [isFocusable]=\"focusable\"\n [attr.class]=\"innerClass\">\n </svg>\n "
})
], LaunchComponent);
return LaunchComponent;
}());
var LaunchDirective = /** @class */ (function () {
function LaunchDirective(elementRef) {
this.elementRef = elementRef;
this.isFocusable = false;
this.icons = {
"32": {
metadata: { "moduleName": "Launch32", "filepath": "launch/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,28H6a2,2,0,0,1-2-2V6A2,2,0,0,1,6,4h9V6H6V26H26V17h2v9A2,2,0,0,1,26,28Z" } }, { "elem": "path", "attrs": { "d": "M21 2L21 4 26.59 4 18 12.59 19.41 14 28 5.41 28 11 30 11 30 2 21 2z" } }], "name": "launch", "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,28H6a2,2,0,0,1-2-2V6A2,2,0,0,1,6,4h9V6H6V26H26V17h2v9A2,2,0,0,1,26,28Z\"></path><path d=\"M21 2L21 4 26.59 4 18 12.59 19.41 14 28 5.41 28 11 30 11 30 2 21 2z\"></path></svg>"
},
"24": {
metadata: { "moduleName": "Launch24", "filepath": "launch/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,28H6a2,2,0,0,1-2-2V6A2,2,0,0,1,6,4h9V6H6V26H26V17h2v9A2,2,0,0,1,26,28Z" } }, { "elem": "path", "attrs": { "d": "M21 2L21 4 26.59 4 18 12.59 19.41 14 28 5.41 28 11 30 11 30 2 21 2z" } }], "name": "launch", "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,28H6a2,2,0,0,1-2-2V6A2,2,0,0,1,6,4h9V6H6V26H26V17h2v9A2,2,0,0,1,26,28Z\"></path><path d=\"M21 2L21 4 26.59 4 18 12.59 19.41 14 28 5.41 28 11 30 11 30 2 21 2z\"></path></svg>"
},
"20": {
metadata: { "moduleName": "Launch20", "filepath": "launch/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,28H6a2,2,0,0,1-2-2V6A2,2,0,0,1,6,4h9V6H6V26H26V17h2v9A2,2,0,0,1,26,28Z" } }, { "elem": "path", "attrs": { "d": "M21 2L21 4 26.59 4 18 12.59 19.41 14 28 5.41 28 11 30 11 30 2 21 2z" } }], "name": "launch", "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,28H6a2,2,0,0,1-2-2V6A2,2,0,0,1,6,4h9V6H6V26H26V17h2v9A2,2,0,0,1,26,28Z\"></path><path d=\"M21 2L21 4 26.59 4 18 12.59 19.41 14 28 5.41 28 11 30 11 30 2 21 2z\"></path></svg>"
},
"16": {
metadata: { "moduleName": "Launch16", "filepath": "launch/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,14H3c-0.6,0-1-0.4-1-1V3c0-0.6,0.4-1,1-1h5v1H3v10h10V8h1v5C14,13.6,13.6,14,13,14z" } }, { "elem": "path", "attrs": { "d": "M10 1L10 2 13.3 2 9 6.3 9.7 7 14 2.7 14 6 15 6 15 1z" } }], "name": "launch", "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,14H3c-0.6,0-1-0.4-1-1V3c0-0.6,0.4-1,1-1h5v1H3v10h10V8h1v5C14,13.6,13.6,14,13,14z\"></path><path d=\"M10 1L10 2 13.3 2 9 6.3 9.7 7 14 2.7 14 6 15 6 15 1z\"></path></svg>"
},
};
}
LaunchDirective_1 = LaunchDirective;
LaunchDirective.prototype.ngAfterViewInit = function () {
var svg = this.elementRef.nativeElement;
svg.setAttribute("xmlns", "http://www.w3.org/2000/svg");
var icon = this.icons[this.size];
var domParser = new DOMParser();
var rawSVG = icon.svg;
var svgElement = domParser.parseFromString(rawSVG, "image/svg+xml").documentElement;
var 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;
}
var 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()
});
var attrKeys = Object.keys(attributes);
for (var i = 0; i < attrKeys.length; i++) {
var key = attrKeys[i];
var value = attributes[key];
if (key === "title") {
continue;
}
if (value) {
svg.setAttribute(key, value);
}
}
if (attributes.title) {
var title = document.createElement("title");
title.textContent = attributes.title;
LaunchDirective_1.titleIdCounter++;
title.setAttribute("id", "launch-" + LaunchDirective_1.titleIdCounter);
svg.appendChild(title);
svg.setAttribute("aria-labelledby", "launch-" + LaunchDirective_1.titleIdCounter);
}
};
var LaunchDirective_1;
LaunchDirective.titleIdCounter = 0;
LaunchDirective.ctorParameters = function () { return [
{ type: ElementRef }
]; };
__decorate([
Input(),
__metadata("design:type", String)
], LaunchDirective.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], LaunchDirective.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], LaunchDirective.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], LaunchDirective.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], LaunchDirective.prototype, "isFocusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], LaunchDirective.prototype, "size", void 0);
LaunchDirective = LaunchDirective_1 = __decorate([
Directive({
selector: "[ibmIconLaunch]"
}),
__metadata("design:paramtypes", [ElementRef])
], LaunchDirective);
return LaunchDirective;
}());
var LaunchModule = /** @class */ (function () {
function LaunchModule() {
}
LaunchModule = __decorate([
NgModule({
declarations: [
LaunchComponent,
LaunchDirective,
],
exports: [
LaunchComponent,
LaunchDirective,
]
})
], LaunchModule);
return LaunchModule;
}());
export { LaunchComponent, LaunchDirective, LaunchModule };