UNPKG

@carbon/icons-angular

Version:

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

174 lines (171 loc) 12.2 kB
import { __decorate, __metadata } from 'tslib'; import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core'; import { getAttributes } from '@carbon/icon-helpers'; var SwimDirective_1; let SwimComponent = class SwimComponent { constructor() { this.focusable = false; } }; __decorate([ Input(), __metadata("design:type", String) ], SwimComponent.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], SwimComponent.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], SwimComponent.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], SwimComponent.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], SwimComponent.prototype, "focusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], SwimComponent.prototype, "innerClass", void 0); __decorate([ Input(), __metadata("design:type", String) ], SwimComponent.prototype, "size", void 0); SwimComponent = __decorate([ Component({ selector: "ibm-icon-swim", template: ` <svg ibmIconSwim [size]="size" [ariaLabel]="ariaLabel" [ariaLabelledby]="ariaLabelledby" [ariaHidden]="ariaHidden" [title]="title" [isFocusable]="focusable" [attr.class]="innerClass"> </svg> ` }) ], SwimComponent); let SwimDirective = SwimDirective_1 = class SwimDirective { constructor(elementRef) { this.elementRef = elementRef; this.isFocusable = false; this.icons = { "32": { metadata: { "moduleName": "Swim32", "filepath": "swim/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 26H28a4.9316 4.9316 0 01-4-1.9873 5.0192 5.0192 0 01-8 0 5.0192 5.0192 0 01-8 0A4.9316 4.9316 0 014 26H2V24H4a3.44 3.44 0 003.0532-2.3215A.9712.9712 0 018 21a1.0069 1.0069 0 01.9487.6838A3.4381 3.4381 0 0012 24a3.44 3.44 0 003.0532-2.3215A.99.99 0 0116 21a1.0069 1.0069 0 01.9487.6838A3.4381 3.4381 0 0020 24a3.44 3.44 0 003.0532-2.3215 1 1 0 011.8955.0053A3.4381 3.4381 0 0028 24h2zM23 17.5859l-8.707-8.707A2.9791 2.9791 0 0012.1714 8H4v2h8.1714a.9933.9933 0 01.7075.293L15.5859 13 10 18.5859 11.4141 20 17 14.4141 21.5859 19zM20 10a4 4 0 114 4A4.0042 4.0042 0 0120 10zm2 0a2 2 0 102-2A2.0023 2.0023 0 0022 10z" } }], "name": "swim", "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 26H28a4.9316 4.9316 0 01-4-1.9873 5.0192 5.0192 0 01-8 0 5.0192 5.0192 0 01-8 0A4.9316 4.9316 0 014 26H2V24H4a3.44 3.44 0 003.0532-2.3215A.9712.9712 0 018 21a1.0069 1.0069 0 01.9487.6838A3.4381 3.4381 0 0012 24a3.44 3.44 0 003.0532-2.3215A.99.99 0 0116 21a1.0069 1.0069 0 01.9487.6838A3.4381 3.4381 0 0020 24a3.44 3.44 0 003.0532-2.3215 1 1 0 011.8955.0053A3.4381 3.4381 0 0028 24h2zM23 17.5859l-8.707-8.707A2.9791 2.9791 0 0012.1714 8H4v2h8.1714a.9933.9933 0 01.7075.293L15.5859 13 10 18.5859 11.4141 20 17 14.4141 21.5859 19zM20 10a4 4 0 114 4A4.0042 4.0042 0 0120 10zm2 0a2 2 0 102-2A2.0023 2.0023 0 0022 10z"></path></svg>` }, "24": { metadata: { "moduleName": "Swim24", "filepath": "swim/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 26H28a4.9316 4.9316 0 01-4-1.9873 5.0192 5.0192 0 01-8 0 5.0192 5.0192 0 01-8 0A4.9316 4.9316 0 014 26H2V24H4a3.44 3.44 0 003.0532-2.3215A.9712.9712 0 018 21a1.0069 1.0069 0 01.9487.6838A3.4381 3.4381 0 0012 24a3.44 3.44 0 003.0532-2.3215A.99.99 0 0116 21a1.0069 1.0069 0 01.9487.6838A3.4381 3.4381 0 0020 24a3.44 3.44 0 003.0532-2.3215 1 1 0 011.8955.0053A3.4381 3.4381 0 0028 24h2zM23 17.5859l-8.707-8.707A2.9791 2.9791 0 0012.1714 8H4v2h8.1714a.9933.9933 0 01.7075.293L15.5859 13 10 18.5859 11.4141 20 17 14.4141 21.5859 19zM20 10a4 4 0 114 4A4.0042 4.0042 0 0120 10zm2 0a2 2 0 102-2A2.0023 2.0023 0 0022 10z" } }], "name": "swim", "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 26H28a4.9316 4.9316 0 01-4-1.9873 5.0192 5.0192 0 01-8 0 5.0192 5.0192 0 01-8 0A4.9316 4.9316 0 014 26H2V24H4a3.44 3.44 0 003.0532-2.3215A.9712.9712 0 018 21a1.0069 1.0069 0 01.9487.6838A3.4381 3.4381 0 0012 24a3.44 3.44 0 003.0532-2.3215A.99.99 0 0116 21a1.0069 1.0069 0 01.9487.6838A3.4381 3.4381 0 0020 24a3.44 3.44 0 003.0532-2.3215 1 1 0 011.8955.0053A3.4381 3.4381 0 0028 24h2zM23 17.5859l-8.707-8.707A2.9791 2.9791 0 0012.1714 8H4v2h8.1714a.9933.9933 0 01.7075.293L15.5859 13 10 18.5859 11.4141 20 17 14.4141 21.5859 19zM20 10a4 4 0 114 4A4.0042 4.0042 0 0120 10zm2 0a2 2 0 102-2A2.0023 2.0023 0 0022 10z"></path></svg>` }, "20": { metadata: { "moduleName": "Swim20", "filepath": "swim/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 26H28a4.9316 4.9316 0 01-4-1.9873 5.0192 5.0192 0 01-8 0 5.0192 5.0192 0 01-8 0A4.9316 4.9316 0 014 26H2V24H4a3.44 3.44 0 003.0532-2.3215A.9712.9712 0 018 21a1.0069 1.0069 0 01.9487.6838A3.4381 3.4381 0 0012 24a3.44 3.44 0 003.0532-2.3215A.99.99 0 0116 21a1.0069 1.0069 0 01.9487.6838A3.4381 3.4381 0 0020 24a3.44 3.44 0 003.0532-2.3215 1 1 0 011.8955.0053A3.4381 3.4381 0 0028 24h2zM23 17.5859l-8.707-8.707A2.9791 2.9791 0 0012.1714 8H4v2h8.1714a.9933.9933 0 01.7075.293L15.5859 13 10 18.5859 11.4141 20 17 14.4141 21.5859 19zM20 10a4 4 0 114 4A4.0042 4.0042 0 0120 10zm2 0a2 2 0 102-2A2.0023 2.0023 0 0022 10z" } }], "name": "swim", "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 26H28a4.9316 4.9316 0 01-4-1.9873 5.0192 5.0192 0 01-8 0 5.0192 5.0192 0 01-8 0A4.9316 4.9316 0 014 26H2V24H4a3.44 3.44 0 003.0532-2.3215A.9712.9712 0 018 21a1.0069 1.0069 0 01.9487.6838A3.4381 3.4381 0 0012 24a3.44 3.44 0 003.0532-2.3215A.99.99 0 0116 21a1.0069 1.0069 0 01.9487.6838A3.4381 3.4381 0 0020 24a3.44 3.44 0 003.0532-2.3215 1 1 0 011.8955.0053A3.4381 3.4381 0 0028 24h2zM23 17.5859l-8.707-8.707A2.9791 2.9791 0 0012.1714 8H4v2h8.1714a.9933.9933 0 01.7075.293L15.5859 13 10 18.5859 11.4141 20 17 14.4141 21.5859 19zM20 10a4 4 0 114 4A4.0042 4.0042 0 0120 10zm2 0a2 2 0 102-2A2.0023 2.0023 0 0022 10z"></path></svg>` }, "16": { metadata: { "moduleName": "Swim16", "filepath": "swim/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 26H28a4.9316 4.9316 0 01-4-1.9873 5.0192 5.0192 0 01-8 0 5.0192 5.0192 0 01-8 0A4.9316 4.9316 0 014 26H2V24H4a3.44 3.44 0 003.0532-2.3215A.9712.9712 0 018 21a1.0069 1.0069 0 01.9487.6838A3.4381 3.4381 0 0012 24a3.44 3.44 0 003.0532-2.3215A.99.99 0 0116 21a1.0069 1.0069 0 01.9487.6838A3.4381 3.4381 0 0020 24a3.44 3.44 0 003.0532-2.3215 1 1 0 011.8955.0053A3.4381 3.4381 0 0028 24h2zM23 17.5859l-8.707-8.707A2.9791 2.9791 0 0012.1714 8H4v2h8.1714a.9933.9933 0 01.7075.293L15.5859 13 10 18.5859 11.4141 20 17 14.4141 21.5859 19zM20 10a4 4 0 114 4A4.0042 4.0042 0 0120 10zm2 0a2 2 0 102-2A2.0023 2.0023 0 0022 10z" } }], "name": "swim", "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 26H28a4.9316 4.9316 0 01-4-1.9873 5.0192 5.0192 0 01-8 0 5.0192 5.0192 0 01-8 0A4.9316 4.9316 0 014 26H2V24H4a3.44 3.44 0 003.0532-2.3215A.9712.9712 0 018 21a1.0069 1.0069 0 01.9487.6838A3.4381 3.4381 0 0012 24a3.44 3.44 0 003.0532-2.3215A.99.99 0 0116 21a1.0069 1.0069 0 01.9487.6838A3.4381 3.4381 0 0020 24a3.44 3.44 0 003.0532-2.3215 1 1 0 011.8955.0053A3.4381 3.4381 0 0028 24h2zM23 17.5859l-8.707-8.707A2.9791 2.9791 0 0012.1714 8H4v2h8.1714a.9933.9933 0 01.7075.293L15.5859 13 10 18.5859 11.4141 20 17 14.4141 21.5859 19zM20 10a4 4 0 114 4A4.0042 4.0042 0 0120 10zm2 0a2 2 0 102-2A2.0023 2.0023 0 0022 10z"></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; SwimDirective_1.titleIdCounter++; title.setAttribute("id", `swim-${SwimDirective_1.titleIdCounter}`); svg.appendChild(title); svg.setAttribute("aria-labelledby", `swim-${SwimDirective_1.titleIdCounter}`); } } }; SwimDirective.titleIdCounter = 0; SwimDirective.ctorParameters = () => [ { type: ElementRef } ]; __decorate([ Input(), __metadata("design:type", String) ], SwimDirective.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], SwimDirective.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], SwimDirective.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], SwimDirective.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], SwimDirective.prototype, "isFocusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], SwimDirective.prototype, "size", void 0); SwimDirective = SwimDirective_1 = __decorate([ Directive({ selector: "[ibmIconSwim]" }), __metadata("design:paramtypes", [ElementRef]) ], SwimDirective); let SwimModule = class SwimModule { }; SwimModule = __decorate([ NgModule({ declarations: [ SwimComponent, SwimDirective, ], exports: [ SwimComponent, SwimDirective, ] }) ], SwimModule); export { SwimComponent, SwimDirective, SwimModule };