Skip to content

Instantly share code, notes, and snippets.

@realtomaszkula
Created July 30, 2018 08:10
Show Gist options
  • Save realtomaszkula/2f18f62397e66a6b89482b71c15d1155 to your computer and use it in GitHub Desktop.
Save realtomaszkula/2f18f62397e66a6b89482b71c15d1155 to your computer and use it in GitHub Desktop.
@Directive({
selector: '[appValidationBorder]'
})
export class ValidationBorderDirective {
private readonly colors: {
VALID: string;
INVALID: string;
PENDING: string;
DISABLED: string;
};
@Input('appValidationBorderWidth') borderWidth: string;
@Input('appValidationBorderStyle') borderStyle: string;
@HostBinding('style.border-style')
get borderStyleCss() {
return this.showBorder ? this.borderStyle : null;
}
@HostBinding('style.border-width')
get borderWidthCss() {
return this.showBorder ? this.borderWidth : null;
}
@HostBinding('style.border-color')
get borderColorCss() {
return this.showBorder ? this.colors[this.ngControl.status] : null;
}
get showBorder() {
return this.ngControl.dirty || this.ngControl.touched;
}
constructor(
@Self() private ngControl: NgControl,
@Inject(VALIDATION_BORDER_CONFIG) config: ValidationBorderConfig
) {
this.colors = config.colors;
this.borderWidth = config.borderWidth;
this.borderStyle = config.borderStyle;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment