@carbon/icons-angular
Version:
Angular components for icons in digital and software products using the Carbon Design System
174 lines (171 loc) • 10.8 kB
JavaScript
import { __decorate, __metadata } from 'tslib';
import { Input, Component, ElementRef, Directive, NgModule } from '@angular/core';
import { getAttributes } from '@carbon/icon-helpers';
var PasswordDirective_1;
let PasswordComponent = class PasswordComponent {
constructor() {
this.focusable = false;
}
};
__decorate([
Input(),
__metadata("design:type", String)
], PasswordComponent.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], PasswordComponent.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], PasswordComponent.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], PasswordComponent.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], PasswordComponent.prototype, "focusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], PasswordComponent.prototype, "innerClass", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], PasswordComponent.prototype, "size", void 0);
PasswordComponent = __decorate([
Component({
selector: "ibm-icon-password",
template: `
<svg
ibmIconPassword
[size]="size"
[ariaLabel]="ariaLabel"
[ariaLabelledby]="ariaLabelledby"
[ariaHidden]="ariaHidden"
[title]="title"
[isFocusable]="focusable"
[attr.class]="innerClass">
</svg>
`
})
], PasswordComponent);
let PasswordDirective = PasswordDirective_1 = class PasswordDirective {
constructor(elementRef) {
this.elementRef = elementRef;
this.isFocusable = false;
this.icons = {
"32": {
metadata: { "moduleName": "Password32", "filepath": "password/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": "M21,2a9,9,0,0,0-9,9,8.87,8.87,0,0,0,.39,2.61L2,24v6H8L18.39,19.61A9,9,0,0,0,30,11.74a8.77,8.77,0,0,0-1.65-6A9,9,0,0,0,21,2Zm0,16a7,7,0,0,1-2-.3l-1.15-.35L17,18.2l-3.18,3.18L12.41,20,11,21.41l1.38,1.38-1.59,1.59L9.41,23,8,24.41l1.38,1.38L7.17,28H4V24.83L13.8,15l.85-.85-.29-.95a7.14,7.14,0,0,1,3.4-8.44,7,7,0,0,1,10.24,6,6.69,6.69,0,0,1-1.09,4A7,7,0,0,1,21,18Z" } }, { "elem": "circle", "attrs": { "cx": "22", "cy": "10", "r": "2" } }], "name": "password", "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="M21,2a9,9,0,0,0-9,9,8.87,8.87,0,0,0,.39,2.61L2,24v6H8L18.39,19.61A9,9,0,0,0,30,11.74a8.77,8.77,0,0,0-1.65-6A9,9,0,0,0,21,2Zm0,16a7,7,0,0,1-2-.3l-1.15-.35L17,18.2l-3.18,3.18L12.41,20,11,21.41l1.38,1.38-1.59,1.59L9.41,23,8,24.41l1.38,1.38L7.17,28H4V24.83L13.8,15l.85-.85-.29-.95a7.14,7.14,0,0,1,3.4-8.44,7,7,0,0,1,10.24,6,6.69,6.69,0,0,1-1.09,4A7,7,0,0,1,21,18Z"></path><circle cx="22" cy="10" r="2"></circle></svg>`
},
"24": {
metadata: { "moduleName": "Password24", "filepath": "password/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": "M21,2a9,9,0,0,0-9,9,8.87,8.87,0,0,0,.39,2.61L2,24v6H8L18.39,19.61A9,9,0,0,0,30,11.74a8.77,8.77,0,0,0-1.65-6A9,9,0,0,0,21,2Zm0,16a7,7,0,0,1-2-.3l-1.15-.35L17,18.2l-3.18,3.18L12.41,20,11,21.41l1.38,1.38-1.59,1.59L9.41,23,8,24.41l1.38,1.38L7.17,28H4V24.83L13.8,15l.85-.85-.29-.95a7.14,7.14,0,0,1,3.4-8.44,7,7,0,0,1,10.24,6,6.69,6.69,0,0,1-1.09,4A7,7,0,0,1,21,18Z" } }, { "elem": "circle", "attrs": { "cx": "22", "cy": "10", "r": "2" } }], "name": "password", "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="M21,2a9,9,0,0,0-9,9,8.87,8.87,0,0,0,.39,2.61L2,24v6H8L18.39,19.61A9,9,0,0,0,30,11.74a8.77,8.77,0,0,0-1.65-6A9,9,0,0,0,21,2Zm0,16a7,7,0,0,1-2-.3l-1.15-.35L17,18.2l-3.18,3.18L12.41,20,11,21.41l1.38,1.38-1.59,1.59L9.41,23,8,24.41l1.38,1.38L7.17,28H4V24.83L13.8,15l.85-.85-.29-.95a7.14,7.14,0,0,1,3.4-8.44,7,7,0,0,1,10.24,6,6.69,6.69,0,0,1-1.09,4A7,7,0,0,1,21,18Z"></path><circle cx="22" cy="10" r="2"></circle></svg>`
},
"20": {
metadata: { "moduleName": "Password20", "filepath": "password/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": "M21,2a9,9,0,0,0-9,9,8.87,8.87,0,0,0,.39,2.61L2,24v6H8L18.39,19.61A9,9,0,0,0,30,11.74a8.77,8.77,0,0,0-1.65-6A9,9,0,0,0,21,2Zm0,16a7,7,0,0,1-2-.3l-1.15-.35L17,18.2l-3.18,3.18L12.41,20,11,21.41l1.38,1.38-1.59,1.59L9.41,23,8,24.41l1.38,1.38L7.17,28H4V24.83L13.8,15l.85-.85-.29-.95a7.14,7.14,0,0,1,3.4-8.44,7,7,0,0,1,10.24,6,6.69,6.69,0,0,1-1.09,4A7,7,0,0,1,21,18Z" } }, { "elem": "circle", "attrs": { "cx": "22", "cy": "10", "r": "2" } }], "name": "password", "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="M21,2a9,9,0,0,0-9,9,8.87,8.87,0,0,0,.39,2.61L2,24v6H8L18.39,19.61A9,9,0,0,0,30,11.74a8.77,8.77,0,0,0-1.65-6A9,9,0,0,0,21,2Zm0,16a7,7,0,0,1-2-.3l-1.15-.35L17,18.2l-3.18,3.18L12.41,20,11,21.41l1.38,1.38-1.59,1.59L9.41,23,8,24.41l1.38,1.38L7.17,28H4V24.83L13.8,15l.85-.85-.29-.95a7.14,7.14,0,0,1,3.4-8.44,7,7,0,0,1,10.24,6,6.69,6.69,0,0,1-1.09,4A7,7,0,0,1,21,18Z"></path><circle cx="22" cy="10" r="2"></circle></svg>`
},
"16": {
metadata: { "moduleName": "Password16", "filepath": "password/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": "M21,2a9,9,0,0,0-9,9,8.87,8.87,0,0,0,.39,2.61L2,24v6H8L18.39,19.61A9,9,0,0,0,30,11.74a8.77,8.77,0,0,0-1.65-6A9,9,0,0,0,21,2Zm0,16a7,7,0,0,1-2-.3l-1.15-.35L17,18.2l-3.18,3.18L12.41,20,11,21.41l1.38,1.38-1.59,1.59L9.41,23,8,24.41l1.38,1.38L7.17,28H4V24.83L13.8,15l.85-.85-.29-.95a7.14,7.14,0,0,1,3.4-8.44,7,7,0,0,1,10.24,6,6.69,6.69,0,0,1-1.09,4A7,7,0,0,1,21,18Z" } }, { "elem": "circle", "attrs": { "cx": "22", "cy": "10", "r": "2" } }], "name": "password", "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="M21,2a9,9,0,0,0-9,9,8.87,8.87,0,0,0,.39,2.61L2,24v6H8L18.39,19.61A9,9,0,0,0,30,11.74a8.77,8.77,0,0,0-1.65-6A9,9,0,0,0,21,2Zm0,16a7,7,0,0,1-2-.3l-1.15-.35L17,18.2l-3.18,3.18L12.41,20,11,21.41l1.38,1.38-1.59,1.59L9.41,23,8,24.41l1.38,1.38L7.17,28H4V24.83L13.8,15l.85-.85-.29-.95a7.14,7.14,0,0,1,3.4-8.44,7,7,0,0,1,10.24,6,6.69,6.69,0,0,1-1.09,4A7,7,0,0,1,21,18Z"></path><circle cx="22" cy="10" r="2"></circle></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;
PasswordDirective_1.titleIdCounter++;
title.setAttribute("id", `password-${PasswordDirective_1.titleIdCounter}`);
svg.appendChild(title);
svg.setAttribute("aria-labelledby", `password-${PasswordDirective_1.titleIdCounter}`);
}
}
};
PasswordDirective.titleIdCounter = 0;
PasswordDirective.ctorParameters = () => [
{ type: ElementRef }
];
__decorate([
Input(),
__metadata("design:type", String)
], PasswordDirective.prototype, "ariaLabel", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], PasswordDirective.prototype, "ariaLabelledby", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], PasswordDirective.prototype, "ariaHidden", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], PasswordDirective.prototype, "title", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], PasswordDirective.prototype, "isFocusable", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], PasswordDirective.prototype, "size", void 0);
PasswordDirective = PasswordDirective_1 = __decorate([
Directive({
selector: "[ibmIconPassword]"
}),
__metadata("design:paramtypes", [ElementRef])
], PasswordDirective);
let PasswordModule = class PasswordModule {
};
PasswordModule = __decorate([
NgModule({
declarations: [
PasswordComponent,
PasswordDirective,
],
exports: [
PasswordComponent,
PasswordDirective,
]
})
], PasswordModule);
export { PasswordComponent, PasswordDirective, PasswordModule };