mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 22:33:35 +00:00
* Rename service-factory folder * Move cryptographic service factories * Move crypto models * Move crypto services * Move domain base class * Platform code owners * Move desktop log services * Move log files * Establish component library ownership * Move background listeners * Move background background * Move localization to Platform * Move browser alarms to Platform * Move browser state to Platform * Move CLI state to Platform * Move Desktop native concerns to Platform * Move flag and misc to Platform * Lint fixes * Move electron state to platform * Move web state to Platform * Move lib state to Platform * Fix broken tests * Rename interface to idiomatic TS * `npm run prettier` 🤖 * Resolve review feedback * Set platform as owners of web core and shared * Expand moved services * Fix test types --------- Co-authored-by: Hinton <hinton@users.noreply.github.com>
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import { Component, HostBinding, Input } from "@angular/core";
|
|
|
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
|
|
|
// Increments for each instance of this component
|
|
let nextId = 0;
|
|
|
|
@Component({
|
|
selector: "bit-error",
|
|
template: `<i class="bwi bwi-error"></i> {{ displayError }}`,
|
|
host: {
|
|
class: "tw-block tw-mt-1 tw-text-danger",
|
|
"aria-live": "assertive",
|
|
},
|
|
})
|
|
export class BitErrorComponent {
|
|
@HostBinding() id = `bit-error-${nextId++}`;
|
|
|
|
@Input() error: [string, any];
|
|
|
|
constructor(private i18nService: I18nService) {}
|
|
|
|
get displayError() {
|
|
switch (this.error[0]) {
|
|
case "required":
|
|
return this.i18nService.t("inputRequired");
|
|
case "email":
|
|
return this.i18nService.t("inputEmail");
|
|
case "minlength":
|
|
return this.i18nService.t("inputMinLength", this.error[1]?.requiredLength);
|
|
case "maxlength":
|
|
return this.i18nService.t("inputMaxLength", this.error[1]?.requiredLength);
|
|
case "min":
|
|
return this.i18nService.t("inputMinValue", this.error[1]?.min);
|
|
case "max":
|
|
return this.i18nService.t("inputMaxValue", this.error[1]?.max);
|
|
case "forbiddenCharacters":
|
|
return this.i18nService.t("inputForbiddenCharacters", this.error[1]?.characters.join(", "));
|
|
case "multipleEmails":
|
|
return this.i18nService.t("multipleInputEmails");
|
|
case "trim":
|
|
return this.i18nService.t("inputTrimValidator");
|
|
default:
|
|
// Attempt to show a custom error message.
|
|
if (this.error[1]?.message) {
|
|
return this.error[1]?.message;
|
|
}
|
|
|
|
return this.error;
|
|
}
|
|
}
|
|
}
|