Created
July 30, 2018 08:10
-
-
Save realtomaszkula/2f18f62397e66a6b89482b71c15d1155 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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