UNPKG

@carbon/icons-angular

Version:

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

174 lines (171 loc) 9.44 kB
import { __decorate, __metadata } from 'tslib'; import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core'; import { getAttributes } from '@carbon/icon-helpers'; var PicnicAreaDirective_1; let PicnicAreaComponent = class PicnicAreaComponent { constructor() { this.focusable = false; } }; __decorate([ Input(), __metadata("design:type", String) ], PicnicAreaComponent.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], PicnicAreaComponent.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], PicnicAreaComponent.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], PicnicAreaComponent.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], PicnicAreaComponent.prototype, "focusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], PicnicAreaComponent.prototype, "innerClass", void 0); __decorate([ Input(), __metadata("design:type", String) ], PicnicAreaComponent.prototype, "size", void 0); PicnicAreaComponent = __decorate([ Component({ selector: "ibm-icon-picnic-area", template: ` <svg ibmIconPicnicArea [size]="size" [ariaLabel]="ariaLabel" [ariaLabelledby]="ariaLabelledby" [ariaHidden]="ariaHidden" [title]="title" [isFocusable]="focusable" [attr.class]="innerClass"> </svg> ` }) ], PicnicAreaComponent); let PicnicAreaDirective = PicnicAreaDirective_1 = class PicnicAreaDirective { constructor(elementRef) { this.elementRef = elementRef; this.isFocusable = false; this.icons = { "32": { metadata: { "moduleName": "PicnicArea32", "filepath": "picnic-area/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": "M24 12a4 4 0 114-4A4.0045 4.0045 0 0124 12zm0-6a2 2 0 102 2A2.0021 2.0021 0 0024 6zM26 22H21.8472L21.18 18H24V16H8v2h2.82l-.6668 4H6v2H9.82l-.6668 4H11.18l.6668-4h8.3056l.6668 4h2.0276L22.18 24H26zM12.18 22l.6665-4h6.3062l.6665 4z" } }], "name": "picnic-area", "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="M24 12a4 4 0 114-4A4.0045 4.0045 0 0124 12zm0-6a2 2 0 102 2A2.0021 2.0021 0 0024 6zM26 22H21.8472L21.18 18H24V16H8v2h2.82l-.6668 4H6v2H9.82l-.6668 4H11.18l.6668-4h8.3056l.6668 4h2.0276L22.18 24H26zM12.18 22l.6665-4h6.3062l.6665 4z"></path></svg>` }, "24": { metadata: { "moduleName": "PicnicArea24", "filepath": "picnic-area/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": "M24 12a4 4 0 114-4A4.0045 4.0045 0 0124 12zm0-6a2 2 0 102 2A2.0021 2.0021 0 0024 6zM26 22H21.8472L21.18 18H24V16H8v2h2.82l-.6668 4H6v2H9.82l-.6668 4H11.18l.6668-4h8.3056l.6668 4h2.0276L22.18 24H26zM12.18 22l.6665-4h6.3062l.6665 4z" } }], "name": "picnic-area", "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="M24 12a4 4 0 114-4A4.0045 4.0045 0 0124 12zm0-6a2 2 0 102 2A2.0021 2.0021 0 0024 6zM26 22H21.8472L21.18 18H24V16H8v2h2.82l-.6668 4H6v2H9.82l-.6668 4H11.18l.6668-4h8.3056l.6668 4h2.0276L22.18 24H26zM12.18 22l.6665-4h6.3062l.6665 4z"></path></svg>` }, "20": { metadata: { "moduleName": "PicnicArea20", "filepath": "picnic-area/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": "M24 12a4 4 0 114-4A4.0045 4.0045 0 0124 12zm0-6a2 2 0 102 2A2.0021 2.0021 0 0024 6zM26 22H21.8472L21.18 18H24V16H8v2h2.82l-.6668 4H6v2H9.82l-.6668 4H11.18l.6668-4h8.3056l.6668 4h2.0276L22.18 24H26zM12.18 22l.6665-4h6.3062l.6665 4z" } }], "name": "picnic-area", "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="M24 12a4 4 0 114-4A4.0045 4.0045 0 0124 12zm0-6a2 2 0 102 2A2.0021 2.0021 0 0024 6zM26 22H21.8472L21.18 18H24V16H8v2h2.82l-.6668 4H6v2H9.82l-.6668 4H11.18l.6668-4h8.3056l.6668 4h2.0276L22.18 24H26zM12.18 22l.6665-4h6.3062l.6665 4z"></path></svg>` }, "16": { metadata: { "moduleName": "PicnicArea16", "filepath": "picnic-area/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": "M24 12a4 4 0 114-4A4.0045 4.0045 0 0124 12zm0-6a2 2 0 102 2A2.0021 2.0021 0 0024 6zM26 22H21.8472L21.18 18H24V16H8v2h2.82l-.6668 4H6v2H9.82l-.6668 4H11.18l.6668-4h8.3056l.6668 4h2.0276L22.18 24H26zM12.18 22l.6665-4h6.3062l.6665 4z" } }], "name": "picnic-area", "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="M24 12a4 4 0 114-4A4.0045 4.0045 0 0124 12zm0-6a2 2 0 102 2A2.0021 2.0021 0 0024 6zM26 22H21.8472L21.18 18H24V16H8v2h2.82l-.6668 4H6v2H9.82l-.6668 4H11.18l.6668-4h8.3056l.6668 4h2.0276L22.18 24H26zM12.18 22l.6665-4h6.3062l.6665 4z"></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; PicnicAreaDirective_1.titleIdCounter++; title.setAttribute("id", `picnic-area-${PicnicAreaDirective_1.titleIdCounter}`); svg.appendChild(title); svg.setAttribute("aria-labelledby", `picnic-area-${PicnicAreaDirective_1.titleIdCounter}`); } } }; PicnicAreaDirective.titleIdCounter = 0; PicnicAreaDirective.ctorParameters = () => [ { type: ElementRef } ]; __decorate([ Input(), __metadata("design:type", String) ], PicnicAreaDirective.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], PicnicAreaDirective.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], PicnicAreaDirective.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], PicnicAreaDirective.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], PicnicAreaDirective.prototype, "isFocusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], PicnicAreaDirective.prototype, "size", void 0); PicnicAreaDirective = PicnicAreaDirective_1 = __decorate([ Directive({ selector: "[ibmIconPicnicArea]" }), __metadata("design:paramtypes", [ElementRef]) ], PicnicAreaDirective); let PicnicAreaModule = class PicnicAreaModule { }; PicnicAreaModule = __decorate([ NgModule({ declarations: [ PicnicAreaComponent, PicnicAreaDirective, ], exports: [ PicnicAreaComponent, PicnicAreaDirective, ] }) ], PicnicAreaModule); export { PicnicAreaComponent, PicnicAreaDirective, PicnicAreaModule };