UNPKG

@carbon/icons-angular

Version:

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

174 lines (171 loc) 12.1 kB
import { __decorate, __metadata } from 'tslib'; import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core'; import { getAttributes } from '@carbon/icon-helpers'; var ChartCustomDirective_1; let ChartCustomComponent = class ChartCustomComponent { constructor() { this.focusable = false; } }; __decorate([ Input(), __metadata("design:type", String) ], ChartCustomComponent.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], ChartCustomComponent.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], ChartCustomComponent.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], ChartCustomComponent.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], ChartCustomComponent.prototype, "focusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], ChartCustomComponent.prototype, "innerClass", void 0); __decorate([ Input(), __metadata("design:type", String) ], ChartCustomComponent.prototype, "size", void 0); ChartCustomComponent = __decorate([ Component({ selector: "ibm-icon-chart-custom", template: ` <svg ibmIconChartCustom [size]="size" [ariaLabel]="ariaLabel" [ariaLabelledby]="ariaLabelledby" [ariaHidden]="ariaHidden" [title]="title" [isFocusable]="focusable" [attr.class]="innerClass"> </svg> ` }) ], ChartCustomComponent); let ChartCustomDirective = ChartCustomDirective_1 = class ChartCustomDirective { constructor(elementRef) { this.elementRef = elementRef; this.isFocusable = false; this.icons = { "32": { metadata: { "moduleName": "ChartCustom32", "filepath": "chart--custom/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": "M29.707,19.293l-3-3a.9994.9994,0,0,0-1.414,0L16,25.5859V30h4.4141l9.2929-9.293A.9994.9994,0,0,0,29.707,19.293ZM19.5859,28H18V26.4141l5-5L24.5859,23ZM26,21.5859,24.4141,20,26,18.4141,27.5859,20Z" } }, { "elem": "path", "attrs": { "d": "M17 15H21V17H17z", "transform": "rotate(-90 19 16)" } }, { "elem": "path", "attrs": { "d": "M12 14H18V16H12z", "transform": "rotate(-90 15 15)" } }, { "elem": "path", "attrs": { "d": "M6 12H16V14H6z", "transform": "rotate(-90 11 13)" } }, { "elem": "path", "attrs": { "d": "M12,30H6a2.0021,2.0021,0,0,1-2-2V4A2.0021,2.0021,0,0,1,6,2H22a2.0021,2.0021,0,0,1,2,2V14H22V4H6V28h6Z" } }], "name": "chart--custom", "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="M29.707,19.293l-3-3a.9994.9994,0,0,0-1.414,0L16,25.5859V30h4.4141l9.2929-9.293A.9994.9994,0,0,0,29.707,19.293ZM19.5859,28H18V26.4141l5-5L24.5859,23ZM26,21.5859,24.4141,20,26,18.4141,27.5859,20Z"></path><path d="M17 15H21V17H17z" transform="rotate(-90 19 16)"></path><path d="M12 14H18V16H12z" transform="rotate(-90 15 15)"></path><path d="M6 12H16V14H6z" transform="rotate(-90 11 13)"></path><path d="M12,30H6a2.0021,2.0021,0,0,1-2-2V4A2.0021,2.0021,0,0,1,6,2H22a2.0021,2.0021,0,0,1,2,2V14H22V4H6V28h6Z"></path></svg>` }, "24": { metadata: { "moduleName": "ChartCustom24", "filepath": "chart--custom/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": "M29.707,19.293l-3-3a.9994.9994,0,0,0-1.414,0L16,25.5859V30h4.4141l9.2929-9.293A.9994.9994,0,0,0,29.707,19.293ZM19.5859,28H18V26.4141l5-5L24.5859,23ZM26,21.5859,24.4141,20,26,18.4141,27.5859,20Z" } }, { "elem": "path", "attrs": { "d": "M17 15H21V17H17z", "transform": "rotate(-90 19 16)" } }, { "elem": "path", "attrs": { "d": "M12 14H18V16H12z", "transform": "rotate(-90 15 15)" } }, { "elem": "path", "attrs": { "d": "M6 12H16V14H6z", "transform": "rotate(-90 11 13)" } }, { "elem": "path", "attrs": { "d": "M12,30H6a2.0021,2.0021,0,0,1-2-2V4A2.0021,2.0021,0,0,1,6,2H22a2.0021,2.0021,0,0,1,2,2V14H22V4H6V28h6Z" } }], "name": "chart--custom", "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="M29.707,19.293l-3-3a.9994.9994,0,0,0-1.414,0L16,25.5859V30h4.4141l9.2929-9.293A.9994.9994,0,0,0,29.707,19.293ZM19.5859,28H18V26.4141l5-5L24.5859,23ZM26,21.5859,24.4141,20,26,18.4141,27.5859,20Z"></path><path d="M17 15H21V17H17z" transform="rotate(-90 19 16)"></path><path d="M12 14H18V16H12z" transform="rotate(-90 15 15)"></path><path d="M6 12H16V14H6z" transform="rotate(-90 11 13)"></path><path d="M12,30H6a2.0021,2.0021,0,0,1-2-2V4A2.0021,2.0021,0,0,1,6,2H22a2.0021,2.0021,0,0,1,2,2V14H22V4H6V28h6Z"></path></svg>` }, "20": { metadata: { "moduleName": "ChartCustom20", "filepath": "chart--custom/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": "M29.707,19.293l-3-3a.9994.9994,0,0,0-1.414,0L16,25.5859V30h4.4141l9.2929-9.293A.9994.9994,0,0,0,29.707,19.293ZM19.5859,28H18V26.4141l5-5L24.5859,23ZM26,21.5859,24.4141,20,26,18.4141,27.5859,20Z" } }, { "elem": "path", "attrs": { "d": "M17 15H21V17H17z", "transform": "rotate(-90 19 16)" } }, { "elem": "path", "attrs": { "d": "M12 14H18V16H12z", "transform": "rotate(-90 15 15)" } }, { "elem": "path", "attrs": { "d": "M6 12H16V14H6z", "transform": "rotate(-90 11 13)" } }, { "elem": "path", "attrs": { "d": "M12,30H6a2.0021,2.0021,0,0,1-2-2V4A2.0021,2.0021,0,0,1,6,2H22a2.0021,2.0021,0,0,1,2,2V14H22V4H6V28h6Z" } }], "name": "chart--custom", "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="M29.707,19.293l-3-3a.9994.9994,0,0,0-1.414,0L16,25.5859V30h4.4141l9.2929-9.293A.9994.9994,0,0,0,29.707,19.293ZM19.5859,28H18V26.4141l5-5L24.5859,23ZM26,21.5859,24.4141,20,26,18.4141,27.5859,20Z"></path><path d="M17 15H21V17H17z" transform="rotate(-90 19 16)"></path><path d="M12 14H18V16H12z" transform="rotate(-90 15 15)"></path><path d="M6 12H16V14H6z" transform="rotate(-90 11 13)"></path><path d="M12,30H6a2.0021,2.0021,0,0,1-2-2V4A2.0021,2.0021,0,0,1,6,2H22a2.0021,2.0021,0,0,1,2,2V14H22V4H6V28h6Z"></path></svg>` }, "16": { metadata: { "moduleName": "ChartCustom16", "filepath": "chart--custom/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": "M29.707,19.293l-3-3a.9994.9994,0,0,0-1.414,0L16,25.5859V30h4.4141l9.2929-9.293A.9994.9994,0,0,0,29.707,19.293ZM19.5859,28H18V26.4141l5-5L24.5859,23ZM26,21.5859,24.4141,20,26,18.4141,27.5859,20Z" } }, { "elem": "path", "attrs": { "d": "M17 15H21V17H17z", "transform": "rotate(-90 19 16)" } }, { "elem": "path", "attrs": { "d": "M12 14H18V16H12z", "transform": "rotate(-90 15 15)" } }, { "elem": "path", "attrs": { "d": "M6 12H16V14H6z", "transform": "rotate(-90 11 13)" } }, { "elem": "path", "attrs": { "d": "M12,30H6a2.0021,2.0021,0,0,1-2-2V4A2.0021,2.0021,0,0,1,6,2H22a2.0021,2.0021,0,0,1,2,2V14H22V4H6V28h6Z" } }], "name": "chart--custom", "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="M29.707,19.293l-3-3a.9994.9994,0,0,0-1.414,0L16,25.5859V30h4.4141l9.2929-9.293A.9994.9994,0,0,0,29.707,19.293ZM19.5859,28H18V26.4141l5-5L24.5859,23ZM26,21.5859,24.4141,20,26,18.4141,27.5859,20Z"></path><path d="M17 15H21V17H17z" transform="rotate(-90 19 16)"></path><path d="M12 14H18V16H12z" transform="rotate(-90 15 15)"></path><path d="M6 12H16V14H6z" transform="rotate(-90 11 13)"></path><path d="M12,30H6a2.0021,2.0021,0,0,1-2-2V4A2.0021,2.0021,0,0,1,6,2H22a2.0021,2.0021,0,0,1,2,2V14H22V4H6V28h6Z"></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; ChartCustomDirective_1.titleIdCounter++; title.setAttribute("id", `chart-custom-${ChartCustomDirective_1.titleIdCounter}`); svg.appendChild(title); svg.setAttribute("aria-labelledby", `chart-custom-${ChartCustomDirective_1.titleIdCounter}`); } } }; ChartCustomDirective.titleIdCounter = 0; ChartCustomDirective.ctorParameters = () => [ { type: ElementRef } ]; __decorate([ Input(), __metadata("design:type", String) ], ChartCustomDirective.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], ChartCustomDirective.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], ChartCustomDirective.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], ChartCustomDirective.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], ChartCustomDirective.prototype, "isFocusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], ChartCustomDirective.prototype, "size", void 0); ChartCustomDirective = ChartCustomDirective_1 = __decorate([ Directive({ selector: "[ibmIconChartCustom]" }), __metadata("design:paramtypes", [ElementRef]) ], ChartCustomDirective); let ChartCustomModule = class ChartCustomModule { }; ChartCustomModule = __decorate([ NgModule({ declarations: [ ChartCustomComponent, ChartCustomDirective, ], exports: [ ChartCustomComponent, ChartCustomDirective, ] }) ], ChartCustomModule); export { ChartCustomComponent, ChartCustomDirective, ChartCustomModule };