@carbon/icons-angular
Version:
Angular components for icons in digital and software products using the Carbon Design System
174 lines (171 loc) • 11.2 kB
JavaScript
import { __decorate, __metadata } from 'tslib';
import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core';
import { getAttributes } from '@carbon/icon-helpers';
var SleetDirective_1;
let SleetComponent = class SleetComponent {
constructor() {
this.focusable = false;
}
};
__decorate([
Input(),
__metadata("design:type", String)
], SleetComponent.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SleetComponent.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], SleetComponent.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SleetComponent.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], SleetComponent.prototype, "focusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SleetComponent.prototype, "innerClass", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SleetComponent.prototype, "size", void 0);
SleetComponent = __decorate([
Component({
selector: "ibm-icon-sleet",
template: `
<svg
ibmIconSleet
[size]="size"
[ariaLabel]="ariaLabel"
[ariaLabelledby]="ariaLabelledby"
[ariaHidden]="ariaHidden"
[title]="title"
[isFocusable]="focusable"
[attr.class]="innerClass">
</svg>
`
})
], SleetComponent);
let SleetDirective = SleetDirective_1 = class SleetDirective {
constructor(elementRef) {
this.elementRef = elementRef;
this.isFocusable = false;
this.icons = {
"32": {
metadata: { "moduleName": "Sleet32", "filepath": "sleet/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": "M6 24H8V26H6zM8 26H10V28H8zM10 28H12V30H10zM10 24H12V26H10zM6 28H8V30H6z" } }, { "elem": "path", "attrs": { "d": "M21 30a1 1 0 01-.8944-1.4474l2-4.0005a1 1 0 111.7888.8947l-2 4A.9981.9981 0 0121 30zM24.8008 9.1362a8.9943 8.9943 0 00-17.6006 0A6.4973 6.4973 0 008.5 22h8.8818L16.106 24.5527a1 1 0 101.7885.8946L19.6177 22H23.5A6.4974 6.4974 0 0024.8008 9.1362zM23.5 20H8.5a4.4975 4.4975 0 01-.356-8.981l.8155-.0639.0991-.812a6.9938 6.9938 0 0113.8838 0l.0986.812.8154.0639A4.4975 4.4975 0 0123.5 20z" } }], "name": "sleet", "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="M6 24H8V26H6zM8 26H10V28H8zM10 28H12V30H10zM10 24H12V26H10zM6 28H8V30H6z"></path><path d="M21 30a1 1 0 01-.8944-1.4474l2-4.0005a1 1 0 111.7888.8947l-2 4A.9981.9981 0 0121 30zM24.8008 9.1362a8.9943 8.9943 0 00-17.6006 0A6.4973 6.4973 0 008.5 22h8.8818L16.106 24.5527a1 1 0 101.7885.8946L19.6177 22H23.5A6.4974 6.4974 0 0024.8008 9.1362zM23.5 20H8.5a4.4975 4.4975 0 01-.356-8.981l.8155-.0639.0991-.812a6.9938 6.9938 0 0113.8838 0l.0986.812.8154.0639A4.4975 4.4975 0 0123.5 20z"></path></svg>`
},
"24": {
metadata: { "moduleName": "Sleet24", "filepath": "sleet/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": "M6 24H8V26H6zM8 26H10V28H8zM10 28H12V30H10zM10 24H12V26H10zM6 28H8V30H6z" } }, { "elem": "path", "attrs": { "d": "M21 30a1 1 0 01-.8944-1.4474l2-4.0005a1 1 0 111.7888.8947l-2 4A.9981.9981 0 0121 30zM24.8008 9.1362a8.9943 8.9943 0 00-17.6006 0A6.4973 6.4973 0 008.5 22h8.8818L16.106 24.5527a1 1 0 101.7885.8946L19.6177 22H23.5A6.4974 6.4974 0 0024.8008 9.1362zM23.5 20H8.5a4.4975 4.4975 0 01-.356-8.981l.8155-.0639.0991-.812a6.9938 6.9938 0 0113.8838 0l.0986.812.8154.0639A4.4975 4.4975 0 0123.5 20z" } }], "name": "sleet", "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="M6 24H8V26H6zM8 26H10V28H8zM10 28H12V30H10zM10 24H12V26H10zM6 28H8V30H6z"></path><path d="M21 30a1 1 0 01-.8944-1.4474l2-4.0005a1 1 0 111.7888.8947l-2 4A.9981.9981 0 0121 30zM24.8008 9.1362a8.9943 8.9943 0 00-17.6006 0A6.4973 6.4973 0 008.5 22h8.8818L16.106 24.5527a1 1 0 101.7885.8946L19.6177 22H23.5A6.4974 6.4974 0 0024.8008 9.1362zM23.5 20H8.5a4.4975 4.4975 0 01-.356-8.981l.8155-.0639.0991-.812a6.9938 6.9938 0 0113.8838 0l.0986.812.8154.0639A4.4975 4.4975 0 0123.5 20z"></path></svg>`
},
"20": {
metadata: { "moduleName": "Sleet20", "filepath": "sleet/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": "M6 24H8V26H6zM8 26H10V28H8zM10 28H12V30H10zM10 24H12V26H10zM6 28H8V30H6z" } }, { "elem": "path", "attrs": { "d": "M21 30a1 1 0 01-.8944-1.4474l2-4.0005a1 1 0 111.7888.8947l-2 4A.9981.9981 0 0121 30zM24.8008 9.1362a8.9943 8.9943 0 00-17.6006 0A6.4973 6.4973 0 008.5 22h8.8818L16.106 24.5527a1 1 0 101.7885.8946L19.6177 22H23.5A6.4974 6.4974 0 0024.8008 9.1362zM23.5 20H8.5a4.4975 4.4975 0 01-.356-8.981l.8155-.0639.0991-.812a6.9938 6.9938 0 0113.8838 0l.0986.812.8154.0639A4.4975 4.4975 0 0123.5 20z" } }], "name": "sleet", "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="M6 24H8V26H6zM8 26H10V28H8zM10 28H12V30H10zM10 24H12V26H10zM6 28H8V30H6z"></path><path d="M21 30a1 1 0 01-.8944-1.4474l2-4.0005a1 1 0 111.7888.8947l-2 4A.9981.9981 0 0121 30zM24.8008 9.1362a8.9943 8.9943 0 00-17.6006 0A6.4973 6.4973 0 008.5 22h8.8818L16.106 24.5527a1 1 0 101.7885.8946L19.6177 22H23.5A6.4974 6.4974 0 0024.8008 9.1362zM23.5 20H8.5a4.4975 4.4975 0 01-.356-8.981l.8155-.0639.0991-.812a6.9938 6.9938 0 0113.8838 0l.0986.812.8154.0639A4.4975 4.4975 0 0123.5 20z"></path></svg>`
},
"16": {
metadata: { "moduleName": "Sleet16", "filepath": "sleet/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": "M6 24H8V26H6zM8 26H10V28H8zM10 28H12V30H10zM10 24H12V26H10zM6 28H8V30H6z" } }, { "elem": "path", "attrs": { "d": "M21 30a1 1 0 01-.8944-1.4474l2-4.0005a1 1 0 111.7888.8947l-2 4A.9981.9981 0 0121 30zM24.8008 9.1362a8.9943 8.9943 0 00-17.6006 0A6.4973 6.4973 0 008.5 22h8.8818L16.106 24.5527a1 1 0 101.7885.8946L19.6177 22H23.5A6.4974 6.4974 0 0024.8008 9.1362zM23.5 20H8.5a4.4975 4.4975 0 01-.356-8.981l.8155-.0639.0991-.812a6.9938 6.9938 0 0113.8838 0l.0986.812.8154.0639A4.4975 4.4975 0 0123.5 20z" } }], "name": "sleet", "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="M6 24H8V26H6zM8 26H10V28H8zM10 28H12V30H10zM10 24H12V26H10zM6 28H8V30H6z"></path><path d="M21 30a1 1 0 01-.8944-1.4474l2-4.0005a1 1 0 111.7888.8947l-2 4A.9981.9981 0 0121 30zM24.8008 9.1362a8.9943 8.9943 0 00-17.6006 0A6.4973 6.4973 0 008.5 22h8.8818L16.106 24.5527a1 1 0 101.7885.8946L19.6177 22H23.5A6.4974 6.4974 0 0024.8008 9.1362zM23.5 20H8.5a4.4975 4.4975 0 01-.356-8.981l.8155-.0639.0991-.812a6.9938 6.9938 0 0113.8838 0l.0986.812.8154.0639A4.4975 4.4975 0 0123.5 20z"></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;
SleetDirective_1.titleIdCounter++;
title.setAttribute("id", `sleet-${SleetDirective_1.titleIdCounter}`);
svg.appendChild(title);
svg.setAttribute("aria-labelledby", `sleet-${SleetDirective_1.titleIdCounter}`);
}
}
};
SleetDirective.titleIdCounter = 0;
SleetDirective.ctorParameters = () => [
{ type: ElementRef }
];
__decorate([
Input(),
__metadata("design:type", String)
], SleetDirective.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SleetDirective.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], SleetDirective.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SleetDirective.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], SleetDirective.prototype, "isFocusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SleetDirective.prototype, "size", void 0);
SleetDirective = SleetDirective_1 = __decorate([
Directive({
selector: "[ibmIconSleet]"
}),
__metadata("design:paramtypes", [ElementRef])
], SleetDirective);
let SleetModule = class SleetModule {
};
SleetModule = __decorate([
NgModule({
declarations: [
SleetComponent,
SleetDirective,
],
exports: [
SleetComponent,
SleetDirective,
]
})
], SleetModule);
export { SleetComponent, SleetDirective, SleetModule };