-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(demo): add form example for tui-checkbox (#8921)
- Loading branch information
Showing
4 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
projects/demo/src/modules/components/checkbox/examples/3/index.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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<ng-container *ngIf="currentQuestion < 2; else result"> | ||
<p>{{ currentQuestion + 1 }}. {{ questionTitles[currentQuestion] }}</p> | ||
|
||
<form [formGroup]="form"> | ||
<label *ngFor="let option of questions[currentQuestion]; let index = index"> | ||
<input | ||
size="s" | ||
tuiCheckbox | ||
type="checkbox" | ||
[formControlName]="index" | ||
/> | ||
{{ option }} | ||
</label> | ||
</form> | ||
|
||
<button | ||
size="s" | ||
tuiButton | ||
type="button" | ||
class="tui-space_top-4" | ||
(click)="nextQuestion()" | ||
> | ||
Next | ||
</button> | ||
</ng-container> | ||
|
||
<ng-template #result> | ||
<p><b>Your answers</b></p> | ||
|
||
<div | ||
*ngFor="let options of results; let i = index" | ||
class="tui-space_top-4" | ||
> | ||
<p>{{ i + 1 }}. {{ questionTitles[i] }}</p> | ||
|
||
<label *ngFor="let question of questions[i]; let j = index"> | ||
<input | ||
size="s" | ||
tuiCheckbox | ||
type="checkbox" | ||
[checked]="options[j]" | ||
/> | ||
{{ question }} | ||
</label> | ||
</div> | ||
</ng-template> |
5 changes: 5 additions & 0 deletions
5
projects/demo/src/modules/components/checkbox/examples/3/index.less
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 @@ | ||
label { | ||
display: flex; | ||
align-items: center; | ||
gap: 0.5rem; | ||
} |
57 changes: 57 additions & 0 deletions
57
projects/demo/src/modules/components/checkbox/examples/3/index.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,57 @@ | ||
import {JsonPipe, NgForOf, NgIf} from '@angular/common'; | ||
import {Component} from '@angular/core'; | ||
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule} from '@angular/forms'; | ||
import {changeDetection} from '@demo/emulate/change-detection'; | ||
import {encapsulation} from '@demo/emulate/encapsulation'; | ||
import {TuiButton} from '@taiga-ui/core'; | ||
import {TuiCheckbox} from '@taiga-ui/kit'; | ||
|
||
@Component({ | ||
standalone: true, | ||
imports: [ | ||
FormsModule, | ||
JsonPipe, | ||
NgForOf, | ||
NgIf, | ||
ReactiveFormsModule, | ||
TuiButton, | ||
TuiCheckbox, | ||
], | ||
templateUrl: './index.html', | ||
styleUrls: ['./index.less'], | ||
encapsulation, | ||
changeDetection, | ||
}) | ||
export default class Example { | ||
protected readonly questionTitles = [ | ||
'What framework do you like?', | ||
'What library do you like?', | ||
]; | ||
|
||
protected readonly questions = [ | ||
['Angular', 'React', 'Vue'], | ||
['Taiga UI', 'Material UI', 'PrimeNG'], | ||
]; | ||
|
||
protected currentQuestion = 0; | ||
|
||
protected results: boolean[][] = []; | ||
|
||
protected form = new FormGroup({ | ||
0: new FormControl(false), | ||
1: new FormControl(false), | ||
2: new FormControl(false), | ||
}); | ||
|
||
protected nextQuestion(): void { | ||
this.currentQuestion++; | ||
|
||
this.results.push(Object.values(this.form.value).map(Boolean)); | ||
|
||
this.form = new FormGroup({ | ||
0: new FormControl(false), | ||
1: new FormControl(false), | ||
2: new FormControl(false), | ||
}); | ||
} | ||
} |
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