-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kit): create TUI_TIME_VALUE_TRANSFORMER for tui-input-time compo…
…nent
- Loading branch information
Showing
11 changed files
with
281 additions
and
79 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
46 changes: 9 additions & 37 deletions
46
projects/demo/src/modules/components/input-time/examples/6/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 |
---|---|---|
@@ -1,39 +1,11 @@ | ||
<form | ||
class="b-form" | ||
[formGroup]="testForm" | ||
<tui-input-time | ||
[formControl]="control" | ||
[items]="items" | ||
> | ||
<tui-input-time | ||
formControlName="testValue" | ||
class="tui-space_bottom-3" | ||
[tuiTextfieldCleaner]="true" | ||
> | ||
Choose a time | ||
</tui-input-time> | ||
Input time | ||
</tui-input-time> | ||
|
||
<tui-input-time | ||
formControlName="testValue2" | ||
mode="HH:MM:SS" | ||
class="tui-space_bottom-3" | ||
[tuiTextfieldCleaner]="true" | ||
> | ||
Choose a time | ||
</tui-input-time> | ||
|
||
<tui-input-time | ||
formControlName="testValue3" | ||
class="tui-space_bottom-3" | ||
[items]="items" | ||
[tuiTextfieldCleaner]="true" | ||
> | ||
Choose a time | ||
</tui-input-time> | ||
|
||
<tui-input-time | ||
formControlName="testValue4" | ||
mode="HH:MM:SS" | ||
[items]="items" | ||
[tuiTextfieldCleaner]="true" | ||
> | ||
Choose a time | ||
</tui-input-time> | ||
</form> | ||
<p>Stringified control value:</p> | ||
<p> | ||
<code>{{ control.value }}</code> | ||
</p> |
36 changes: 22 additions & 14 deletions
36
projects/demo/src/modules/components/input-time/examples/6/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 |
---|---|---|
@@ -1,28 +1,36 @@ | ||
import {Component} from '@angular/core'; | ||
import {FormControl, FormGroup} from '@angular/forms'; | ||
import {FormControl} from '@angular/forms'; | ||
import {changeDetection} from '@demo/emulate/change-detection'; | ||
import {encapsulation} from '@demo/emulate/encapsulation'; | ||
import {TuiTime} from '@taiga-ui/cdk'; | ||
import {tuiCreateTimePeriods, tuiInputTimeOptionsProvider} from '@taiga-ui/kit'; | ||
import {AbstractTuiValueTransformer, TuiTime} from '@taiga-ui/cdk'; | ||
import {TUI_TIME_VALUE_TRANSFORMER, tuiCreateTimePeriods} from '@taiga-ui/kit'; | ||
|
||
class ExampleTimeTransformer extends AbstractTuiValueTransformer< | ||
TuiTime | null, | ||
string | null | ||
> { | ||
fromControlValue(controlValue: string): TuiTime | null { | ||
return controlValue ? TuiTime.fromString(controlValue) : null; | ||
} | ||
|
||
toControlValue(time: TuiTime | null): string { | ||
return time ? time.toString() : ''; | ||
} | ||
} | ||
|
||
@Component({ | ||
selector: 'tui-input-time-example-6', | ||
templateUrl: './index.html', | ||
encapsulation, | ||
changeDetection, | ||
providers: [ | ||
tuiInputTimeOptionsProvider({ | ||
nativePicker: true, | ||
}), | ||
{ | ||
provide: TUI_TIME_VALUE_TRANSFORMER, | ||
useClass: ExampleTimeTransformer, | ||
}, | ||
], | ||
}) | ||
export class TuiInputTimeExample6 { | ||
readonly testForm = new FormGroup({ | ||
testValue: new FormControl(new TuiTime(10, 30)), | ||
testValue2: new FormControl(new TuiTime(10, 30, 0)), | ||
testValue3: new FormControl(new TuiTime(14, 30)), | ||
testValue4: new FormControl(new TuiTime(10, 30, 0)), | ||
}); | ||
|
||
readonly items = tuiCreateTimePeriods(14, 16, [0, 30]); | ||
readonly control = new FormControl(''); | ||
readonly items = tuiCreateTimePeriods(); | ||
} |
39 changes: 39 additions & 0 deletions
39
projects/demo/src/modules/components/input-time/examples/7/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,39 @@ | ||
<form | ||
class="b-form" | ||
[formGroup]="testForm" | ||
> | ||
<tui-input-time | ||
formControlName="testValue" | ||
class="tui-space_bottom-3" | ||
[tuiTextfieldCleaner]="true" | ||
> | ||
Choose a time | ||
</tui-input-time> | ||
|
||
<tui-input-time | ||
formControlName="testValue2" | ||
mode="HH:MM:SS" | ||
class="tui-space_bottom-3" | ||
[tuiTextfieldCleaner]="true" | ||
> | ||
Choose a time | ||
</tui-input-time> | ||
|
||
<tui-input-time | ||
formControlName="testValue3" | ||
class="tui-space_bottom-3" | ||
[items]="items" | ||
[tuiTextfieldCleaner]="true" | ||
> | ||
Choose a time | ||
</tui-input-time> | ||
|
||
<tui-input-time | ||
formControlName="testValue4" | ||
mode="HH:MM:SS" | ||
[items]="items" | ||
[tuiTextfieldCleaner]="true" | ||
> | ||
Choose a time | ||
</tui-input-time> | ||
</form> |
28 changes: 28 additions & 0 deletions
28
projects/demo/src/modules/components/input-time/examples/7/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,28 @@ | ||
import {Component} from '@angular/core'; | ||
import {FormControl, FormGroup} from '@angular/forms'; | ||
import {changeDetection} from '@demo/emulate/change-detection'; | ||
import {encapsulation} from '@demo/emulate/encapsulation'; | ||
import {TuiTime} from '@taiga-ui/cdk'; | ||
import {tuiCreateTimePeriods, tuiInputTimeOptionsProvider} from '@taiga-ui/kit'; | ||
|
||
@Component({ | ||
selector: 'tui-input-time-example-7', | ||
templateUrl: './index.html', | ||
encapsulation, | ||
changeDetection, | ||
providers: [ | ||
tuiInputTimeOptionsProvider({ | ||
nativePicker: true, | ||
}), | ||
], | ||
}) | ||
export class TuiInputTimeExample7 { | ||
readonly testForm = new FormGroup({ | ||
testValue: new FormControl(new TuiTime(10, 30)), | ||
testValue2: new FormControl(new TuiTime(10, 30, 0)), | ||
testValue3: new FormControl(new TuiTime(14, 30)), | ||
testValue4: new FormControl(new TuiTime(10, 30, 0)), | ||
}); | ||
|
||
readonly items = tuiCreateTimePeriods(14, 16, [0, 30]); | ||
} |
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
Oops, something went wrong.