UNPKG

@carbon/icons-angular

Version:

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

174 lines (171 loc) 9.98 kB
import { __decorate, __metadata } from 'tslib'; import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core'; import { getAttributes } from '@carbon/icon-helpers'; var TextLeadingDirective_1; let TextLeadingComponent = class TextLeadingComponent { constructor() { this.focusable = false; } }; __decorate([ Input(), __metadata("design:type", String) ], TextLeadingComponent.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], TextLeadingComponent.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], TextLeadingComponent.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], TextLeadingComponent.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], TextLeadingComponent.prototype, "focusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], TextLeadingComponent.prototype, "innerClass", void 0); __decorate([ Input(), __metadata("design:type", String) ], TextLeadingComponent.prototype, "size", void 0); TextLeadingComponent = __decorate([ Component({ selector: "ibm-icon-text-leading", template: ` <svg ibmIconTextLeading [size]="size" [ariaLabel]="ariaLabel" [ariaLabelledby]="ariaLabelledby" [ariaHidden]="ariaHidden" [title]="title" [isFocusable]="focusable" [attr.class]="innerClass"> </svg> ` }) ], TextLeadingComponent); let TextLeadingDirective = TextLeadingDirective_1 = class TextLeadingDirective { constructor(elementRef) { this.elementRef = elementRef; this.isFocusable = false; this.icons = { "32": { metadata: { "moduleName": "TextLeading32", "filepath": "text--leading/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": "M14 13H30V15H14zM15 28H30V30H15zM25.85 27H28L23.64 17H21.36L17 27h2.15l.8-2h5.1zm-5.1-4l1.75-4.37L24.25 23zM25.85 12H28L23.64 2H21.36L17 12h2.15l.8-2h5.1zm-5.1-4L22.5 3.63 24.25 8zM6 15.83L8.58 18.41 10 17 6 13 2 17 3.41 18.42 6 15.83zM6 27.17L3.42 24.59 2 26 6 30 10 26 8.59 24.58 6 27.17z" } }], "name": "text--leading", "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="M14 13H30V15H14zM15 28H30V30H15zM25.85 27H28L23.64 17H21.36L17 27h2.15l.8-2h5.1zm-5.1-4l1.75-4.37L24.25 23zM25.85 12H28L23.64 2H21.36L17 12h2.15l.8-2h5.1zm-5.1-4L22.5 3.63 24.25 8zM6 15.83L8.58 18.41 10 17 6 13 2 17 3.41 18.42 6 15.83zM6 27.17L3.42 24.59 2 26 6 30 10 26 8.59 24.58 6 27.17z"></path></svg>` }, "24": { metadata: { "moduleName": "TextLeading24", "filepath": "text--leading/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": "M14 13H30V15H14zM15 28H30V30H15zM25.85 27H28L23.64 17H21.36L17 27h2.15l.8-2h5.1zm-5.1-4l1.75-4.37L24.25 23zM25.85 12H28L23.64 2H21.36L17 12h2.15l.8-2h5.1zm-5.1-4L22.5 3.63 24.25 8zM6 15.83L8.58 18.41 10 17 6 13 2 17 3.41 18.42 6 15.83zM6 27.17L3.42 24.59 2 26 6 30 10 26 8.59 24.58 6 27.17z" } }], "name": "text--leading", "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="M14 13H30V15H14zM15 28H30V30H15zM25.85 27H28L23.64 17H21.36L17 27h2.15l.8-2h5.1zm-5.1-4l1.75-4.37L24.25 23zM25.85 12H28L23.64 2H21.36L17 12h2.15l.8-2h5.1zm-5.1-4L22.5 3.63 24.25 8zM6 15.83L8.58 18.41 10 17 6 13 2 17 3.41 18.42 6 15.83zM6 27.17L3.42 24.59 2 26 6 30 10 26 8.59 24.58 6 27.17z"></path></svg>` }, "20": { metadata: { "moduleName": "TextLeading20", "filepath": "text--leading/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": "M14 13H30V15H14zM15 28H30V30H15zM25.85 27H28L23.64 17H21.36L17 27h2.15l.8-2h5.1zm-5.1-4l1.75-4.37L24.25 23zM25.85 12H28L23.64 2H21.36L17 12h2.15l.8-2h5.1zm-5.1-4L22.5 3.63 24.25 8zM6 15.83L8.58 18.41 10 17 6 13 2 17 3.41 18.42 6 15.83zM6 27.17L3.42 24.59 2 26 6 30 10 26 8.59 24.58 6 27.17z" } }], "name": "text--leading", "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="M14 13H30V15H14zM15 28H30V30H15zM25.85 27H28L23.64 17H21.36L17 27h2.15l.8-2h5.1zm-5.1-4l1.75-4.37L24.25 23zM25.85 12H28L23.64 2H21.36L17 12h2.15l.8-2h5.1zm-5.1-4L22.5 3.63 24.25 8zM6 15.83L8.58 18.41 10 17 6 13 2 17 3.41 18.42 6 15.83zM6 27.17L3.42 24.59 2 26 6 30 10 26 8.59 24.58 6 27.17z"></path></svg>` }, "16": { metadata: { "moduleName": "TextLeading16", "filepath": "text--leading/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": "M14 13H30V15H14zM15 28H30V30H15zM25.85 27H28L23.64 17H21.36L17 27h2.15l.8-2h5.1zm-5.1-4l1.75-4.37L24.25 23zM25.85 12H28L23.64 2H21.36L17 12h2.15l.8-2h5.1zm-5.1-4L22.5 3.63 24.25 8zM6 15.83L8.58 18.41 10 17 6 13 2 17 3.41 18.42 6 15.83zM6 27.17L3.42 24.59 2 26 6 30 10 26 8.59 24.58 6 27.17z" } }], "name": "text--leading", "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="M14 13H30V15H14zM15 28H30V30H15zM25.85 27H28L23.64 17H21.36L17 27h2.15l.8-2h5.1zm-5.1-4l1.75-4.37L24.25 23zM25.85 12H28L23.64 2H21.36L17 12h2.15l.8-2h5.1zm-5.1-4L22.5 3.63 24.25 8zM6 15.83L8.58 18.41 10 17 6 13 2 17 3.41 18.42 6 15.83zM6 27.17L3.42 24.59 2 26 6 30 10 26 8.59 24.58 6 27.17z"></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; TextLeadingDirective_1.titleIdCounter++; title.setAttribute("id", `text-leading-${TextLeadingDirective_1.titleIdCounter}`); svg.appendChild(title); svg.setAttribute("aria-labelledby", `text-leading-${TextLeadingDirective_1.titleIdCounter}`); } } }; TextLeadingDirective.titleIdCounter = 0; TextLeadingDirective.ctorParameters = () => [ { type: ElementRef } ]; __decorate([ Input(), __metadata("design:type", String) ], TextLeadingDirective.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], TextLeadingDirective.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], TextLeadingDirective.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], TextLeadingDirective.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], TextLeadingDirective.prototype, "isFocusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], TextLeadingDirective.prototype, "size", void 0); TextLeadingDirective = TextLeadingDirective_1 = __decorate([ Directive({ selector: "[ibmIconTextLeading]" }), __metadata("design:paramtypes", [ElementRef]) ], TextLeadingDirective); let TextLeadingModule = class TextLeadingModule { }; TextLeadingModule = __decorate([ NgModule({ declarations: [ TextLeadingComponent, TextLeadingDirective, ], exports: [ TextLeadingComponent, TextLeadingDirective, ] }) ], TextLeadingModule); export { TextLeadingComponent, TextLeadingDirective, TextLeadingModule };