Skip to content

Commit

Permalink
fix: new component interface
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriocomo committed Jul 30, 2024
1 parent ebbf885 commit 6414c00
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import { TransferItem } from './transfer.model';
})
export class ItTransferComponent<T = any> extends ItAbstractFormComponent<T> implements OnInit {
/**
* The source options (left side)
* The select options (left side)
*/
@Input() source = [];
@Input() options = [];
/**
* The target options (right side)
* The selected options (right side)
*/
@Input() target = [];
@Input() selected = [];
/**
* Fired when there is a transfer, a backtransfer or a reset event
*/
Expand Down Expand Up @@ -136,12 +136,12 @@ export class ItTransferComponent<T = any> extends ItAbstractFormComponent<T> imp
}

console.debug('ngControl is defined. Input() target will be ignored');
} else if (this.target && Array.isArray(this.target)) {
target = [...this.target];
} else if (this.selected && Array.isArray(this.selected)) {
target = [...this.selected];
}

console.debug('target:', this.target, 'formControl:', this.control.value, 'ngModel:', this._ngControl);
this.store.init({ source: [...this.source], target });
console.debug('target:', this.selected, 'formControl:', this.control.value, 'ngModel:', this._ngControl);
this.store.init({ source: [...this.options], target });
}

private onStoreValueChanged() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ <h3>Esempio senza form</h3>
<div class="row">
<div class="col">
<h5>Esempio di default</h5>
<it-transfer [source]="sourceItems" [target]="targetItems" (transferChanges)="transferChangesHandler($event)"></it-transfer>
<it-transfer [options]="options" [selected]="selected" (transferChanges)="transferChangesHandler($event)"></it-transfer>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TransferItem } from 'projects/design-angular-kit/src/public_api';
templateUrl: './transfer-default-example.component.html',
})
export class TransferDefaultExampleComponent {
readonly sourceItems: TransferItem<number>[] = [
readonly options: TransferItem<number>[] = [
{
text: 'Item 1',
value: 1,
Expand All @@ -16,7 +16,7 @@ export class TransferDefaultExampleComponent {
value: 2,
},
];
readonly targetItems: TransferItem<number>[] = [
readonly selected: TransferItem<number>[] = [
{
text: 'Item 3',
value: 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ <h3>Esempio con Reactive Form</h3>
<div class="col">
<h5>FormGroup</h5>
<form [formGroup]="formGroup">
<it-transfer formControlName="transfer" [source]="sourceItems"></it-transfer>
<it-transfer formControlName="transfer" [options]="options"></it-transfer>
</form>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { TransferItem } from 'projects/design-angular-kit/src/public_api';
templateUrl: './transfer-reactive-form-example.component.html',
})
export class TransferReactiveFormExampleComponent {
readonly sourceItems: TransferItem<number>[] = [
readonly options: TransferItem<number>[] = [
{
text: 'Item 1',
value: 1,
Expand All @@ -17,14 +17,14 @@ export class TransferReactiveFormExampleComponent {
value: 2,
},
];
readonly targetItems: TransferItem<number>[] = [
readonly selected: TransferItem<number>[] = [
{
text: 'Item 3',
value: 3,
},
];

readonly formGroup = inject(FormBuilder).group({
transfer: [this.targetItems],
transfer: [this.selected],
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ <h3>Esempio con Template Form</h3>
<div class="row">
<div class="col">
<h5>NgModel</h5>
<it-transfer [(ngModel)]="transferModel" [source]="sourceItems"></it-transfer>
<it-transfer [(ngModel)]="transferModel" [options]="options"></it-transfer>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TransferItem } from 'projects/design-angular-kit/src/public_api';
templateUrl: './transfer-template-form-example.component.html',
})
export class TransferTemplateFormExampleComponent {
readonly sourceItems: TransferItem<number>[] = [
readonly options: TransferItem<number>[] = [
{
text: 'Item 1',
value: 1,
Expand All @@ -16,12 +16,12 @@ export class TransferTemplateFormExampleComponent {
value: 2,
},
];
readonly targetItems: TransferItem<number>[] = [
readonly selected: TransferItem<number>[] = [
{
text: 'Item 3',
value: 3,
},
];

transferModel = this.targetItems;
transferModel = this.selected;
}

0 comments on commit 6414c00

Please sign in to comment.