@carbon/icons-angular
Version:
Angular components for icons in digital and software products using the Carbon Design System
169 lines (166 loc) • 8.85 kB
JavaScript
import { __decorate, __metadata } from 'tslib';
import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core';
import { getAttributes } from '@carbon/icon-helpers';
var CheckmarkComponent = /** @class */ (function () {
function CheckmarkComponent() {
this.focusable = false;
}
__decorate([
Input(),
__metadata("design:type", String)
], CheckmarkComponent.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], CheckmarkComponent.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], CheckmarkComponent.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], CheckmarkComponent.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], CheckmarkComponent.prototype, "focusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], CheckmarkComponent.prototype, "innerClass", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], CheckmarkComponent.prototype, "size", void 0);
CheckmarkComponent = __decorate([
Component({
selector: "ibm-icon-checkmark",
template: "\n <svg\n ibmIconCheckmark\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 "
})
], CheckmarkComponent);
return CheckmarkComponent;
}());
var CheckmarkDirective = /** @class */ (function () {
function CheckmarkDirective(elementRef) {
this.elementRef = elementRef;
this.isFocusable = false;
this.icons = {
"32": {
metadata: { "moduleName": "Checkmark32", "filepath": "checkmark/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": "M13 24L4 15 5.414 13.586 13 21.171 26.586 7.586 28 9 13 24z" } }], "name": "checkmark", "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=\"M13 24L4 15 5.414 13.586 13 21.171 26.586 7.586 28 9 13 24z\"></path></svg>"
},
"24": {
metadata: { "moduleName": "Checkmark24", "filepath": "checkmark/24.js", "descriptor": { "elem": "svg", "attrs": { "xmlns": "http://www.w3.org/2000/svg", "viewBox": "0 0 24 24", "fill": "currentColor", "width": 24, "height": 24 }, "content": [{ "elem": "path", "attrs": { "d": "M10 15.9L4.7 10.6 3.6 11.6 8.9 16.9 10 18 20.6 7.4 19.5 6.3z" } }], "name": "checkmark", "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 24 24\" aria-hidden=\"true\"><path d=\"M10 15.9L4.7 10.6 3.6 11.6 8.9 16.9 10 18 20.6 7.4 19.5 6.3z\"></path></svg>"
},
"20": {
metadata: { "moduleName": "Checkmark20", "filepath": "checkmark/20.js", "descriptor": { "elem": "svg", "attrs": { "xmlns": "http://www.w3.org/2000/svg", "viewBox": "0 0 20 20", "fill": "currentColor", "width": 20, "height": 20 }, "content": [{ "elem": "path", "attrs": { "d": "M8 13.2L3.6 8.8 2.7 9.7 7.1 14.1 8 15 16.5 6.5 15.6 5.6z" } }, { "elem": "path", "attrs": { "d": "M15.6 5.6L8 13.2 3.6 8.8 2.7 9.7 7.1 14.1 8 15 16.5 6.5 15.6 5.6z" } }], "name": "checkmark", "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 20 20\" aria-hidden=\"true\"><path d=\"M8 13.2L3.6 8.8 2.7 9.7 7.1 14.1 8 15 16.5 6.5 15.6 5.6z\"></path><path d=\"M15.6 5.6L8 13.2 3.6 8.8 2.7 9.7 7.1 14.1 8 15 16.5 6.5 15.6 5.6z\"></path></svg>"
},
"16": {
metadata: { "moduleName": "Checkmark16", "filepath": "checkmark/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": "M13 24L4 15 5.414 13.586 13 21.171 26.586 7.586 28 9 13 24z" } }], "name": "checkmark", "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=\"M13 24L4 15 5.414 13.586 13 21.171 26.586 7.586 28 9 13 24z\"></path></svg>"
},
};
}
CheckmarkDirective_1 = CheckmarkDirective;
CheckmarkDirective.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;
CheckmarkDirective_1.titleIdCounter++;
title.setAttribute("id", "checkmark-" + CheckmarkDirective_1.titleIdCounter);
svg.appendChild(title);
svg.setAttribute("aria-labelledby", "checkmark-" + CheckmarkDirective_1.titleIdCounter);
}
};
var CheckmarkDirective_1;
CheckmarkDirective.titleIdCounter = 0;
CheckmarkDirective.ctorParameters = function () { return [
{ type: ElementRef }
]; };
__decorate([
Input(),
__metadata("design:type", String)
], CheckmarkDirective.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], CheckmarkDirective.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], CheckmarkDirective.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], CheckmarkDirective.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], CheckmarkDirective.prototype, "isFocusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], CheckmarkDirective.prototype, "size", void 0);
CheckmarkDirective = CheckmarkDirective_1 = __decorate([
Directive({
selector: "[ibmIconCheckmark]"
}),
__metadata("design:paramtypes", [ElementRef])
], CheckmarkDirective);
return CheckmarkDirective;
}());
var CheckmarkModule = /** @class */ (function () {
function CheckmarkModule() {
}
CheckmarkModule = __decorate([
NgModule({
declarations: [
CheckmarkComponent,
CheckmarkDirective,
],
exports: [
CheckmarkComponent,
CheckmarkDirective,
]
})
], CheckmarkModule);
return CheckmarkModule;
}());
export { CheckmarkComponent, CheckmarkDirective, CheckmarkModule };