UNPKG

@carbon/icons-angular

Version:

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

174 lines (171 loc) 8.9 kB
import { __decorate, __metadata } from 'tslib'; import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core'; import { getAttributes } from '@carbon/icon-helpers'; var DvrDirective_1; let DvrComponent = class DvrComponent { constructor() { this.focusable = false; } }; __decorate([ Input(), __metadata("design:type", String) ], DvrComponent.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], DvrComponent.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], DvrComponent.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], DvrComponent.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], DvrComponent.prototype, "focusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], DvrComponent.prototype, "innerClass", void 0); __decorate([ Input(), __metadata("design:type", String) ], DvrComponent.prototype, "size", void 0); DvrComponent = __decorate([ Component({ selector: "ibm-icon-dvr", template: ` <svg ibmIconDvr [size]="size" [ariaLabel]="ariaLabel" [ariaLabelledby]="ariaLabelledby" [ariaHidden]="ariaHidden" [title]="title" [isFocusable]="focusable" [attr.class]="innerClass"> </svg> ` }) ], DvrComponent); let DvrDirective = DvrDirective_1 = class DvrDirective { constructor(elementRef) { this.elementRef = elementRef; this.isFocusable = false; this.icons = { "32": { metadata: { "moduleName": "Dvr32", "filepath": "DVR/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 15V11a2 2 0 00-2-2H22V23h2V17h1.48l2.34 6H30l-2.33-6H28A2 2 0 0030 15zm-6-4h4v4H24zM18 9L16 22 14 9 12 9 14.52 23 17.48 23 20 9 18 9zM6 23H2V9H6a4 4 0 014 4v6A4 4 0 016 23zM4 21H6a2 2 0 002-2V13a2 2 0 00-2-2H4z" } }], "name": "DVR", "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 15V11a2 2 0 00-2-2H22V23h2V17h1.48l2.34 6H30l-2.33-6H28A2 2 0 0030 15zm-6-4h4v4H24zM18 9L16 22 14 9 12 9 14.52 23 17.48 23 20 9 18 9zM6 23H2V9H6a4 4 0 014 4v6A4 4 0 016 23zM4 21H6a2 2 0 002-2V13a2 2 0 00-2-2H4z"></path></svg>` }, "24": { metadata: { "moduleName": "Dvr24", "filepath": "DVR/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 15V11a2 2 0 00-2-2H22V23h2V17h1.48l2.34 6H30l-2.33-6H28A2 2 0 0030 15zm-6-4h4v4H24zM18 9L16 22 14 9 12 9 14.52 23 17.48 23 20 9 18 9zM6 23H2V9H6a4 4 0 014 4v6A4 4 0 016 23zM4 21H6a2 2 0 002-2V13a2 2 0 00-2-2H4z" } }], "name": "DVR", "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 15V11a2 2 0 00-2-2H22V23h2V17h1.48l2.34 6H30l-2.33-6H28A2 2 0 0030 15zm-6-4h4v4H24zM18 9L16 22 14 9 12 9 14.52 23 17.48 23 20 9 18 9zM6 23H2V9H6a4 4 0 014 4v6A4 4 0 016 23zM4 21H6a2 2 0 002-2V13a2 2 0 00-2-2H4z"></path></svg>` }, "20": { metadata: { "moduleName": "Dvr20", "filepath": "DVR/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 15V11a2 2 0 00-2-2H22V23h2V17h1.48l2.34 6H30l-2.33-6H28A2 2 0 0030 15zm-6-4h4v4H24zM18 9L16 22 14 9 12 9 14.52 23 17.48 23 20 9 18 9zM6 23H2V9H6a4 4 0 014 4v6A4 4 0 016 23zM4 21H6a2 2 0 002-2V13a2 2 0 00-2-2H4z" } }], "name": "DVR", "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 15V11a2 2 0 00-2-2H22V23h2V17h1.48l2.34 6H30l-2.33-6H28A2 2 0 0030 15zm-6-4h4v4H24zM18 9L16 22 14 9 12 9 14.52 23 17.48 23 20 9 18 9zM6 23H2V9H6a4 4 0 014 4v6A4 4 0 016 23zM4 21H6a2 2 0 002-2V13a2 2 0 00-2-2H4z"></path></svg>` }, "16": { metadata: { "moduleName": "Dvr16", "filepath": "DVR/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 15V11a2 2 0 00-2-2H22V23h2V17h1.48l2.34 6H30l-2.33-6H28A2 2 0 0030 15zm-6-4h4v4H24zM18 9L16 22 14 9 12 9 14.52 23 17.48 23 20 9 18 9zM6 23H2V9H6a4 4 0 014 4v6A4 4 0 016 23zM4 21H6a2 2 0 002-2V13a2 2 0 00-2-2H4z" } }], "name": "DVR", "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 15V11a2 2 0 00-2-2H22V23h2V17h1.48l2.34 6H30l-2.33-6H28A2 2 0 0030 15zm-6-4h4v4H24zM18 9L16 22 14 9 12 9 14.52 23 17.48 23 20 9 18 9zM6 23H2V9H6a4 4 0 014 4v6A4 4 0 016 23zM4 21H6a2 2 0 002-2V13a2 2 0 00-2-2H4z"></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; DvrDirective_1.titleIdCounter++; title.setAttribute("id", `dvr-${DvrDirective_1.titleIdCounter}`); svg.appendChild(title); svg.setAttribute("aria-labelledby", `dvr-${DvrDirective_1.titleIdCounter}`); } } }; DvrDirective.titleIdCounter = 0; DvrDirective.ctorParameters = () => [ { type: ElementRef } ]; __decorate([ Input(), __metadata("design:type", String) ], DvrDirective.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], DvrDirective.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], DvrDirective.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], DvrDirective.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], DvrDirective.prototype, "isFocusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], DvrDirective.prototype, "size", void 0); DvrDirective = DvrDirective_1 = __decorate([ Directive({ selector: "[ibmIconDvr]" }), __metadata("design:paramtypes", [ElementRef]) ], DvrDirective); let DvrModule = class DvrModule { }; DvrModule = __decorate([ NgModule({ declarations: [ DvrComponent, DvrDirective, ], exports: [ DvrComponent, DvrDirective, ] }) ], DvrModule); export { DvrComponent, DvrDirective, DvrModule };