UNPKG

@carbon/icons-angular

Version:

Angular components for icons in digital and software products using the Carbon Design System

169 lines (166 loc) 11.2 kB
import { __decorate, __metadata } from 'tslib'; import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core'; import { getAttributes } from '@carbon/icon-helpers'; var CodeReferenceComponent = /** @class */ (function () { function CodeReferenceComponent() { this.focusable = false; } __decorate([ Input(), __metadata("design:type", String) ], CodeReferenceComponent.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], CodeReferenceComponent.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], CodeReferenceComponent.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], CodeReferenceComponent.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], CodeReferenceComponent.prototype, "focusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], CodeReferenceComponent.prototype, "innerClass", void 0); __decorate([ Input(), __metadata("design:type", String) ], CodeReferenceComponent.prototype, "size", void 0); CodeReferenceComponent = __decorate([ Component({ selector: "ibm-icon-code-reference", template: "\n <svg\n ibmIconCodeReference\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 " }) ], CodeReferenceComponent); return CodeReferenceComponent; }()); var CodeReferenceDirective = /** @class */ (function () { function CodeReferenceDirective(elementRef) { this.elementRef = elementRef; this.isFocusable = false; this.icons = { "32": { metadata: { "moduleName": "CodeReference32", "filepath": "code--reference/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": "M4 20L4 22 8.586 22 2 28.586 3.414 30 10 23.414 10 28 12 28 12 20 4 20zM30 10L24 4 22.586 5.414 27.172 10 22.586 14.586 24 16 30 10z" } }, { "elem": "path", "attrs": { "d": "M8.944 9.001H24.974000000000004V11.001H8.944z", "transform": "rotate(-74.995 16.96 10)" } }, { "elem": "path", "attrs": { "d": "M4 10L10 4 11.414 5.414 6.828 10 11.414 14.586 10 16 4 10z" } }], "name": "code--reference", "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=\"M4 20L4 22 8.586 22 2 28.586 3.414 30 10 23.414 10 28 12 28 12 20 4 20zM30 10L24 4 22.586 5.414 27.172 10 22.586 14.586 24 16 30 10z\"></path><path d=\"M8.944 9.001H24.974000000000004V11.001H8.944z\" transform=\"rotate(-74.995 16.96 10)\"></path><path d=\"M4 10L10 4 11.414 5.414 6.828 10 11.414 14.586 10 16 4 10z\"></path></svg>" }, "24": { metadata: { "moduleName": "CodeReference24", "filepath": "code--reference/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": "M4 20L4 22 8.586 22 2 28.586 3.414 30 10 23.414 10 28 12 28 12 20 4 20zM30 10L24 4 22.586 5.414 27.172 10 22.586 14.586 24 16 30 10z" } }, { "elem": "path", "attrs": { "d": "M8.944 9.001H24.974000000000004V11.001H8.944z", "transform": "rotate(-74.995 16.96 10)" } }, { "elem": "path", "attrs": { "d": "M4 10L10 4 11.414 5.414 6.828 10 11.414 14.586 10 16 4 10z" } }], "name": "code--reference", "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=\"M4 20L4 22 8.586 22 2 28.586 3.414 30 10 23.414 10 28 12 28 12 20 4 20zM30 10L24 4 22.586 5.414 27.172 10 22.586 14.586 24 16 30 10z\"></path><path d=\"M8.944 9.001H24.974000000000004V11.001H8.944z\" transform=\"rotate(-74.995 16.96 10)\"></path><path d=\"M4 10L10 4 11.414 5.414 6.828 10 11.414 14.586 10 16 4 10z\"></path></svg>" }, "20": { metadata: { "moduleName": "CodeReference20", "filepath": "code--reference/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": "M4 20L4 22 8.586 22 2 28.586 3.414 30 10 23.414 10 28 12 28 12 20 4 20zM30 10L24 4 22.586 5.414 27.172 10 22.586 14.586 24 16 30 10z" } }, { "elem": "path", "attrs": { "d": "M8.944 9.001H24.974000000000004V11.001H8.944z", "transform": "rotate(-74.995 16.96 10)" } }, { "elem": "path", "attrs": { "d": "M4 10L10 4 11.414 5.414 6.828 10 11.414 14.586 10 16 4 10z" } }], "name": "code--reference", "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=\"M4 20L4 22 8.586 22 2 28.586 3.414 30 10 23.414 10 28 12 28 12 20 4 20zM30 10L24 4 22.586 5.414 27.172 10 22.586 14.586 24 16 30 10z\"></path><path d=\"M8.944 9.001H24.974000000000004V11.001H8.944z\" transform=\"rotate(-74.995 16.96 10)\"></path><path d=\"M4 10L10 4 11.414 5.414 6.828 10 11.414 14.586 10 16 4 10z\"></path></svg>" }, "16": { metadata: { "moduleName": "CodeReference16", "filepath": "code--reference/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": "M4 20L4 22 8.586 22 2 28.586 3.414 30 10 23.414 10 28 12 28 12 20 4 20zM30 10L24 4 22.586 5.414 27.172 10 22.586 14.586 24 16 30 10z" } }, { "elem": "path", "attrs": { "d": "M8.944 9.001H24.974000000000004V11.001H8.944z", "transform": "rotate(-74.995 16.96 10)" } }, { "elem": "path", "attrs": { "d": "M4 10L10 4 11.414 5.414 6.828 10 11.414 14.586 10 16 4 10z" } }], "name": "code--reference", "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=\"M4 20L4 22 8.586 22 2 28.586 3.414 30 10 23.414 10 28 12 28 12 20 4 20zM30 10L24 4 22.586 5.414 27.172 10 22.586 14.586 24 16 30 10z\"></path><path d=\"M8.944 9.001H24.974000000000004V11.001H8.944z\" transform=\"rotate(-74.995 16.96 10)\"></path><path d=\"M4 10L10 4 11.414 5.414 6.828 10 11.414 14.586 10 16 4 10z\"></path></svg>" }, }; } CodeReferenceDirective_1 = CodeReferenceDirective; CodeReferenceDirective.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; CodeReferenceDirective_1.titleIdCounter++; title.setAttribute("id", "code-reference-" + CodeReferenceDirective_1.titleIdCounter); svg.appendChild(title); svg.setAttribute("aria-labelledby", "code-reference-" + CodeReferenceDirective_1.titleIdCounter); } }; var CodeReferenceDirective_1; CodeReferenceDirective.titleIdCounter = 0; CodeReferenceDirective.ctorParameters = function () { return [ { type: ElementRef } ]; }; __decorate([ Input(), __metadata("design:type", String) ], CodeReferenceDirective.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], CodeReferenceDirective.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], CodeReferenceDirective.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], CodeReferenceDirective.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], CodeReferenceDirective.prototype, "isFocusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], CodeReferenceDirective.prototype, "size", void 0); CodeReferenceDirective = CodeReferenceDirective_1 = __decorate([ Directive({ selector: "[ibmIconCodeReference]" }), __metadata("design:paramtypes", [ElementRef]) ], CodeReferenceDirective); return CodeReferenceDirective; }()); var CodeReferenceModule = /** @class */ (function () { function CodeReferenceModule() { } CodeReferenceModule = __decorate([ NgModule({ declarations: [ CodeReferenceComponent, CodeReferenceDirective, ], exports: [ CodeReferenceComponent, CodeReferenceDirective, ] }) ], CodeReferenceModule); return CodeReferenceModule; }()); export { CodeReferenceComponent, CodeReferenceDirective, CodeReferenceModule };