UNPKG

@carbon/icons-angular

Version:

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

174 lines (171 loc) 11.4 kB
import { __decorate, __metadata } from 'tslib'; import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core'; import { getAttributes } from '@carbon/icon-helpers'; var DataConnectedDirective_1; let DataConnectedComponent = class DataConnectedComponent { constructor() { this.focusable = false; } }; __decorate([ Input(), __metadata("design:type", String) ], DataConnectedComponent.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], DataConnectedComponent.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], DataConnectedComponent.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], DataConnectedComponent.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], DataConnectedComponent.prototype, "focusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], DataConnectedComponent.prototype, "innerClass", void 0); __decorate([ Input(), __metadata("design:type", String) ], DataConnectedComponent.prototype, "size", void 0); DataConnectedComponent = __decorate([ Component({ selector: "ibm-icon-data-connected", template: ` <svg ibmIconDataConnected [size]="size" [ariaLabel]="ariaLabel" [ariaLabelledby]="ariaLabelledby" [ariaHidden]="ariaHidden" [title]="title" [isFocusable]="focusable" [attr.class]="innerClass"> </svg> ` }) ], DataConnectedComponent); let DataConnectedDirective = DataConnectedDirective_1 = class DataConnectedDirective { constructor(elementRef) { this.elementRef = elementRef; this.isFocusable = false; this.icons = { "32": { metadata: { "moduleName": "DataConnected32", "filepath": "data--connected/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 30L24 30 24 28 28 28 28 4 24 4 24 2 30 2 30 30z" } }, { "elem": "path", "attrs": { "d": "M24.91,19.59a4.51,4.51,0,0,0-2.66-3.24,4.55,4.55,0,0,0-3.5,0,4.94,4.94,0,0,0-.64.35L15.3,13.89a4.53,4.53,0,1,0-1.41,1.41l2.81,2.81a4.48,4.48,0,0,0-.61,3.3,4.51,4.51,0,0,0,2.66,3.24,4.55,4.55,0,0,0,3.5,0,4.51,4.51,0,0,0,2.66-3.24,4.65,4.65,0,0,0,0-1.82ZM11.5,14A2.5,2.5,0,1,1,14,11.5,2.5,2.5,0,0,1,11.5,14Z" } }, { "elem": "path", "attrs": { "d": "M8 30L2 30 2 2 8 2 8 4 4 4 4 28 8 28 8 30z" } }], "name": "data--connected", "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 30L24 30 24 28 28 28 28 4 24 4 24 2 30 2 30 30z"></path><path d="M24.91,19.59a4.51,4.51,0,0,0-2.66-3.24,4.55,4.55,0,0,0-3.5,0,4.94,4.94,0,0,0-.64.35L15.3,13.89a4.53,4.53,0,1,0-1.41,1.41l2.81,2.81a4.48,4.48,0,0,0-.61,3.3,4.51,4.51,0,0,0,2.66,3.24,4.55,4.55,0,0,0,3.5,0,4.51,4.51,0,0,0,2.66-3.24,4.65,4.65,0,0,0,0-1.82ZM11.5,14A2.5,2.5,0,1,1,14,11.5,2.5,2.5,0,0,1,11.5,14Z"></path><path d="M8 30L2 30 2 2 8 2 8 4 4 4 4 28 8 28 8 30z"></path></svg>` }, "24": { metadata: { "moduleName": "DataConnected24", "filepath": "data--connected/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 30L24 30 24 28 28 28 28 4 24 4 24 2 30 2 30 30z" } }, { "elem": "path", "attrs": { "d": "M24.91,19.59a4.51,4.51,0,0,0-2.66-3.24,4.55,4.55,0,0,0-3.5,0,4.94,4.94,0,0,0-.64.35L15.3,13.89a4.53,4.53,0,1,0-1.41,1.41l2.81,2.81a4.48,4.48,0,0,0-.61,3.3,4.51,4.51,0,0,0,2.66,3.24,4.55,4.55,0,0,0,3.5,0,4.51,4.51,0,0,0,2.66-3.24,4.65,4.65,0,0,0,0-1.82ZM11.5,14A2.5,2.5,0,1,1,14,11.5,2.5,2.5,0,0,1,11.5,14Z" } }, { "elem": "path", "attrs": { "d": "M8 30L2 30 2 2 8 2 8 4 4 4 4 28 8 28 8 30z" } }], "name": "data--connected", "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 30L24 30 24 28 28 28 28 4 24 4 24 2 30 2 30 30z"></path><path d="M24.91,19.59a4.51,4.51,0,0,0-2.66-3.24,4.55,4.55,0,0,0-3.5,0,4.94,4.94,0,0,0-.64.35L15.3,13.89a4.53,4.53,0,1,0-1.41,1.41l2.81,2.81a4.48,4.48,0,0,0-.61,3.3,4.51,4.51,0,0,0,2.66,3.24,4.55,4.55,0,0,0,3.5,0,4.51,4.51,0,0,0,2.66-3.24,4.65,4.65,0,0,0,0-1.82ZM11.5,14A2.5,2.5,0,1,1,14,11.5,2.5,2.5,0,0,1,11.5,14Z"></path><path d="M8 30L2 30 2 2 8 2 8 4 4 4 4 28 8 28 8 30z"></path></svg>` }, "20": { metadata: { "moduleName": "DataConnected20", "filepath": "data--connected/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 30L24 30 24 28 28 28 28 4 24 4 24 2 30 2 30 30z" } }, { "elem": "path", "attrs": { "d": "M24.91,19.59a4.51,4.51,0,0,0-2.66-3.24,4.55,4.55,0,0,0-3.5,0,4.94,4.94,0,0,0-.64.35L15.3,13.89a4.53,4.53,0,1,0-1.41,1.41l2.81,2.81a4.48,4.48,0,0,0-.61,3.3,4.51,4.51,0,0,0,2.66,3.24,4.55,4.55,0,0,0,3.5,0,4.51,4.51,0,0,0,2.66-3.24,4.65,4.65,0,0,0,0-1.82ZM11.5,14A2.5,2.5,0,1,1,14,11.5,2.5,2.5,0,0,1,11.5,14Z" } }, { "elem": "path", "attrs": { "d": "M8 30L2 30 2 2 8 2 8 4 4 4 4 28 8 28 8 30z" } }], "name": "data--connected", "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 30L24 30 24 28 28 28 28 4 24 4 24 2 30 2 30 30z"></path><path d="M24.91,19.59a4.51,4.51,0,0,0-2.66-3.24,4.55,4.55,0,0,0-3.5,0,4.94,4.94,0,0,0-.64.35L15.3,13.89a4.53,4.53,0,1,0-1.41,1.41l2.81,2.81a4.48,4.48,0,0,0-.61,3.3,4.51,4.51,0,0,0,2.66,3.24,4.55,4.55,0,0,0,3.5,0,4.51,4.51,0,0,0,2.66-3.24,4.65,4.65,0,0,0,0-1.82ZM11.5,14A2.5,2.5,0,1,1,14,11.5,2.5,2.5,0,0,1,11.5,14Z"></path><path d="M8 30L2 30 2 2 8 2 8 4 4 4 4 28 8 28 8 30z"></path></svg>` }, "16": { metadata: { "moduleName": "DataConnected16", "filepath": "data--connected/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 30L24 30 24 28 28 28 28 4 24 4 24 2 30 2 30 30z" } }, { "elem": "path", "attrs": { "d": "M24.91,19.59a4.51,4.51,0,0,0-2.66-3.24,4.55,4.55,0,0,0-3.5,0,4.94,4.94,0,0,0-.64.35L15.3,13.89a4.53,4.53,0,1,0-1.41,1.41l2.81,2.81a4.48,4.48,0,0,0-.61,3.3,4.51,4.51,0,0,0,2.66,3.24,4.55,4.55,0,0,0,3.5,0,4.51,4.51,0,0,0,2.66-3.24,4.65,4.65,0,0,0,0-1.82ZM11.5,14A2.5,2.5,0,1,1,14,11.5,2.5,2.5,0,0,1,11.5,14Z" } }, { "elem": "path", "attrs": { "d": "M8 30L2 30 2 2 8 2 8 4 4 4 4 28 8 28 8 30z" } }], "name": "data--connected", "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 30L24 30 24 28 28 28 28 4 24 4 24 2 30 2 30 30z"></path><path d="M24.91,19.59a4.51,4.51,0,0,0-2.66-3.24,4.55,4.55,0,0,0-3.5,0,4.94,4.94,0,0,0-.64.35L15.3,13.89a4.53,4.53,0,1,0-1.41,1.41l2.81,2.81a4.48,4.48,0,0,0-.61,3.3,4.51,4.51,0,0,0,2.66,3.24,4.55,4.55,0,0,0,3.5,0,4.51,4.51,0,0,0,2.66-3.24,4.65,4.65,0,0,0,0-1.82ZM11.5,14A2.5,2.5,0,1,1,14,11.5,2.5,2.5,0,0,1,11.5,14Z"></path><path d="M8 30L2 30 2 2 8 2 8 4 4 4 4 28 8 28 8 30z"></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; DataConnectedDirective_1.titleIdCounter++; title.setAttribute("id", `data-connected-${DataConnectedDirective_1.titleIdCounter}`); svg.appendChild(title); svg.setAttribute("aria-labelledby", `data-connected-${DataConnectedDirective_1.titleIdCounter}`); } } }; DataConnectedDirective.titleIdCounter = 0; DataConnectedDirective.ctorParameters = () => [ { type: ElementRef } ]; __decorate([ Input(), __metadata("design:type", String) ], DataConnectedDirective.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], DataConnectedDirective.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], DataConnectedDirective.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], DataConnectedDirective.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], DataConnectedDirective.prototype, "isFocusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], DataConnectedDirective.prototype, "size", void 0); DataConnectedDirective = DataConnectedDirective_1 = __decorate([ Directive({ selector: "[ibmIconDataConnected]" }), __metadata("design:paramtypes", [ElementRef]) ], DataConnectedDirective); let DataConnectedModule = class DataConnectedModule { }; DataConnectedModule = __decorate([ NgModule({ declarations: [ DataConnectedComponent, DataConnectedDirective, ], exports: [ DataConnectedComponent, DataConnectedDirective, ] }) ], DataConnectedModule); export { DataConnectedComponent, DataConnectedDirective, DataConnectedModule };