UNPKG

@carbon/icons-angular

Version:

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

174 lines (171 loc) 12.5 kB
import { __decorate, __metadata } from 'tslib'; import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core'; import { getAttributes } from '@carbon/icon-helpers'; var TouchInteractionDirective_1; let TouchInteractionComponent = class TouchInteractionComponent { constructor() { this.focusable = false; } }; __decorate([ Input(), __metadata("design:type", String) ], TouchInteractionComponent.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], TouchInteractionComponent.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], TouchInteractionComponent.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], TouchInteractionComponent.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], TouchInteractionComponent.prototype, "focusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], TouchInteractionComponent.prototype, "innerClass", void 0); __decorate([ Input(), __metadata("design:type", String) ], TouchInteractionComponent.prototype, "size", void 0); TouchInteractionComponent = __decorate([ Component({ selector: "ibm-icon-touch-interaction", template: ` <svg ibmIconTouchInteraction [size]="size" [ariaLabel]="ariaLabel" [ariaLabelledby]="ariaLabelledby" [ariaHidden]="ariaHidden" [title]="title" [isFocusable]="focusable" [attr.class]="innerClass"> </svg> ` }) ], TouchInteractionComponent); let TouchInteractionDirective = TouchInteractionDirective_1 = class TouchInteractionDirective { constructor(elementRef) { this.elementRef = elementRef; this.isFocusable = false; this.icons = { "32": { metadata: { "moduleName": "TouchInteraction32", "filepath": "touch--interaction/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": "M26,21V20a1,1,0,0,1,2,0V30h2V20a3.0033,3.0033,0,0,0-3-3,2.964,2.964,0,0,0-1.4708.4014,2.9541,2.9541,0,0,0-4-1A2.9934,2.9934,0,0,0,19,15a2.96,2.96,0,0,0-1,.1846L18,10h0a3,3,0,0,0-6,0V21.1045L9.7651,19.5752l-.0008.001a2.999,2.999,0,0,0-3.881,4.55L12.3223,30l1.3479-1.478L7.2915,22.7036A.9908.9908,0,0,1,7,22a1.0005,1.0005,0,0,1,1.6-.8008L14,24.8955V10a1,1,0,0,1,2,0h0V21h2V18a1,1,0,0,1,2,0v3h2V19a1,1,0,0,1,2,0v2Z" } }, { "elem": "path", "attrs": { "d": "M28,12H22V10h6V4H4v6H8v2H4a2.0021,2.0021,0,0,1-2-2V4A2.0021,2.0021,0,0,1,4,2H28a2.0021,2.0021,0,0,1,2,2v6A2.0021,2.0021,0,0,1,28,12Z" } }], "name": "touch--interaction", "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="M26,21V20a1,1,0,0,1,2,0V30h2V20a3.0033,3.0033,0,0,0-3-3,2.964,2.964,0,0,0-1.4708.4014,2.9541,2.9541,0,0,0-4-1A2.9934,2.9934,0,0,0,19,15a2.96,2.96,0,0,0-1,.1846L18,10h0a3,3,0,0,0-6,0V21.1045L9.7651,19.5752l-.0008.001a2.999,2.999,0,0,0-3.881,4.55L12.3223,30l1.3479-1.478L7.2915,22.7036A.9908.9908,0,0,1,7,22a1.0005,1.0005,0,0,1,1.6-.8008L14,24.8955V10a1,1,0,0,1,2,0h0V21h2V18a1,1,0,0,1,2,0v3h2V19a1,1,0,0,1,2,0v2Z"></path><path d="M28,12H22V10h6V4H4v6H8v2H4a2.0021,2.0021,0,0,1-2-2V4A2.0021,2.0021,0,0,1,4,2H28a2.0021,2.0021,0,0,1,2,2v6A2.0021,2.0021,0,0,1,28,12Z"></path></svg>` }, "24": { metadata: { "moduleName": "TouchInteraction24", "filepath": "touch--interaction/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": "M26,21V20a1,1,0,0,1,2,0V30h2V20a3.0033,3.0033,0,0,0-3-3,2.964,2.964,0,0,0-1.4708.4014,2.9541,2.9541,0,0,0-4-1A2.9934,2.9934,0,0,0,19,15a2.96,2.96,0,0,0-1,.1846L18,10h0a3,3,0,0,0-6,0V21.1045L9.7651,19.5752l-.0008.001a2.999,2.999,0,0,0-3.881,4.55L12.3223,30l1.3479-1.478L7.2915,22.7036A.9908.9908,0,0,1,7,22a1.0005,1.0005,0,0,1,1.6-.8008L14,24.8955V10a1,1,0,0,1,2,0h0V21h2V18a1,1,0,0,1,2,0v3h2V19a1,1,0,0,1,2,0v2Z" } }, { "elem": "path", "attrs": { "d": "M28,12H22V10h6V4H4v6H8v2H4a2.0021,2.0021,0,0,1-2-2V4A2.0021,2.0021,0,0,1,4,2H28a2.0021,2.0021,0,0,1,2,2v6A2.0021,2.0021,0,0,1,28,12Z" } }], "name": "touch--interaction", "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="M26,21V20a1,1,0,0,1,2,0V30h2V20a3.0033,3.0033,0,0,0-3-3,2.964,2.964,0,0,0-1.4708.4014,2.9541,2.9541,0,0,0-4-1A2.9934,2.9934,0,0,0,19,15a2.96,2.96,0,0,0-1,.1846L18,10h0a3,3,0,0,0-6,0V21.1045L9.7651,19.5752l-.0008.001a2.999,2.999,0,0,0-3.881,4.55L12.3223,30l1.3479-1.478L7.2915,22.7036A.9908.9908,0,0,1,7,22a1.0005,1.0005,0,0,1,1.6-.8008L14,24.8955V10a1,1,0,0,1,2,0h0V21h2V18a1,1,0,0,1,2,0v3h2V19a1,1,0,0,1,2,0v2Z"></path><path d="M28,12H22V10h6V4H4v6H8v2H4a2.0021,2.0021,0,0,1-2-2V4A2.0021,2.0021,0,0,1,4,2H28a2.0021,2.0021,0,0,1,2,2v6A2.0021,2.0021,0,0,1,28,12Z"></path></svg>` }, "20": { metadata: { "moduleName": "TouchInteraction20", "filepath": "touch--interaction/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": "M26,21V20a1,1,0,0,1,2,0V30h2V20a3.0033,3.0033,0,0,0-3-3,2.964,2.964,0,0,0-1.4708.4014,2.9541,2.9541,0,0,0-4-1A2.9934,2.9934,0,0,0,19,15a2.96,2.96,0,0,0-1,.1846L18,10h0a3,3,0,0,0-6,0V21.1045L9.7651,19.5752l-.0008.001a2.999,2.999,0,0,0-3.881,4.55L12.3223,30l1.3479-1.478L7.2915,22.7036A.9908.9908,0,0,1,7,22a1.0005,1.0005,0,0,1,1.6-.8008L14,24.8955V10a1,1,0,0,1,2,0h0V21h2V18a1,1,0,0,1,2,0v3h2V19a1,1,0,0,1,2,0v2Z" } }, { "elem": "path", "attrs": { "d": "M28,12H22V10h6V4H4v6H8v2H4a2.0021,2.0021,0,0,1-2-2V4A2.0021,2.0021,0,0,1,4,2H28a2.0021,2.0021,0,0,1,2,2v6A2.0021,2.0021,0,0,1,28,12Z" } }], "name": "touch--interaction", "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="M26,21V20a1,1,0,0,1,2,0V30h2V20a3.0033,3.0033,0,0,0-3-3,2.964,2.964,0,0,0-1.4708.4014,2.9541,2.9541,0,0,0-4-1A2.9934,2.9934,0,0,0,19,15a2.96,2.96,0,0,0-1,.1846L18,10h0a3,3,0,0,0-6,0V21.1045L9.7651,19.5752l-.0008.001a2.999,2.999,0,0,0-3.881,4.55L12.3223,30l1.3479-1.478L7.2915,22.7036A.9908.9908,0,0,1,7,22a1.0005,1.0005,0,0,1,1.6-.8008L14,24.8955V10a1,1,0,0,1,2,0h0V21h2V18a1,1,0,0,1,2,0v3h2V19a1,1,0,0,1,2,0v2Z"></path><path d="M28,12H22V10h6V4H4v6H8v2H4a2.0021,2.0021,0,0,1-2-2V4A2.0021,2.0021,0,0,1,4,2H28a2.0021,2.0021,0,0,1,2,2v6A2.0021,2.0021,0,0,1,28,12Z"></path></svg>` }, "16": { metadata: { "moduleName": "TouchInteraction16", "filepath": "touch--interaction/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": "M26,21V20a1,1,0,0,1,2,0V30h2V20a3.0033,3.0033,0,0,0-3-3,2.964,2.964,0,0,0-1.4708.4014,2.9541,2.9541,0,0,0-4-1A2.9934,2.9934,0,0,0,19,15a2.96,2.96,0,0,0-1,.1846L18,10h0a3,3,0,0,0-6,0V21.1045L9.7651,19.5752l-.0008.001a2.999,2.999,0,0,0-3.881,4.55L12.3223,30l1.3479-1.478L7.2915,22.7036A.9908.9908,0,0,1,7,22a1.0005,1.0005,0,0,1,1.6-.8008L14,24.8955V10a1,1,0,0,1,2,0h0V21h2V18a1,1,0,0,1,2,0v3h2V19a1,1,0,0,1,2,0v2Z" } }, { "elem": "path", "attrs": { "d": "M28,12H22V10h6V4H4v6H8v2H4a2.0021,2.0021,0,0,1-2-2V4A2.0021,2.0021,0,0,1,4,2H28a2.0021,2.0021,0,0,1,2,2v6A2.0021,2.0021,0,0,1,28,12Z" } }], "name": "touch--interaction", "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="M26,21V20a1,1,0,0,1,2,0V30h2V20a3.0033,3.0033,0,0,0-3-3,2.964,2.964,0,0,0-1.4708.4014,2.9541,2.9541,0,0,0-4-1A2.9934,2.9934,0,0,0,19,15a2.96,2.96,0,0,0-1,.1846L18,10h0a3,3,0,0,0-6,0V21.1045L9.7651,19.5752l-.0008.001a2.999,2.999,0,0,0-3.881,4.55L12.3223,30l1.3479-1.478L7.2915,22.7036A.9908.9908,0,0,1,7,22a1.0005,1.0005,0,0,1,1.6-.8008L14,24.8955V10a1,1,0,0,1,2,0h0V21h2V18a1,1,0,0,1,2,0v3h2V19a1,1,0,0,1,2,0v2Z"></path><path d="M28,12H22V10h6V4H4v6H8v2H4a2.0021,2.0021,0,0,1-2-2V4A2.0021,2.0021,0,0,1,4,2H28a2.0021,2.0021,0,0,1,2,2v6A2.0021,2.0021,0,0,1,28,12Z"></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; TouchInteractionDirective_1.titleIdCounter++; title.setAttribute("id", `touch-interaction-${TouchInteractionDirective_1.titleIdCounter}`); svg.appendChild(title); svg.setAttribute("aria-labelledby", `touch-interaction-${TouchInteractionDirective_1.titleIdCounter}`); } } }; TouchInteractionDirective.titleIdCounter = 0; TouchInteractionDirective.ctorParameters = () => [ { type: ElementRef } ]; __decorate([ Input(), __metadata("design:type", String) ], TouchInteractionDirective.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], TouchInteractionDirective.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], TouchInteractionDirective.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], TouchInteractionDirective.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], TouchInteractionDirective.prototype, "isFocusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], TouchInteractionDirective.prototype, "size", void 0); TouchInteractionDirective = TouchInteractionDirective_1 = __decorate([ Directive({ selector: "[ibmIconTouchInteraction]" }), __metadata("design:paramtypes", [ElementRef]) ], TouchInteractionDirective); let TouchInteractionModule = class TouchInteractionModule { }; TouchInteractionModule = __decorate([ NgModule({ declarations: [ TouchInteractionComponent, TouchInteractionDirective, ], exports: [ TouchInteractionComponent, TouchInteractionDirective, ] }) ], TouchInteractionModule); export { TouchInteractionComponent, TouchInteractionDirective, TouchInteractionModule };