UNPKG

@carbon/icons-angular

Version:

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

174 lines (171 loc) 11.6 kB
import { __decorate, __metadata } from 'tslib'; import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core'; import { getAttributes } from '@carbon/icon-helpers'; var TypePatternDirective_1; let TypePatternComponent = class TypePatternComponent { constructor() { this.focusable = false; } }; __decorate([ Input(), __metadata("design:type", String) ], TypePatternComponent.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], TypePatternComponent.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], TypePatternComponent.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], TypePatternComponent.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], TypePatternComponent.prototype, "focusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], TypePatternComponent.prototype, "innerClass", void 0); __decorate([ Input(), __metadata("design:type", String) ], TypePatternComponent.prototype, "size", void 0); TypePatternComponent = __decorate([ Component({ selector: "ibm-icon-type-pattern", template: ` <svg ibmIconTypePattern [size]="size" [ariaLabel]="ariaLabel" [ariaLabelledby]="ariaLabelledby" [ariaHidden]="ariaHidden" [title]="title" [isFocusable]="focusable" [attr.class]="innerClass"> </svg> ` }) ], TypePatternComponent); let TypePatternDirective = TypePatternDirective_1 = class TypePatternDirective { constructor(elementRef) { this.elementRef = elementRef; this.isFocusable = false; this.icons = { "32": { metadata: { "moduleName": "TypePattern32", "filepath": "type-pattern/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": "M30 15L17 15 17 2 15 2 15 15 2 15 2 17 15 17 15 30 17 30 17 17 30 17 30 15z" } }, { "elem": "path", "attrs": { "d": "M25.586 20L27 21.414 23.414 25 27 28.586 25.586 30 20.586 25 25.586 20zM11 30H3a1 1 0 01-.8945-1.4473l4-8a1.0412 1.0412 0 011.789 0l4 8A1 1 0 0111 30zM4.6182 28H9.3818L7 23.2363zM28 12H22a2.0023 2.0023 0 01-2-2V4a2.0023 2.0023 0 012-2h6a2.0023 2.0023 0 012 2v6A2.0023 2.0023 0 0128 12zM22 4v6h6.001L28 4zM7 12a5 5 0 115-5A5.0059 5.0059 0 017 12zM7 4a3 3 0 103 3A3.0033 3.0033 0 007 4z" } }], "name": "type-pattern", "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="M30 15L17 15 17 2 15 2 15 15 2 15 2 17 15 17 15 30 17 30 17 17 30 17 30 15z"></path><path d="M25.586 20L27 21.414 23.414 25 27 28.586 25.586 30 20.586 25 25.586 20zM11 30H3a1 1 0 01-.8945-1.4473l4-8a1.0412 1.0412 0 011.789 0l4 8A1 1 0 0111 30zM4.6182 28H9.3818L7 23.2363zM28 12H22a2.0023 2.0023 0 01-2-2V4a2.0023 2.0023 0 012-2h6a2.0023 2.0023 0 012 2v6A2.0023 2.0023 0 0128 12zM22 4v6h6.001L28 4zM7 12a5 5 0 115-5A5.0059 5.0059 0 017 12zM7 4a3 3 0 103 3A3.0033 3.0033 0 007 4z"></path></svg>` }, "24": { metadata: { "moduleName": "TypePattern24", "filepath": "type-pattern/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": "M30 15L17 15 17 2 15 2 15 15 2 15 2 17 15 17 15 30 17 30 17 17 30 17 30 15z" } }, { "elem": "path", "attrs": { "d": "M25.586 20L27 21.414 23.414 25 27 28.586 25.586 30 20.586 25 25.586 20zM11 30H3a1 1 0 01-.8945-1.4473l4-8a1.0412 1.0412 0 011.789 0l4 8A1 1 0 0111 30zM4.6182 28H9.3818L7 23.2363zM28 12H22a2.0023 2.0023 0 01-2-2V4a2.0023 2.0023 0 012-2h6a2.0023 2.0023 0 012 2v6A2.0023 2.0023 0 0128 12zM22 4v6h6.001L28 4zM7 12a5 5 0 115-5A5.0059 5.0059 0 017 12zM7 4a3 3 0 103 3A3.0033 3.0033 0 007 4z" } }], "name": "type-pattern", "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="M30 15L17 15 17 2 15 2 15 15 2 15 2 17 15 17 15 30 17 30 17 17 30 17 30 15z"></path><path d="M25.586 20L27 21.414 23.414 25 27 28.586 25.586 30 20.586 25 25.586 20zM11 30H3a1 1 0 01-.8945-1.4473l4-8a1.0412 1.0412 0 011.789 0l4 8A1 1 0 0111 30zM4.6182 28H9.3818L7 23.2363zM28 12H22a2.0023 2.0023 0 01-2-2V4a2.0023 2.0023 0 012-2h6a2.0023 2.0023 0 012 2v6A2.0023 2.0023 0 0128 12zM22 4v6h6.001L28 4zM7 12a5 5 0 115-5A5.0059 5.0059 0 017 12zM7 4a3 3 0 103 3A3.0033 3.0033 0 007 4z"></path></svg>` }, "20": { metadata: { "moduleName": "TypePattern20", "filepath": "type-pattern/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": "M30 15L17 15 17 2 15 2 15 15 2 15 2 17 15 17 15 30 17 30 17 17 30 17 30 15z" } }, { "elem": "path", "attrs": { "d": "M25.586 20L27 21.414 23.414 25 27 28.586 25.586 30 20.586 25 25.586 20zM11 30H3a1 1 0 01-.8945-1.4473l4-8a1.0412 1.0412 0 011.789 0l4 8A1 1 0 0111 30zM4.6182 28H9.3818L7 23.2363zM28 12H22a2.0023 2.0023 0 01-2-2V4a2.0023 2.0023 0 012-2h6a2.0023 2.0023 0 012 2v6A2.0023 2.0023 0 0128 12zM22 4v6h6.001L28 4zM7 12a5 5 0 115-5A5.0059 5.0059 0 017 12zM7 4a3 3 0 103 3A3.0033 3.0033 0 007 4z" } }], "name": "type-pattern", "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="M30 15L17 15 17 2 15 2 15 15 2 15 2 17 15 17 15 30 17 30 17 17 30 17 30 15z"></path><path d="M25.586 20L27 21.414 23.414 25 27 28.586 25.586 30 20.586 25 25.586 20zM11 30H3a1 1 0 01-.8945-1.4473l4-8a1.0412 1.0412 0 011.789 0l4 8A1 1 0 0111 30zM4.6182 28H9.3818L7 23.2363zM28 12H22a2.0023 2.0023 0 01-2-2V4a2.0023 2.0023 0 012-2h6a2.0023 2.0023 0 012 2v6A2.0023 2.0023 0 0128 12zM22 4v6h6.001L28 4zM7 12a5 5 0 115-5A5.0059 5.0059 0 017 12zM7 4a3 3 0 103 3A3.0033 3.0033 0 007 4z"></path></svg>` }, "16": { metadata: { "moduleName": "TypePattern16", "filepath": "type-pattern/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": "M30 15L17 15 17 2 15 2 15 15 2 15 2 17 15 17 15 30 17 30 17 17 30 17 30 15z" } }, { "elem": "path", "attrs": { "d": "M25.586 20L27 21.414 23.414 25 27 28.586 25.586 30 20.586 25 25.586 20zM11 30H3a1 1 0 01-.8945-1.4473l4-8a1.0412 1.0412 0 011.789 0l4 8A1 1 0 0111 30zM4.6182 28H9.3818L7 23.2363zM28 12H22a2.0023 2.0023 0 01-2-2V4a2.0023 2.0023 0 012-2h6a2.0023 2.0023 0 012 2v6A2.0023 2.0023 0 0128 12zM22 4v6h6.001L28 4zM7 12a5 5 0 115-5A5.0059 5.0059 0 017 12zM7 4a3 3 0 103 3A3.0033 3.0033 0 007 4z" } }], "name": "type-pattern", "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="M30 15L17 15 17 2 15 2 15 15 2 15 2 17 15 17 15 30 17 30 17 17 30 17 30 15z"></path><path d="M25.586 20L27 21.414 23.414 25 27 28.586 25.586 30 20.586 25 25.586 20zM11 30H3a1 1 0 01-.8945-1.4473l4-8a1.0412 1.0412 0 011.789 0l4 8A1 1 0 0111 30zM4.6182 28H9.3818L7 23.2363zM28 12H22a2.0023 2.0023 0 01-2-2V4a2.0023 2.0023 0 012-2h6a2.0023 2.0023 0 012 2v6A2.0023 2.0023 0 0128 12zM22 4v6h6.001L28 4zM7 12a5 5 0 115-5A5.0059 5.0059 0 017 12zM7 4a3 3 0 103 3A3.0033 3.0033 0 007 4z"></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; TypePatternDirective_1.titleIdCounter++; title.setAttribute("id", `type-pattern-${TypePatternDirective_1.titleIdCounter}`); svg.appendChild(title); svg.setAttribute("aria-labelledby", `type-pattern-${TypePatternDirective_1.titleIdCounter}`); } } }; TypePatternDirective.titleIdCounter = 0; TypePatternDirective.ctorParameters = () => [ { type: ElementRef } ]; __decorate([ Input(), __metadata("design:type", String) ], TypePatternDirective.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], TypePatternDirective.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], TypePatternDirective.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], TypePatternDirective.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], TypePatternDirective.prototype, "isFocusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], TypePatternDirective.prototype, "size", void 0); TypePatternDirective = TypePatternDirective_1 = __decorate([ Directive({ selector: "[ibmIconTypePattern]" }), __metadata("design:paramtypes", [ElementRef]) ], TypePatternDirective); let TypePatternModule = class TypePatternModule { }; TypePatternModule = __decorate([ NgModule({ declarations: [ TypePatternComponent, TypePatternDirective, ], exports: [ TypePatternComponent, TypePatternDirective, ] }) ], TypePatternModule); export { TypePatternComponent, TypePatternDirective, TypePatternModule };