-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kit): support null in
tuiImmutableUpdateInputDateMulti
(#6176)
- Loading branch information
Showing
11 changed files
with
277 additions
and
46 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
16 changes: 16 additions & 0 deletions
16
projects/demo/src/modules/components/mobile-calendar/examples/4/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,16 @@ | ||
<div class="wrapper"> | ||
<button | ||
appearance="secondary" | ||
icon="tuiIconCalendarLarge" | ||
shape="rounded" | ||
tuiIconButton | ||
type="button" | ||
(click)="onClick()" | ||
></button> | ||
<span | ||
class="date" | ||
[class.date_empty]="empty" | ||
> | ||
{{ date$ | async }} | ||
</span> | ||
</div> |
12 changes: 12 additions & 0 deletions
12
projects/demo/src/modules/components/mobile-calendar/examples/4/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,12 @@ | ||
.wrapper { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.date { | ||
margin-left: 1rem; | ||
|
||
&_empty { | ||
color: var(--tui-text-03); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
projects/demo/src/modules/components/mobile-calendar/examples/4/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,75 @@ | ||
import {Component, Inject, Injector} from '@angular/core'; | ||
import {FormControl} from '@angular/forms'; | ||
import {changeDetection} from '@demo/emulate/change-detection'; | ||
import {encapsulation} from '@demo/emulate/encapsulation'; | ||
import {TuiMobileCalendarDialogComponent} from '@taiga-ui/addon-mobile'; | ||
import {tuiControlValue, TuiDay, TuiDayRange} from '@taiga-ui/cdk'; | ||
import {TUI_MONTHS, TuiDialogService} from '@taiga-ui/core'; | ||
import {TUI_CALENDAR_DATE_STREAM} from '@taiga-ui/kit'; | ||
import {PolymorpheusComponent} from '@tinkoff/ng-polymorpheus'; | ||
import {combineLatest, Observable} from 'rxjs'; | ||
import {map} from 'rxjs/operators'; | ||
|
||
@Component({ | ||
selector: 'tui-mobile-calendar-example-4', | ||
templateUrl: './index.html', | ||
styleUrls: ['./index.less'], | ||
encapsulation, | ||
changeDetection, | ||
}) | ||
export class TuiMobileCalendarExample4 { | ||
private readonly control = new FormControl(null); | ||
|
||
private readonly dialog$: Observable<TuiDayRange> = this.dialogs.open( | ||
new PolymorpheusComponent( | ||
TuiMobileCalendarDialogComponent, | ||
Injector.create({ | ||
providers: [ | ||
{ | ||
provide: TUI_CALENDAR_DATE_STREAM, | ||
useValue: tuiControlValue(this.control), | ||
}, | ||
], | ||
parent: this.injector, | ||
}), | ||
), | ||
{ | ||
size: 'fullscreen', | ||
closeable: false, | ||
data: { | ||
min: new TuiDay(2018, 2, 10), | ||
}, | ||
}, | ||
); | ||
|
||
readonly date$ = combineLatest([ | ||
tuiControlValue<TuiDayRange>(this.control), | ||
this.months$, | ||
]).pipe( | ||
map(([value, months]) => { | ||
if (!value) { | ||
return 'Choose a date range'; | ||
} | ||
|
||
return value.isSingleDay | ||
? `${months[value.from.month]} ${value.from.day}, ${value.from.year}` | ||
: `${months[value.from.month]} ${value.from.day}, ${value.from.year} - ${ | ||
months[value.to.month] | ||
} ${value.to.day}, ${value.to.year}`; | ||
}), | ||
); | ||
|
||
constructor( | ||
@Inject(TuiDialogService) private readonly dialogs: TuiDialogService, | ||
@Inject(Injector) private readonly injector: Injector, | ||
@Inject(TUI_MONTHS) private readonly months$: Observable<string[]>, | ||
) {} | ||
|
||
get empty(): boolean { | ||
return !this.control.value; | ||
} | ||
|
||
onClick(): void { | ||
this.dialog$.subscribe(value => this.control.setValue(value)); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
projects/demo/src/modules/components/mobile-calendar/examples/5/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,16 @@ | ||
<div class="wrapper"> | ||
<button | ||
appearance="secondary" | ||
icon="tuiIconCalendarLarge" | ||
shape="rounded" | ||
tuiIconButton | ||
type="button" | ||
(click)="onClick()" | ||
></button> | ||
<span | ||
class="date" | ||
[class.date_empty]="empty" | ||
> | ||
{{ date$ | async }} | ||
</span> | ||
</div> |
12 changes: 12 additions & 0 deletions
12
projects/demo/src/modules/components/mobile-calendar/examples/5/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,12 @@ | ||
.wrapper { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.date { | ||
margin-left: 1rem; | ||
|
||
&_empty { | ||
color: var(--tui-text-03); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
projects/demo/src/modules/components/mobile-calendar/examples/5/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,74 @@ | ||
import {Component, Inject, Injector} from '@angular/core'; | ||
import {FormControl} from '@angular/forms'; | ||
import {changeDetection} from '@demo/emulate/change-detection'; | ||
import {encapsulation} from '@demo/emulate/encapsulation'; | ||
import {TuiMobileCalendarDialogComponent} from '@taiga-ui/addon-mobile'; | ||
import {tuiControlValue, TuiDay} from '@taiga-ui/cdk'; | ||
import {TUI_MONTHS, TuiDialogService} from '@taiga-ui/core'; | ||
import {TUI_CALENDAR_DATE_STREAM} from '@taiga-ui/kit'; | ||
import {PolymorpheusComponent} from '@tinkoff/ng-polymorpheus'; | ||
import {combineLatest, Observable} from 'rxjs'; | ||
import {map} from 'rxjs/operators'; | ||
|
||
@Component({ | ||
selector: 'tui-mobile-calendar-example-5', | ||
templateUrl: './index.html', | ||
styleUrls: ['./index.less'], | ||
encapsulation, | ||
changeDetection, | ||
}) | ||
export class TuiMobileCalendarExample5 { | ||
private readonly control = new FormControl(null); | ||
|
||
private readonly dialog$: Observable<readonly TuiDay[]> = this.dialogs.open( | ||
new PolymorpheusComponent( | ||
TuiMobileCalendarDialogComponent, | ||
Injector.create({ | ||
providers: [ | ||
{ | ||
provide: TUI_CALENDAR_DATE_STREAM, | ||
useValue: tuiControlValue(this.control), | ||
}, | ||
], | ||
parent: this.injector, | ||
}), | ||
), | ||
{ | ||
size: 'fullscreen', | ||
closeable: false, | ||
data: { | ||
multi: true, | ||
min: new TuiDay(2018, 2, 10), | ||
}, | ||
}, | ||
); | ||
|
||
readonly date$ = combineLatest([ | ||
tuiControlValue<readonly TuiDay[]>(this.control), | ||
this.months$, | ||
]).pipe( | ||
map(([value, months]) => { | ||
if (!value?.length) { | ||
return 'Choose dates'; | ||
} | ||
|
||
return value | ||
.map(day => `${months[day.month]} ${day.day}, ${day.year}`) | ||
.join('; '); | ||
}), | ||
); | ||
|
||
constructor( | ||
@Inject(TuiDialogService) private readonly dialogs: TuiDialogService, | ||
@Inject(Injector) private readonly injector: Injector, | ||
@Inject(TUI_MONTHS) private readonly months$: Observable<string[]>, | ||
) {} | ||
|
||
get empty(): boolean { | ||
return !this.control.value?.length; | ||
} | ||
|
||
onClick(): void { | ||
this.dialog$.subscribe(value => this.control.setValue(value)); | ||
} | ||
} |
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,10 +1,12 @@ | ||
import {TuiDay} from '@taiga-ui/cdk'; | ||
|
||
export function tuiImmutableUpdateInputDateMulti( | ||
days: readonly TuiDay[] = [], | ||
days: readonly TuiDay[] | null = [], | ||
day: TuiDay, | ||
): readonly TuiDay[] { | ||
return days.find(item => item.daySame(day)) | ||
? days.filter(item => !item.daySame(day)) | ||
: days.concat(day); | ||
return ( | ||
(days?.find(item => item.daySame(day)) | ||
? days.filter(item => !item.daySame(day)) | ||
: days?.concat(day)) || [] | ||
); | ||
} |