UNPKG

@carbon/icons-angular

Version:

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

174 lines (171 loc) 8.28 kB
import { __decorate, __metadata } from 'tslib'; import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core'; import { getAttributes } from '@carbon/icon-helpers'; var OrdinalDirective_1; let OrdinalComponent = class OrdinalComponent { constructor() { this.focusable = false; } }; __decorate([ Input(), __metadata("design:type", String) ], OrdinalComponent.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], OrdinalComponent.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], OrdinalComponent.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], OrdinalComponent.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], OrdinalComponent.prototype, "focusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], OrdinalComponent.prototype, "innerClass", void 0); __decorate([ Input(), __metadata("design:type", String) ], OrdinalComponent.prototype, "size", void 0); OrdinalComponent = __decorate([ Component({ selector: "ibm-icon-ordinal", template: ` <svg ibmIconOrdinal [size]="size" [ariaLabel]="ariaLabel" [ariaLabelledby]="ariaLabelledby" [ariaHidden]="ariaHidden" [title]="title" [isFocusable]="focusable" [attr.class]="innerClass"> </svg> ` }) ], OrdinalComponent); let OrdinalDirective = OrdinalDirective_1 = class OrdinalDirective { constructor(elementRef) { this.elementRef = elementRef; this.isFocusable = false; this.icons = { "32": { metadata: { "moduleName": "Ordinal32", "filepath": "ordinal/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": "M26,26V4H18v6H12v6H6V26H2v2H30V26ZM8,26V18h4v8Zm6,0V12h4V26Zm6,0V6h4V26Z" } }], "name": "ordinal", "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="M26,26V4H18v6H12v6H6V26H2v2H30V26ZM8,26V18h4v8Zm6,0V12h4V26Zm6,0V6h4V26Z"></path></svg>` }, "24": { metadata: { "moduleName": "Ordinal24", "filepath": "ordinal/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": "M26,26V4H18v6H12v6H6V26H2v2H30V26ZM8,26V18h4v8Zm6,0V12h4V26Zm6,0V6h4V26Z" } }], "name": "ordinal", "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="M26,26V4H18v6H12v6H6V26H2v2H30V26ZM8,26V18h4v8Zm6,0V12h4V26Zm6,0V6h4V26Z"></path></svg>` }, "20": { metadata: { "moduleName": "Ordinal20", "filepath": "ordinal/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": "M26,26V4H18v6H12v6H6V26H2v2H30V26ZM8,26V18h4v8Zm6,0V12h4V26Zm6,0V6h4V26Z" } }], "name": "ordinal", "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="M26,26V4H18v6H12v6H6V26H2v2H30V26ZM8,26V18h4v8Zm6,0V12h4V26Zm6,0V6h4V26Z"></path></svg>` }, "16": { metadata: { "moduleName": "Ordinal16", "filepath": "ordinal/16.js", "descriptor": { "elem": "svg", "attrs": { "xmlns": "http://www.w3.org/2000/svg", "viewBox": "0 0 16 16", "fill": "currentColor", "width": 16, "height": 16 }, "content": [{ "elem": "path", "attrs": { "d": "M1,13 L1,12 L3,12 L3,9 L5.999,9 L6,6 L9,6 L9,3 L13,3 L13,12 L15,12 L15,13 L1,13 Z M5.999,10 L4,10 L4,12 L5.999,12 L5.999,10 Z M8.999,7 L6.999,7 L6.999,9 L7,9 L7,12 L8.999,12 L8.999,7 Z M12,4 L10,4 L10,12 L12,12 L12,4 Z" } }], "name": "ordinal", "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 16 16" aria-hidden="true"><path d="M1,13 L1,12 L3,12 L3,9 L5.999,9 L6,6 L9,6 L9,3 L13,3 L13,12 L15,12 L15,13 L1,13 Z M5.999,10 L4,10 L4,12 L5.999,12 L5.999,10 Z M8.999,7 L6.999,7 L6.999,9 L7,9 L7,12 L8.999,12 L8.999,7 Z M12,4 L10,4 L10,12 L12,12 L12,4 Z"></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; OrdinalDirective_1.titleIdCounter++; title.setAttribute("id", `ordinal-${OrdinalDirective_1.titleIdCounter}`); svg.appendChild(title); svg.setAttribute("aria-labelledby", `ordinal-${OrdinalDirective_1.titleIdCounter}`); } } }; OrdinalDirective.titleIdCounter = 0; OrdinalDirective.ctorParameters = () => [ { type: ElementRef } ]; __decorate([ Input(), __metadata("design:type", String) ], OrdinalDirective.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], OrdinalDirective.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], OrdinalDirective.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], OrdinalDirective.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], OrdinalDirective.prototype, "isFocusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], OrdinalDirective.prototype, "size", void 0); OrdinalDirective = OrdinalDirective_1 = __decorate([ Directive({ selector: "[ibmIconOrdinal]" }), __metadata("design:paramtypes", [ElementRef]) ], OrdinalDirective); let OrdinalModule = class OrdinalModule { }; OrdinalModule = __decorate([ NgModule({ declarations: [ OrdinalComponent, OrdinalDirective, ], exports: [ OrdinalComponent, OrdinalDirective, ] }) ], OrdinalModule); export { OrdinalComponent, OrdinalDirective, OrdinalModule };