UNPKG

@carbon/icons-angular

Version:

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

174 lines (171 loc) 9.01 kB
import { __decorate, __metadata } from 'tslib'; import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core'; import { getAttributes } from '@carbon/icon-helpers'; var OpacityDirective_1; let OpacityComponent = class OpacityComponent { constructor() { this.focusable = false; } }; __decorate([ Input(), __metadata("design:type", String) ], OpacityComponent.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], OpacityComponent.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], OpacityComponent.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], OpacityComponent.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], OpacityComponent.prototype, "focusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], OpacityComponent.prototype, "innerClass", void 0); __decorate([ Input(), __metadata("design:type", String) ], OpacityComponent.prototype, "size", void 0); OpacityComponent = __decorate([ Component({ selector: "ibm-icon-opacity", template: ` <svg ibmIconOpacity [size]="size" [ariaLabel]="ariaLabel" [ariaLabelledby]="ariaLabelledby" [ariaHidden]="ariaHidden" [title]="title" [isFocusable]="focusable" [attr.class]="innerClass"> </svg> ` }) ], OpacityComponent); let OpacityDirective = OpacityDirective_1 = class OpacityDirective { constructor(elementRef) { this.elementRef = elementRef; this.isFocusable = false; this.icons = { "32": { metadata: { "moduleName": "Opacity32", "filepath": "opacity/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": "M6 6H10V10H6zM10 10H14V14H10zM14 6H18V10H14zM22 6H26V10H22zM6 14H10V18H6zM14 14H18V18H14zM22 14H26V18H22zM6 22H10V26H6zM14 22H18V26H14zM22 22H26V26H22zM18 10H22V14H18zM10 18H14V22H10zM18 18H22V22H18z" } }], "name": "opacity", "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="M6 6H10V10H6zM10 10H14V14H10zM14 6H18V10H14zM22 6H26V10H22zM6 14H10V18H6zM14 14H18V18H14zM22 14H26V18H22zM6 22H10V26H6zM14 22H18V26H14zM22 22H26V26H22zM18 10H22V14H18zM10 18H14V22H10zM18 18H22V22H18z"></path></svg>` }, "24": { metadata: { "moduleName": "Opacity24", "filepath": "opacity/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": "M6 6H10V10H6zM10 10H14V14H10zM14 6H18V10H14zM22 6H26V10H22zM6 14H10V18H6zM14 14H18V18H14zM22 14H26V18H22zM6 22H10V26H6zM14 22H18V26H14zM22 22H26V26H22zM18 10H22V14H18zM10 18H14V22H10zM18 18H22V22H18z" } }], "name": "opacity", "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="M6 6H10V10H6zM10 10H14V14H10zM14 6H18V10H14zM22 6H26V10H22zM6 14H10V18H6zM14 14H18V18H14zM22 14H26V18H22zM6 22H10V26H6zM14 22H18V26H14zM22 22H26V26H22zM18 10H22V14H18zM10 18H14V22H10zM18 18H22V22H18z"></path></svg>` }, "20": { metadata: { "moduleName": "Opacity20", "filepath": "opacity/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": "M6 6H10V10H6zM10 10H14V14H10zM14 6H18V10H14zM22 6H26V10H22zM6 14H10V18H6zM14 14H18V18H14zM22 14H26V18H22zM6 22H10V26H6zM14 22H18V26H14zM22 22H26V26H22zM18 10H22V14H18zM10 18H14V22H10zM18 18H22V22H18z" } }], "name": "opacity", "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="M6 6H10V10H6zM10 10H14V14H10zM14 6H18V10H14zM22 6H26V10H22zM6 14H10V18H6zM14 14H18V18H14zM22 14H26V18H22zM6 22H10V26H6zM14 22H18V26H14zM22 22H26V26H22zM18 10H22V14H18zM10 18H14V22H10zM18 18H22V22H18z"></path></svg>` }, "16": { metadata: { "moduleName": "Opacity16", "filepath": "opacity/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": "M6 6H10V10H6zM10 10H14V14H10zM14 6H18V10H14zM22 6H26V10H22zM6 14H10V18H6zM14 14H18V18H14zM22 14H26V18H22zM6 22H10V26H6zM14 22H18V26H14zM22 22H26V26H22zM18 10H22V14H18zM10 18H14V22H10zM18 18H22V22H18z" } }], "name": "opacity", "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="M6 6H10V10H6zM10 10H14V14H10zM14 6H18V10H14zM22 6H26V10H22zM6 14H10V18H6zM14 14H18V18H14zM22 14H26V18H22zM6 22H10V26H6zM14 22H18V26H14zM22 22H26V26H22zM18 10H22V14H18zM10 18H14V22H10zM18 18H22V22H18z"></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; OpacityDirective_1.titleIdCounter++; title.setAttribute("id", `opacity-${OpacityDirective_1.titleIdCounter}`); svg.appendChild(title); svg.setAttribute("aria-labelledby", `opacity-${OpacityDirective_1.titleIdCounter}`); } } }; OpacityDirective.titleIdCounter = 0; OpacityDirective.ctorParameters = () => [ { type: ElementRef } ]; __decorate([ Input(), __metadata("design:type", String) ], OpacityDirective.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], OpacityDirective.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], OpacityDirective.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], OpacityDirective.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], OpacityDirective.prototype, "isFocusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], OpacityDirective.prototype, "size", void 0); OpacityDirective = OpacityDirective_1 = __decorate([ Directive({ selector: "[ibmIconOpacity]" }), __metadata("design:paramtypes", [ElementRef]) ], OpacityDirective); let OpacityModule = class OpacityModule { }; OpacityModule = __decorate([ NgModule({ declarations: [ OpacityComponent, OpacityDirective, ], exports: [ OpacityComponent, OpacityDirective, ] }) ], OpacityModule); export { OpacityComponent, OpacityDirective, OpacityModule };