UNPKG

@carbon/icons-angular

Version:

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

174 lines (171 loc) 8.97 kB
import { __decorate, __metadata } from 'tslib'; import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core'; import { getAttributes } from '@carbon/icon-helpers'; var ForumDirective_1; let ForumComponent = class ForumComponent { constructor() { this.focusable = false; } }; __decorate([ Input(), __metadata("design:type", String) ], ForumComponent.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], ForumComponent.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], ForumComponent.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], ForumComponent.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], ForumComponent.prototype, "focusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], ForumComponent.prototype, "innerClass", void 0); __decorate([ Input(), __metadata("design:type", String) ], ForumComponent.prototype, "size", void 0); ForumComponent = __decorate([ Component({ selector: "ibm-icon-forum", template: ` <svg ibmIconForum [size]="size" [ariaLabel]="ariaLabel" [ariaLabelledby]="ariaLabelledby" [ariaHidden]="ariaHidden" [title]="title" [isFocusable]="focusable" [attr.class]="innerClass"> </svg> ` }) ], ForumComponent); let ForumDirective = ForumDirective_1 = class ForumDirective { constructor(elementRef) { this.elementRef = elementRef; this.isFocusable = false; this.icons = { "32": { metadata: { "moduleName": "Forum32", "filepath": "forum/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": "M28,6H8C6.8,6,6,6.8,6,8v14c0,1.2,0.8,2,2,2h8v-2H8V8h20v14h-7.2L16,28.8l1.6,1.2l4.2-6H28c1.2,0,2-0.8,2-2V8\tC30,6.8,29.2,6,28,6z" } }, { "elem": "path", "attrs": { "d": "M4,18H2V5c0-1.7,1.3-3,3-3h13v2H5C4.4,4,4,4.4,4,5V18z" } }], "name": "forum", "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="M28,6H8C6.8,6,6,6.8,6,8v14c0,1.2,0.8,2,2,2h8v-2H8V8h20v14h-7.2L16,28.8l1.6,1.2l4.2-6H28c1.2,0,2-0.8,2-2V8 C30,6.8,29.2,6,28,6z"></path><path d="M4,18H2V5c0-1.7,1.3-3,3-3h13v2H5C4.4,4,4,4.4,4,5V18z"></path></svg>` }, "24": { metadata: { "moduleName": "Forum24", "filepath": "forum/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": "M28,6H8C6.8,6,6,6.8,6,8v14c0,1.2,0.8,2,2,2h8v-2H8V8h20v14h-7.2L16,28.8l1.6,1.2l4.2-6H28c1.2,0,2-0.8,2-2V8\tC30,6.8,29.2,6,28,6z" } }, { "elem": "path", "attrs": { "d": "M4,18H2V5c0-1.7,1.3-3,3-3h13v2H5C4.4,4,4,4.4,4,5V18z" } }], "name": "forum", "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="M28,6H8C6.8,6,6,6.8,6,8v14c0,1.2,0.8,2,2,2h8v-2H8V8h20v14h-7.2L16,28.8l1.6,1.2l4.2-6H28c1.2,0,2-0.8,2-2V8 C30,6.8,29.2,6,28,6z"></path><path d="M4,18H2V5c0-1.7,1.3-3,3-3h13v2H5C4.4,4,4,4.4,4,5V18z"></path></svg>` }, "20": { metadata: { "moduleName": "Forum20", "filepath": "forum/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": "M28,6H8C6.8,6,6,6.8,6,8v14c0,1.2,0.8,2,2,2h8v-2H8V8h20v14h-7.2L16,28.8l1.6,1.2l4.2-6H28c1.2,0,2-0.8,2-2V8\tC30,6.8,29.2,6,28,6z" } }, { "elem": "path", "attrs": { "d": "M4,18H2V5c0-1.7,1.3-3,3-3h13v2H5C4.4,4,4,4.4,4,5V18z" } }], "name": "forum", "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="M28,6H8C6.8,6,6,6.8,6,8v14c0,1.2,0.8,2,2,2h8v-2H8V8h20v14h-7.2L16,28.8l1.6,1.2l4.2-6H28c1.2,0,2-0.8,2-2V8 C30,6.8,29.2,6,28,6z"></path><path d="M4,18H2V5c0-1.7,1.3-3,3-3h13v2H5C4.4,4,4,4.4,4,5V18z"></path></svg>` }, "16": { metadata: { "moduleName": "Forum16", "filepath": "forum/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": "M28,6H8C6.8,6,6,6.8,6,8v14c0,1.2,0.8,2,2,2h8v-2H8V8h20v14h-7.2L16,28.8l1.6,1.2l4.2-6H28c1.2,0,2-0.8,2-2V8\tC30,6.8,29.2,6,28,6z" } }, { "elem": "path", "attrs": { "d": "M4,18H2V5c0-1.7,1.3-3,3-3h13v2H5C4.4,4,4,4.4,4,5V18z" } }], "name": "forum", "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="M28,6H8C6.8,6,6,6.8,6,8v14c0,1.2,0.8,2,2,2h8v-2H8V8h20v14h-7.2L16,28.8l1.6,1.2l4.2-6H28c1.2,0,2-0.8,2-2V8 C30,6.8,29.2,6,28,6z"></path><path d="M4,18H2V5c0-1.7,1.3-3,3-3h13v2H5C4.4,4,4,4.4,4,5V18z"></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; ForumDirective_1.titleIdCounter++; title.setAttribute("id", `forum-${ForumDirective_1.titleIdCounter}`); svg.appendChild(title); svg.setAttribute("aria-labelledby", `forum-${ForumDirective_1.titleIdCounter}`); } } }; ForumDirective.titleIdCounter = 0; ForumDirective.ctorParameters = () => [ { type: ElementRef } ]; __decorate([ Input(), __metadata("design:type", String) ], ForumDirective.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], ForumDirective.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], ForumDirective.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], ForumDirective.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], ForumDirective.prototype, "isFocusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], ForumDirective.prototype, "size", void 0); ForumDirective = ForumDirective_1 = __decorate([ Directive({ selector: "[ibmIconForum]" }), __metadata("design:paramtypes", [ElementRef]) ], ForumDirective); let ForumModule = class ForumModule { }; ForumModule = __decorate([ NgModule({ declarations: [ ForumComponent, ForumDirective, ], exports: [ ForumComponent, ForumDirective, ] }) ], ForumModule); export { ForumComponent, ForumDirective, ForumModule };