-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: formly - data type of the input addon text extended by Observab…
…le<string>
- Loading branch information
Showing
3 changed files
with
30 additions
and
15 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
6 changes: 3 additions & 3 deletions
6
src/app/shared/formly/wrappers/input-addon-wrapper/input-addon-wrapper.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
<div class="align-items-start" [ngClass]="{ 'input-group': to.addonLeft || to.addonRight }"> | ||
<div class="align-items-start flex-nowrap" [ngClass]="{ 'input-group': to.addonLeft || to.addonRight }"> | ||
<div *ngIf="to.addonLeft" class="input-group-prepend"> | ||
<span class="input-group-text">{{ to.addonLeft?.text | translate }}</span> | ||
<span class="input-group-text">{{ addonLeftText | async | translate }}</span> | ||
</div> | ||
<div class="flex-grow-1"><ng-container #fieldComponent></ng-container></div> | ||
<div *ngIf="to.addonRight" class="input-group-append"> | ||
<span class="input-group-text">{{ to.addonRight?.text | translate }}</span> | ||
<span class="input-group-text">{{ addonRightText | async | translate }}</span> | ||
</div> | ||
</div> |
21 changes: 18 additions & 3 deletions
21
src/app/shared/formly/wrappers/input-addon-wrapper/input-addon-wrapper.component.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,16 +1,31 @@ | ||
import { ChangeDetectionStrategy, Component } from '@angular/core'; | ||
import { FieldWrapper } from '@ngx-formly/core'; | ||
import { of } from 'rxjs'; | ||
|
||
/** | ||
* Wrapper to add input-addons to fields, using bootstrap styling. | ||
* | ||
* @templateOption **addonRight** - object of type ``{ text: string }`` that will be used to render an input addon to the right of the field. | ||
* @templateOption **addonLeft** - object of type ``{ text: string }`` that will be used to render an input addon to the left of the field. | ||
* @templateOption **addonRight** - object of type ``{ text: string }`` or ``{ text: Observable<string> }`` that will be used to render an input addon to the right of the field. | ||
* @templateOption **addonLeft** - object of type ``{ text: string }`` or ``{ text: Observable<string> }`` that will be used to render an input addon to the left of the field. | ||
* | ||
*/ | ||
@Component({ | ||
selector: 'ish-input-addon-wrapper', | ||
templateUrl: './input-addon-wrapper.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class InputAddonWrapperComponent extends FieldWrapper {} | ||
export class InputAddonWrapperComponent extends FieldWrapper { | ||
get addonLeftText() { | ||
if (!this.to.addonLeft?.text) { | ||
return; | ||
} | ||
return typeof this.to.addonLeft.text === 'string' ? of(this.to.addonLeft.text) : this.to.addonLeft.text; | ||
} | ||
|
||
get addonRightText() { | ||
if (!this.to.addonRight?.text) { | ||
return; | ||
} | ||
return typeof this.to.addonRight.text === 'string' ? of(this.to.addonRight.text) : this.to.addonRight.text; | ||
} | ||
} |