-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CM-68: Refactor form utils, styles (#21)
- Loading branch information
Showing
33 changed files
with
160 additions
and
141 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@vality/ng-core", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"sideEffects": false, | ||
"exports": { | ||
".": { | ||
|
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
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
11 changes: 11 additions & 0 deletions
11
projects/ng-core/src/lib/components/dialog/_dialog-theme.scss
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,11 @@ | ||
@use '@angular/material' as mat; | ||
|
||
@mixin theme($theme) { | ||
$typography: map-get($theme, typography); | ||
|
||
.v-dialog { | ||
.title { | ||
@include mat.typography-level($typography, headline-5); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
projects/ng-core/src/lib/components/dialog/dialog.component.html
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
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
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
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
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
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,5 +1,7 @@ | ||
@use '../components/table/table-theme'; | ||
@use '../components/dialog/dialog-theme'; | ||
|
||
@mixin all-component-themes($theme-or-color-config) { | ||
@include table-theme.theme($theme-or-color-config); | ||
@include dialog-theme.theme($theme-or-color-config); | ||
} |
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
37 changes: 37 additions & 0 deletions
37
projects/ng-core/src/lib/utils/form/form-wrappers/abstract-control-superclass.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,37 @@ | ||
import { ValidationErrors } from '@angular/forms'; | ||
import { WrappedControlSuperclass } from '@s-libs/ng-core'; | ||
import isEqual from 'lodash-es/isEqual'; | ||
import { EMPTY, Observable, switchMap } from 'rxjs'; | ||
import { distinctUntilChanged, map, startWith } from 'rxjs/operators'; | ||
|
||
import { getErrorsTree } from './utils/get-errors-tree'; | ||
import { hasControls } from '../has-controls'; | ||
|
||
export abstract class AbstractControlSuperclass< | ||
OuterType, | ||
InnerType = OuterType | ||
> extends WrappedControlSuperclass<OuterType, InnerType> { | ||
override setDisabledState(isDisabled: boolean): void { | ||
// If the form group control is disabled, then it turns it on during initialization | ||
if (hasControls(this.control)) { | ||
return; | ||
} | ||
super.setDisabledState(isDisabled); | ||
} | ||
|
||
protected override setUpInnerToOuterErrors$( | ||
inner$: Observable<ValidationErrors> | ||
): Observable<ValidationErrors> { | ||
return inner$.pipe( | ||
switchMap(() => this.control.statusChanges.pipe(startWith(this.control.status))), | ||
map(() => getErrorsTree(this.control) || {}), | ||
distinctUntilChanged(isEqual) | ||
); | ||
} | ||
|
||
protected override setUpOuterToInnerErrors$( | ||
_outer$: Observable<ValidationErrors> | ||
): Observable<ValidationErrors> { | ||
return EMPTY; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
projects/ng-core/src/lib/utils/form/form-wrappers/form-array-superclass.directive.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,9 @@ | ||
import { Directive } from '@angular/core'; | ||
|
||
import { FormGroupSuperclass } from './form-group-superclass.directive'; | ||
|
||
@Directive() | ||
export abstract class FormArraySuperclass< | ||
OuterType, | ||
InnerType = OuterType | ||
> extends FormGroupSuperclass<OuterType, InnerType> {} |
12 changes: 12 additions & 0 deletions
12
projects/ng-core/src/lib/utils/form/form-wrappers/form-control-superclass.directive.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,12 @@ | ||
import { Directive } from '@angular/core'; | ||
import { FormControl } from '@angular/forms'; | ||
|
||
import { AbstractControlSuperclass } from './abstract-control-superclass'; | ||
|
||
@Directive() | ||
export class FormControlSuperclass< | ||
OuterType, | ||
InnerType = OuterType | ||
> extends AbstractControlSuperclass<OuterType, InnerType> { | ||
control = new FormControl() as FormControl<InnerType>; | ||
} |
30 changes: 30 additions & 0 deletions
30
projects/ng-core/src/lib/utils/form/form-wrappers/form-group-superclass.directive.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,30 @@ | ||
import { Directive, OnInit } from '@angular/core'; | ||
import { FormGroup } from '@angular/forms'; | ||
|
||
import { AbstractControlSuperclass } from './abstract-control-superclass'; | ||
import { getValue } from '../get-value'; | ||
import { hasControls } from '../has-controls'; | ||
|
||
@Directive() | ||
export abstract class FormGroupSuperclass<OuterType, InnerType = OuterType> | ||
extends AbstractControlSuperclass<OuterType, InnerType> | ||
implements OnInit | ||
{ | ||
protected emptyValue!: InnerType; | ||
|
||
override ngOnInit() { | ||
this.emptyValue = getValue(this.control) as InnerType; | ||
super.ngOnInit(); | ||
} | ||
|
||
protected override outerToInnerValue(outer: OuterType): InnerType { | ||
if (hasControls(this.control)) { | ||
if (!outer) return this.emptyValue; | ||
if ( | ||
Object.keys(outer).length < Object.keys((this.control as FormGroup).controls).length | ||
) | ||
return Object.assign({}, this.emptyValue, outer); | ||
} | ||
return outer as never; | ||
} | ||
} |
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,5 @@ | ||
export * from './form-group-superclass.directive'; | ||
export * from './utils/provide-value-accessor'; | ||
export * from './utils/create-control-providers'; | ||
export * from './utils/get-errors-tree'; | ||
export * from './form-control-superclass.directive'; |
2 changes: 0 additions & 2 deletions
2
...ol-superclass/create-control-providers.ts → ...rappers/utils/create-control-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,9 +1,7 @@ | ||
import { Provider, Type } from '@angular/core'; | ||
|
||
import { provideValidators } from './provide-validators'; | ||
import { provideValueAccessor } from './provide-value-accessor'; | ||
|
||
export const createControlProviders = (component: () => Type<unknown>): Provider[] => [ | ||
provideValueAccessor(component), | ||
provideValidators(component), | ||
]; |
File renamed without changes.
File renamed without changes.
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,3 +1,4 @@ | ||
export * from './get-form-value-changes'; | ||
export * from './validated-control-superclass'; | ||
export * from './form-wrappers'; | ||
export * from './get-valid-value-changes'; | ||
export * from './set-disabled'; |
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,11 @@ | ||
import { AbstractControl } from '@angular/forms'; | ||
|
||
export function setDisabled( | ||
control?: AbstractControl, | ||
disabled: boolean = true, | ||
options: { onlySelf?: boolean; emitEvent?: boolean } = {} | ||
) { | ||
if (!control) return; | ||
if (disabled) control.disable(options); | ||
else control.enable(options); | ||
} |
Oops, something went wrong.