-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
869be45
commit 5dfb5a8
Showing
8 changed files
with
88 additions
and
83 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
18 changes: 18 additions & 0 deletions
18
projects/ngneat/error-tailor/src/lib/error-tailor.module.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { ControlErrorAnchorDirective } from './control-error-anchor.directive'; | ||
import { DefaultControlErrorComponent } from './control-error.component'; | ||
import { ControlErrorsDirective } from './control-error.directive'; | ||
import { FormActionDirective } from './form-action.directive'; | ||
|
||
const _errorTailorImports = [ | ||
ControlErrorsDirective, | ||
ControlErrorAnchorDirective, | ||
DefaultControlErrorComponent, | ||
FormActionDirective, | ||
]; | ||
|
||
@NgModule({ | ||
imports: [_errorTailorImports], | ||
exports: [_errorTailorImports], | ||
}) | ||
export class errorTailorImports {} |
59 changes: 39 additions & 20 deletions
59
projects/ngneat/error-tailor/src/lib/error-tailor.providers.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,51 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { ControlErrorAnchorDirective } from './control-error-anchor.directive'; | ||
import { DefaultControlErrorComponent } from './control-error.component'; | ||
import { ControlErrorsDirective } from './control-error.directive'; | ||
import { FormActionDirective } from './form-action.directive'; | ||
import { ErrorTailorConfig, ErrorTailorConfigProvider, FORM_ERRORS } from './providers'; | ||
import { FactorySansProvider, InjectionToken, Type, ValueSansProvider } from '@angular/core'; | ||
import { ErrorsMap } from './types'; | ||
import { ControlErrorComponent } from './control-error.component'; | ||
|
||
const _errorTailorImports = [ | ||
ControlErrorsDirective, | ||
ControlErrorAnchorDirective, | ||
DefaultControlErrorComponent, | ||
FormActionDirective | ||
]; | ||
export const FORM_ERRORS = new InjectionToken('FORM_ERRORS', { | ||
providedIn: 'root', | ||
factory: () => { | ||
return {}; | ||
}, | ||
}); | ||
|
||
@NgModule({ | ||
imports: [_errorTailorImports], | ||
exports: [_errorTailorImports] | ||
}) | ||
export class errorTailorImports {} | ||
export interface ErrorsUseValue extends ValueSansProvider { | ||
useValue: ErrorsMap; | ||
} | ||
|
||
export interface ErrorsUseFactory extends FactorySansProvider { | ||
useFactory: (...args: any[]) => ErrorsMap; | ||
} | ||
|
||
export type ErrorsProvider = ErrorsUseValue | ErrorsUseFactory; | ||
|
||
export type ErrorTailorConfig = { | ||
errors?: ErrorsProvider; | ||
blurPredicate?: (element: Element) => boolean; | ||
controlErrorsClass?: string | string[] | undefined; | ||
controlCustomClass?: string | string[] | undefined; | ||
controlErrorComponent?: Type<ControlErrorComponent>; | ||
controlClassOnly?: boolean; | ||
controlErrorComponentAnchorFn?: (hostElement: Element, errorElement: Element) => () => void; | ||
controlErrorsOn?: { | ||
async?: boolean; | ||
blur?: boolean; | ||
change?: boolean; | ||
status?: boolean; | ||
}; | ||
}; | ||
|
||
export const ErrorTailorConfigProvider = new InjectionToken<ErrorTailorConfig>('ErrorTailorConfigProvider'); | ||
|
||
export function provideErrorTailorConfig(config: ErrorTailorConfig) { | ||
return [ | ||
{ | ||
provide: ErrorTailorConfigProvider, | ||
useValue: config | ||
useValue: config, | ||
}, | ||
{ | ||
provide: FORM_ERRORS, | ||
...config.errors | ||
} | ||
...config.errors, | ||
}, | ||
]; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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