@carbon/icons-angular
Version:
Angular components for icons in digital and software products using the Carbon Design System
174 lines (171 loc) • 10.7 kB
JavaScript
import { __decorate, __metadata } from 'tslib';
import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core';
import { getAttributes } from '@carbon/icon-helpers';
var CarDirective_1;
let CarComponent = class CarComponent {
constructor() {
this.focusable = false;
}
};
__decorate([
Input(),
__metadata("design:type", String)
], CarComponent.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], CarComponent.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], CarComponent.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], CarComponent.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], CarComponent.prototype, "focusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], CarComponent.prototype, "innerClass", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], CarComponent.prototype, "size", void 0);
CarComponent = __decorate([
Component({
selector: "ibm-icon-car",
template: `
<svg
ibmIconCar
[size]="size"
[ariaLabel]="ariaLabel"
[ariaLabelledby]="ariaLabelledby"
[ariaHidden]="ariaHidden"
[title]="title"
[isFocusable]="focusable"
[attr.class]="innerClass">
</svg>
`
})
], CarComponent);
let CarDirective = CarDirective_1 = class CarDirective {
constructor(elementRef) {
this.elementRef = elementRef;
this.isFocusable = false;
this.icons = {
"32": {
metadata: { "moduleName": "Car32", "filepath": "car/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.34,15.94l-7.73-2.78L18.37,9.1A3,3,0,0,0,16.05,8h-8A3,3,0,0,0,5.58,9.32l-2.71,4A5,5,0,0,0,2,16.11V24a1,1,0,0,0,1,1H5.14a4,4,0,0,0,7.72,0h6.28a4,4,0,0,0,7.72,0H29a1,1,0,0,0,1-1V16.88A1,1,0,0,0,29.34,15.94ZM9,26a2,2,0,1,1,2-2A2,2,0,0,1,9,26Zm14,0a2,2,0,1,1,2-2A2,2,0,0,1,23,26Zm5-3H26.86a4,4,0,0,0-7.72,0H12.86a4,4,0,0,0-7.72,0H4V16.11a3,3,0,0,1,.52-1.69l2.71-4A1,1,0,0,1,8.06,10h8a1,1,0,0,1,.77.36l3.4,4.27a1.09,1.09,0,0,0,.44.32L28,17.58Z" } }], "name": "car", "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.34,15.94l-7.73-2.78L18.37,9.1A3,3,0,0,0,16.05,8h-8A3,3,0,0,0,5.58,9.32l-2.71,4A5,5,0,0,0,2,16.11V24a1,1,0,0,0,1,1H5.14a4,4,0,0,0,7.72,0h6.28a4,4,0,0,0,7.72,0H29a1,1,0,0,0,1-1V16.88A1,1,0,0,0,29.34,15.94ZM9,26a2,2,0,1,1,2-2A2,2,0,0,1,9,26Zm14,0a2,2,0,1,1,2-2A2,2,0,0,1,23,26Zm5-3H26.86a4,4,0,0,0-7.72,0H12.86a4,4,0,0,0-7.72,0H4V16.11a3,3,0,0,1,.52-1.69l2.71-4A1,1,0,0,1,8.06,10h8a1,1,0,0,1,.77.36l3.4,4.27a1.09,1.09,0,0,0,.44.32L28,17.58Z"></path></svg>`
},
"24": {
metadata: { "moduleName": "Car24", "filepath": "car/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.34,15.94l-7.73-2.78L18.37,9.1A3,3,0,0,0,16.05,8h-8A3,3,0,0,0,5.58,9.32l-2.71,4A5,5,0,0,0,2,16.11V24a1,1,0,0,0,1,1H5.14a4,4,0,0,0,7.72,0h6.28a4,4,0,0,0,7.72,0H29a1,1,0,0,0,1-1V16.88A1,1,0,0,0,29.34,15.94ZM9,26a2,2,0,1,1,2-2A2,2,0,0,1,9,26Zm14,0a2,2,0,1,1,2-2A2,2,0,0,1,23,26Zm5-3H26.86a4,4,0,0,0-7.72,0H12.86a4,4,0,0,0-7.72,0H4V16.11a3,3,0,0,1,.52-1.69l2.71-4A1,1,0,0,1,8.06,10h8a1,1,0,0,1,.77.36l3.4,4.27a1.09,1.09,0,0,0,.44.32L28,17.58Z" } }], "name": "car", "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.34,15.94l-7.73-2.78L18.37,9.1A3,3,0,0,0,16.05,8h-8A3,3,0,0,0,5.58,9.32l-2.71,4A5,5,0,0,0,2,16.11V24a1,1,0,0,0,1,1H5.14a4,4,0,0,0,7.72,0h6.28a4,4,0,0,0,7.72,0H29a1,1,0,0,0,1-1V16.88A1,1,0,0,0,29.34,15.94ZM9,26a2,2,0,1,1,2-2A2,2,0,0,1,9,26Zm14,0a2,2,0,1,1,2-2A2,2,0,0,1,23,26Zm5-3H26.86a4,4,0,0,0-7.72,0H12.86a4,4,0,0,0-7.72,0H4V16.11a3,3,0,0,1,.52-1.69l2.71-4A1,1,0,0,1,8.06,10h8a1,1,0,0,1,.77.36l3.4,4.27a1.09,1.09,0,0,0,.44.32L28,17.58Z"></path></svg>`
},
"20": {
metadata: { "moduleName": "Car20", "filepath": "car/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.34,15.94l-7.73-2.78L18.37,9.1A3,3,0,0,0,16.05,8h-8A3,3,0,0,0,5.58,9.32l-2.71,4A5,5,0,0,0,2,16.11V24a1,1,0,0,0,1,1H5.14a4,4,0,0,0,7.72,0h6.28a4,4,0,0,0,7.72,0H29a1,1,0,0,0,1-1V16.88A1,1,0,0,0,29.34,15.94ZM9,26a2,2,0,1,1,2-2A2,2,0,0,1,9,26Zm14,0a2,2,0,1,1,2-2A2,2,0,0,1,23,26Zm5-3H26.86a4,4,0,0,0-7.72,0H12.86a4,4,0,0,0-7.72,0H4V16.11a3,3,0,0,1,.52-1.69l2.71-4A1,1,0,0,1,8.06,10h8a1,1,0,0,1,.77.36l3.4,4.27a1.09,1.09,0,0,0,.44.32L28,17.58Z" } }], "name": "car", "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.34,15.94l-7.73-2.78L18.37,9.1A3,3,0,0,0,16.05,8h-8A3,3,0,0,0,5.58,9.32l-2.71,4A5,5,0,0,0,2,16.11V24a1,1,0,0,0,1,1H5.14a4,4,0,0,0,7.72,0h6.28a4,4,0,0,0,7.72,0H29a1,1,0,0,0,1-1V16.88A1,1,0,0,0,29.34,15.94ZM9,26a2,2,0,1,1,2-2A2,2,0,0,1,9,26Zm14,0a2,2,0,1,1,2-2A2,2,0,0,1,23,26Zm5-3H26.86a4,4,0,0,0-7.72,0H12.86a4,4,0,0,0-7.72,0H4V16.11a3,3,0,0,1,.52-1.69l2.71-4A1,1,0,0,1,8.06,10h8a1,1,0,0,1,.77.36l3.4,4.27a1.09,1.09,0,0,0,.44.32L28,17.58Z"></path></svg>`
},
"16": {
metadata: { "moduleName": "Car16", "filepath": "car/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.34,15.94l-7.73-2.78L18.37,9.1A3,3,0,0,0,16.05,8h-8A3,3,0,0,0,5.58,9.32l-2.71,4A5,5,0,0,0,2,16.11V24a1,1,0,0,0,1,1H5.14a4,4,0,0,0,7.72,0h6.28a4,4,0,0,0,7.72,0H29a1,1,0,0,0,1-1V16.88A1,1,0,0,0,29.34,15.94ZM9,26a2,2,0,1,1,2-2A2,2,0,0,1,9,26Zm14,0a2,2,0,1,1,2-2A2,2,0,0,1,23,26Zm5-3H26.86a4,4,0,0,0-7.72,0H12.86a4,4,0,0,0-7.72,0H4V16.11a3,3,0,0,1,.52-1.69l2.71-4A1,1,0,0,1,8.06,10h8a1,1,0,0,1,.77.36l3.4,4.27a1.09,1.09,0,0,0,.44.32L28,17.58Z" } }], "name": "car", "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.34,15.94l-7.73-2.78L18.37,9.1A3,3,0,0,0,16.05,8h-8A3,3,0,0,0,5.58,9.32l-2.71,4A5,5,0,0,0,2,16.11V24a1,1,0,0,0,1,1H5.14a4,4,0,0,0,7.72,0h6.28a4,4,0,0,0,7.72,0H29a1,1,0,0,0,1-1V16.88A1,1,0,0,0,29.34,15.94ZM9,26a2,2,0,1,1,2-2A2,2,0,0,1,9,26Zm14,0a2,2,0,1,1,2-2A2,2,0,0,1,23,26Zm5-3H26.86a4,4,0,0,0-7.72,0H12.86a4,4,0,0,0-7.72,0H4V16.11a3,3,0,0,1,.52-1.69l2.71-4A1,1,0,0,1,8.06,10h8a1,1,0,0,1,.77.36l3.4,4.27a1.09,1.09,0,0,0,.44.32L28,17.58Z"></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;
CarDirective_1.titleIdCounter++;
title.setAttribute("id", `car-${CarDirective_1.titleIdCounter}`);
svg.appendChild(title);
svg.setAttribute("aria-labelledby", `car-${CarDirective_1.titleIdCounter}`);
}
}
};
CarDirective.titleIdCounter = 0;
CarDirective.ctorParameters = () => [
{ type: ElementRef }
];
__decorate([
Input(),
__metadata("design:type", String)
], CarDirective.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], CarDirective.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], CarDirective.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], CarDirective.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], CarDirective.prototype, "isFocusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], CarDirective.prototype, "size", void 0);
CarDirective = CarDirective_1 = __decorate([
Directive({
selector: "[ibmIconCar]"
}),
__metadata("design:paramtypes", [ElementRef])
], CarDirective);
let CarModule = class CarModule {
};
CarModule = __decorate([
NgModule({
declarations: [
CarComponent,
CarDirective,
],
exports: [
CarComponent,
CarDirective,
]
})
], CarModule);
export { CarComponent, CarDirective, CarModule };