1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 07:43:35 +00:00

Move to libs

This commit is contained in:
Hinton
2022-06-03 16:24:40 +02:00
parent 28d15bfe2a
commit d7492e3cf3
878 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
import { Directive, HostBinding, Input, Optional, Self } from "@angular/core";
import { NgControl, Validators } from "@angular/forms";
// Increments for each instance of this component
let nextId = 0;
@Directive({
selector: "input[bitInput], select[bitInput], textarea[bitInput]",
})
export class BitInputDirective {
@HostBinding("class") @Input() get classList() {
return [
"tw-block",
"tw-w-full",
"tw-px-3",
"tw-py-1.5",
"tw-bg-background-alt",
"tw-border",
"tw-border-solid",
"tw-rounded",
"tw-text-main",
"tw-placeholder-text-muted",
"focus:tw-outline-none",
"focus:tw-border-primary-700",
"focus:tw-ring-1",
"focus:tw-ring-primary-700",
"focus:tw-z-10",
"disabled:tw-bg-secondary-100",
this.hasPrefix ? "tw-rounded-l-none" : "",
this.hasSuffix ? "tw-rounded-r-none" : "",
this.hasError ? "tw-border-danger-500" : "tw-border-secondary-500",
].filter((s) => s != "");
}
@HostBinding() id = `bit-input-${nextId++}`;
@HostBinding("attr.aria-describedby") ariaDescribedBy: string;
@HostBinding("attr.aria-invalid") get ariaInvalid() {
return this.hasError ? true : undefined;
}
@HostBinding()
@Input()
get required() {
return this._required ?? this.ngControl?.control?.hasValidator(Validators.required) ?? false;
}
set required(value: any) {
this._required = value != null && value !== false;
}
private _required: boolean;
@Input() hasPrefix = false;
@Input() hasSuffix = false;
get hasError() {
return this.ngControl?.status === "INVALID" && this.ngControl?.touched;
}
get error(): [string, any] {
const key = Object.keys(this.ngControl.errors)[0];
return [key, this.ngControl.errors[key]];
}
constructor(@Optional() @Self() private ngControl: NgControl) {}
}

View File

@@ -0,0 +1,11 @@
import { CommonModule } from "@angular/common";
import { NgModule } from "@angular/core";
import { BitInputDirective } from "./input.directive";
@NgModule({
imports: [CommonModule],
declarations: [BitInputDirective],
exports: [BitInputDirective],
})
export class InputModule {}