UNPKG

@carbon/icons-angular

Version:

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

174 lines (171 loc) 10.7 kB
import { __decorate, __metadata } from 'tslib'; import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core'; import { getAttributes } from '@carbon/icon-helpers'; var UserFavoriteDirective_1; let UserFavoriteComponent = class UserFavoriteComponent { constructor() { this.focusable = false; } }; __decorate([ Input(), __metadata("design:type", String) ], UserFavoriteComponent.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], UserFavoriteComponent.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], UserFavoriteComponent.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], UserFavoriteComponent.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], UserFavoriteComponent.prototype, "focusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], UserFavoriteComponent.prototype, "innerClass", void 0); __decorate([ Input(), __metadata("design:type", String) ], UserFavoriteComponent.prototype, "size", void 0); UserFavoriteComponent = __decorate([ Component({ selector: "ibm-icon-user-favorite", template: ` <svg ibmIconUserFavorite [size]="size" [ariaLabel]="ariaLabel" [ariaLabelledby]="ariaLabelledby" [ariaHidden]="ariaHidden" [title]="title" [isFocusable]="focusable" [attr.class]="innerClass"> </svg> ` }) ], UserFavoriteComponent); let UserFavoriteDirective = UserFavoriteDirective_1 = class UserFavoriteDirective { constructor(elementRef) { this.elementRef = elementRef; this.isFocusable = false; this.icons = { "32": { metadata: { "moduleName": "UserFavorite32", "filepath": "user--favorite/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": "M27.303 12a2.6616 2.6616 0 00-1.9079.8058l-.3932.4054-.397-.4054a2.6615 2.6615 0 00-3.8157 0 2.7992 2.7992 0 000 3.8964L25.0019 21l4.2089-4.2978a2.7992 2.7992 0 000-3.8964A2.6616 2.6616 0 0027.303 12zM2 30H4V25a5.0059 5.0059 0 015-5h6a5.0059 5.0059 0 015 5v5h2V25a7.0082 7.0082 0 00-7-7H9a7.0082 7.0082 0 00-7 7zM12 4A5 5 0 117 9a5 5 0 015-5m0-2a7 7 0 107 7A7 7 0 0012 2z" } }], "name": "user--favorite", "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="M27.303 12a2.6616 2.6616 0 00-1.9079.8058l-.3932.4054-.397-.4054a2.6615 2.6615 0 00-3.8157 0 2.7992 2.7992 0 000 3.8964L25.0019 21l4.2089-4.2978a2.7992 2.7992 0 000-3.8964A2.6616 2.6616 0 0027.303 12zM2 30H4V25a5.0059 5.0059 0 015-5h6a5.0059 5.0059 0 015 5v5h2V25a7.0082 7.0082 0 00-7-7H9a7.0082 7.0082 0 00-7 7zM12 4A5 5 0 117 9a5 5 0 015-5m0-2a7 7 0 107 7A7 7 0 0012 2z"></path></svg>` }, "24": { metadata: { "moduleName": "UserFavorite24", "filepath": "user--favorite/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": "M27.303 12a2.6616 2.6616 0 00-1.9079.8058l-.3932.4054-.397-.4054a2.6615 2.6615 0 00-3.8157 0 2.7992 2.7992 0 000 3.8964L25.0019 21l4.2089-4.2978a2.7992 2.7992 0 000-3.8964A2.6616 2.6616 0 0027.303 12zM2 30H4V25a5.0059 5.0059 0 015-5h6a5.0059 5.0059 0 015 5v5h2V25a7.0082 7.0082 0 00-7-7H9a7.0082 7.0082 0 00-7 7zM12 4A5 5 0 117 9a5 5 0 015-5m0-2a7 7 0 107 7A7 7 0 0012 2z" } }], "name": "user--favorite", "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="M27.303 12a2.6616 2.6616 0 00-1.9079.8058l-.3932.4054-.397-.4054a2.6615 2.6615 0 00-3.8157 0 2.7992 2.7992 0 000 3.8964L25.0019 21l4.2089-4.2978a2.7992 2.7992 0 000-3.8964A2.6616 2.6616 0 0027.303 12zM2 30H4V25a5.0059 5.0059 0 015-5h6a5.0059 5.0059 0 015 5v5h2V25a7.0082 7.0082 0 00-7-7H9a7.0082 7.0082 0 00-7 7zM12 4A5 5 0 117 9a5 5 0 015-5m0-2a7 7 0 107 7A7 7 0 0012 2z"></path></svg>` }, "20": { metadata: { "moduleName": "UserFavorite20", "filepath": "user--favorite/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": "M27.303 12a2.6616 2.6616 0 00-1.9079.8058l-.3932.4054-.397-.4054a2.6615 2.6615 0 00-3.8157 0 2.7992 2.7992 0 000 3.8964L25.0019 21l4.2089-4.2978a2.7992 2.7992 0 000-3.8964A2.6616 2.6616 0 0027.303 12zM2 30H4V25a5.0059 5.0059 0 015-5h6a5.0059 5.0059 0 015 5v5h2V25a7.0082 7.0082 0 00-7-7H9a7.0082 7.0082 0 00-7 7zM12 4A5 5 0 117 9a5 5 0 015-5m0-2a7 7 0 107 7A7 7 0 0012 2z" } }], "name": "user--favorite", "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="M27.303 12a2.6616 2.6616 0 00-1.9079.8058l-.3932.4054-.397-.4054a2.6615 2.6615 0 00-3.8157 0 2.7992 2.7992 0 000 3.8964L25.0019 21l4.2089-4.2978a2.7992 2.7992 0 000-3.8964A2.6616 2.6616 0 0027.303 12zM2 30H4V25a5.0059 5.0059 0 015-5h6a5.0059 5.0059 0 015 5v5h2V25a7.0082 7.0082 0 00-7-7H9a7.0082 7.0082 0 00-7 7zM12 4A5 5 0 117 9a5 5 0 015-5m0-2a7 7 0 107 7A7 7 0 0012 2z"></path></svg>` }, "16": { metadata: { "moduleName": "UserFavorite16", "filepath": "user--favorite/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": "M27.303 12a2.6616 2.6616 0 00-1.9079.8058l-.3932.4054-.397-.4054a2.6615 2.6615 0 00-3.8157 0 2.7992 2.7992 0 000 3.8964L25.0019 21l4.2089-4.2978a2.7992 2.7992 0 000-3.8964A2.6616 2.6616 0 0027.303 12zM2 30H4V25a5.0059 5.0059 0 015-5h6a5.0059 5.0059 0 015 5v5h2V25a7.0082 7.0082 0 00-7-7H9a7.0082 7.0082 0 00-7 7zM12 4A5 5 0 117 9a5 5 0 015-5m0-2a7 7 0 107 7A7 7 0 0012 2z" } }], "name": "user--favorite", "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="M27.303 12a2.6616 2.6616 0 00-1.9079.8058l-.3932.4054-.397-.4054a2.6615 2.6615 0 00-3.8157 0 2.7992 2.7992 0 000 3.8964L25.0019 21l4.2089-4.2978a2.7992 2.7992 0 000-3.8964A2.6616 2.6616 0 0027.303 12zM2 30H4V25a5.0059 5.0059 0 015-5h6a5.0059 5.0059 0 015 5v5h2V25a7.0082 7.0082 0 00-7-7H9a7.0082 7.0082 0 00-7 7zM12 4A5 5 0 117 9a5 5 0 015-5m0-2a7 7 0 107 7A7 7 0 0012 2z"></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; UserFavoriteDirective_1.titleIdCounter++; title.setAttribute("id", `user-favorite-${UserFavoriteDirective_1.titleIdCounter}`); svg.appendChild(title); svg.setAttribute("aria-labelledby", `user-favorite-${UserFavoriteDirective_1.titleIdCounter}`); } } }; UserFavoriteDirective.titleIdCounter = 0; UserFavoriteDirective.ctorParameters = () => [ { type: ElementRef } ]; __decorate([ Input(), __metadata("design:type", String) ], UserFavoriteDirective.prototype, "ariaLabel", void 0); __decorate([ Input(), __metadata("design:type", String) ], UserFavoriteDirective.prototype, "ariaLabelledby", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], UserFavoriteDirective.prototype, "ariaHidden", void 0); __decorate([ Input(), __metadata("design:type", String) ], UserFavoriteDirective.prototype, "title", void 0); __decorate([ Input(), __metadata("design:type", Boolean) ], UserFavoriteDirective.prototype, "isFocusable", void 0); __decorate([ Input(), __metadata("design:type", String) ], UserFavoriteDirective.prototype, "size", void 0); UserFavoriteDirective = UserFavoriteDirective_1 = __decorate([ Directive({ selector: "[ibmIconUserFavorite]" }), __metadata("design:paramtypes", [ElementRef]) ], UserFavoriteDirective); let UserFavoriteModule = class UserFavoriteModule { }; UserFavoriteModule = __decorate([ NgModule({ declarations: [ UserFavoriteComponent, UserFavoriteDirective, ], exports: [ UserFavoriteComponent, UserFavoriteDirective, ] }) ], UserFavoriteModule); export { UserFavoriteComponent, UserFavoriteDirective, UserFavoriteModule };