@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 SnoozeDirective_1;
let SnoozeComponent = class SnoozeComponent {
constructor() {
this.focusable = false;
}
};
__decorate([
Input(),
__metadata("design:type", String)
], SnoozeComponent.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SnoozeComponent.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], SnoozeComponent.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SnoozeComponent.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], SnoozeComponent.prototype, "focusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SnoozeComponent.prototype, "innerClass", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SnoozeComponent.prototype, "size", void 0);
SnoozeComponent = __decorate([
Component({
selector: "ibm-icon-snooze",
template: `
<svg
ibmIconSnooze
[size]="size"
[ariaLabel]="ariaLabel"
[ariaLabelledby]="ariaLabelledby"
[ariaHidden]="ariaHidden"
[title]="title"
[isFocusable]="focusable"
[attr.class]="innerClass">
</svg>
`
})
], SnoozeComponent);
let SnoozeDirective = SnoozeDirective_1 = class SnoozeDirective {
constructor(elementRef) {
this.elementRef = elementRef;
this.isFocusable = false;
this.icons = {
"32": {
metadata: { "moduleName": "Snooze32", "filepath": "snooze/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": "M20 14L20 12 12 12 12 14 17.5 14 12 20 12 22 20 22 20 20 14.507 20 20 14z" } }, { "elem": "path", "attrs": { "d": "M24.5 3.965H26.499V9.036999999999999H24.5z", "transform": "rotate(-44.945 25.5 6.5)" } }, { "elem": "path", "attrs": { "d": "M16,28A11,11,0,1,1,27,17,11.0125,11.0125,0,0,1,16,28ZM16,8a9,9,0,1,0,9,9A9.01,9.01,0,0,0,16,8Z" } }, { "elem": "path", "attrs": { "d": "M3.965 5.501H9.036999999999999V7.5H3.965z", "transform": "rotate(-45.055 6.5 6.5)" } }], "name": "snooze", "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="M20 14L20 12 12 12 12 14 17.5 14 12 20 12 22 20 22 20 20 14.507 20 20 14z"></path><path d="M24.5 3.965H26.499V9.036999999999999H24.5z" transform="rotate(-44.945 25.5 6.5)"></path><path d="M16,28A11,11,0,1,1,27,17,11.0125,11.0125,0,0,1,16,28ZM16,8a9,9,0,1,0,9,9A9.01,9.01,0,0,0,16,8Z"></path><path d="M3.965 5.501H9.036999999999999V7.5H3.965z" transform="rotate(-45.055 6.5 6.5)"></path></svg>`
},
"24": {
metadata: { "moduleName": "Snooze24", "filepath": "snooze/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": "M20 14L20 12 12 12 12 14 17.5 14 12 20 12 22 20 22 20 20 14.507 20 20 14z" } }, { "elem": "path", "attrs": { "d": "M24.5 3.965H26.499V9.036999999999999H24.5z", "transform": "rotate(-44.945 25.5 6.5)" } }, { "elem": "path", "attrs": { "d": "M16,28A11,11,0,1,1,27,17,11.0125,11.0125,0,0,1,16,28ZM16,8a9,9,0,1,0,9,9A9.01,9.01,0,0,0,16,8Z" } }, { "elem": "path", "attrs": { "d": "M3.965 5.501H9.036999999999999V7.5H3.965z", "transform": "rotate(-45.055 6.5 6.5)" } }], "name": "snooze", "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="M20 14L20 12 12 12 12 14 17.5 14 12 20 12 22 20 22 20 20 14.507 20 20 14z"></path><path d="M24.5 3.965H26.499V9.036999999999999H24.5z" transform="rotate(-44.945 25.5 6.5)"></path><path d="M16,28A11,11,0,1,1,27,17,11.0125,11.0125,0,0,1,16,28ZM16,8a9,9,0,1,0,9,9A9.01,9.01,0,0,0,16,8Z"></path><path d="M3.965 5.501H9.036999999999999V7.5H3.965z" transform="rotate(-45.055 6.5 6.5)"></path></svg>`
},
"20": {
metadata: { "moduleName": "Snooze20", "filepath": "snooze/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": "M20 14L20 12 12 12 12 14 17.5 14 12 20 12 22 20 22 20 20 14.507 20 20 14z" } }, { "elem": "path", "attrs": { "d": "M24.5 3.965H26.499V9.036999999999999H24.5z", "transform": "rotate(-44.945 25.5 6.5)" } }, { "elem": "path", "attrs": { "d": "M16,28A11,11,0,1,1,27,17,11.0125,11.0125,0,0,1,16,28ZM16,8a9,9,0,1,0,9,9A9.01,9.01,0,0,0,16,8Z" } }, { "elem": "path", "attrs": { "d": "M3.965 5.501H9.036999999999999V7.5H3.965z", "transform": "rotate(-45.055 6.5 6.5)" } }], "name": "snooze", "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="M20 14L20 12 12 12 12 14 17.5 14 12 20 12 22 20 22 20 20 14.507 20 20 14z"></path><path d="M24.5 3.965H26.499V9.036999999999999H24.5z" transform="rotate(-44.945 25.5 6.5)"></path><path d="M16,28A11,11,0,1,1,27,17,11.0125,11.0125,0,0,1,16,28ZM16,8a9,9,0,1,0,9,9A9.01,9.01,0,0,0,16,8Z"></path><path d="M3.965 5.501H9.036999999999999V7.5H3.965z" transform="rotate(-45.055 6.5 6.5)"></path></svg>`
},
"16": {
metadata: { "moduleName": "Snooze16", "filepath": "snooze/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": "M20 14L20 12 12 12 12 14 17.5 14 12 20 12 22 20 22 20 20 14.507 20 20 14z" } }, { "elem": "path", "attrs": { "d": "M24.5 3.965H26.499V9.036999999999999H24.5z", "transform": "rotate(-44.945 25.5 6.5)" } }, { "elem": "path", "attrs": { "d": "M16,28A11,11,0,1,1,27,17,11.0125,11.0125,0,0,1,16,28ZM16,8a9,9,0,1,0,9,9A9.01,9.01,0,0,0,16,8Z" } }, { "elem": "path", "attrs": { "d": "M3.965 5.501H9.036999999999999V7.5H3.965z", "transform": "rotate(-45.055 6.5 6.5)" } }], "name": "snooze", "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="M20 14L20 12 12 12 12 14 17.5 14 12 20 12 22 20 22 20 20 14.507 20 20 14z"></path><path d="M24.5 3.965H26.499V9.036999999999999H24.5z" transform="rotate(-44.945 25.5 6.5)"></path><path d="M16,28A11,11,0,1,1,27,17,11.0125,11.0125,0,0,1,16,28ZM16,8a9,9,0,1,0,9,9A9.01,9.01,0,0,0,16,8Z"></path><path d="M3.965 5.501H9.036999999999999V7.5H3.965z" transform="rotate(-45.055 6.5 6.5)"></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;
SnoozeDirective_1.titleIdCounter++;
title.setAttribute("id", `snooze-${SnoozeDirective_1.titleIdCounter}`);
svg.appendChild(title);
svg.setAttribute("aria-labelledby", `snooze-${SnoozeDirective_1.titleIdCounter}`);
}
}
};
SnoozeDirective.titleIdCounter = 0;
SnoozeDirective.ctorParameters = () => [
{ type: ElementRef }
];
__decorate([
Input(),
__metadata("design:type", String)
], SnoozeDirective.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SnoozeDirective.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], SnoozeDirective.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SnoozeDirective.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], SnoozeDirective.prototype, "isFocusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], SnoozeDirective.prototype, "size", void 0);
SnoozeDirective = SnoozeDirective_1 = __decorate([
Directive({
selector: "[ibmIconSnooze]"
}),
__metadata("design:paramtypes", [ElementRef])
], SnoozeDirective);
let SnoozeModule = class SnoozeModule {
};
SnoozeModule = __decorate([
NgModule({
declarations: [
SnoozeComponent,
SnoozeDirective,
],
exports: [
SnoozeComponent,
SnoozeDirective,
]
})
], SnoozeModule);
export { SnoozeComponent, SnoozeDirective, SnoozeModule };