Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(addon-mobile): fix mobile-calendar size without header #8296

Merged
merged 3 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,22 @@ import {
TUI_DONE_WORD,
tuiImmutableUpdateInputDateMulti,
} from '@taiga-ui/kit';
import {identity, MonoTypeOperatorFunction, Observable, race, timer} from 'rxjs';
import {
BehaviorSubject,
identity,
MonoTypeOperatorFunction,
Observable,
race,
timer,
} from 'rxjs';
import {
debounceTime,
delay,
distinctUntilChanged,
filter,
map,
mergeMap,
skip,
switchMap,
take,
takeUntil,
Expand All @@ -73,7 +82,10 @@ import {
styleUrls: ['./mobile-calendar.style.less'],
changeDetection: ChangeDetectionStrategy.OnPush,
providers: TUI_MOBILE_CALENDAR_PROVIDERS,
host: {'[class._ios]': 'isIOS', '[class._initialized]': 'initialized'},
host: {
'[class._ios]': 'isIOS',
'[class._initialized]': 'initialized',
},
})
export class TuiMobileCalendarComponent implements AfterViewInit {
@ViewChild('yearsScrollRef')
Expand All @@ -82,6 +94,10 @@ export class TuiMobileCalendarComponent implements AfterViewInit {
@ViewChild('monthsScrollRef')
private readonly monthsScrollRef?: CdkVirtualScrollViewport;

private readonly value$ = new BehaviorSubject<
TuiDay | TuiDayRange | readonly TuiDay[] | null
>(null);

private readonly today = TuiDay.currentLocal();
private activeYear = 0;
private activeMonth = 0;
Expand All @@ -107,7 +123,12 @@ export class TuiMobileCalendarComponent implements AfterViewInit {
@Output()
readonly confirm = new EventEmitter<TuiDay | TuiDayRange | readonly TuiDay[]>();

value: TuiDay | TuiDayRange | readonly TuiDay[] | null = null;
@Output()
readonly valueChange = this.value$.pipe(
skip(1),
distinctUntilChanged((a, b) => a?.toString() === b?.toString()),
takeUntil(this.destroy$),
);

readonly years = Array.from({length: RANGE}, (_, i) => i + STARTING_YEAR);

Expand Down Expand Up @@ -147,6 +168,15 @@ export class TuiMobileCalendarComponent implements AfterViewInit {
});
}

get value(): TuiDay | TuiDayRange | readonly TuiDay[] | null {
return this.value$.value;
}

@Input()
set value(value: TuiDay | TuiDayRange | readonly TuiDay[] | null) {
this.value$.next(value);
}

get yearWidth(): number {
return this.doc.documentElement.clientWidth / YEARS_IN_ROW;
}
Expand Down Expand Up @@ -176,12 +206,14 @@ export class TuiMobileCalendarComponent implements AfterViewInit {
this.value = day;
} else if (this.isMultiValue(this.value)) {
this.value = tuiImmutableUpdateInputDateMulti(this.value, day);
} else if (this.isSingleValue(this.value)) {
this.value = new TuiDayRange(day, day);
} else if (this.value instanceof TuiDay) {
this.value = TuiDayRange.sort(this.value, day);
} else if (this.value instanceof TuiDayRange && !this.value.isSingleDay) {
this.value = day;
} else if (this.value instanceof TuiDayRange) {
this.value = TuiDayRange.sort(this.value.from, day);
} else if (!this.value) {
this.value = new TuiDayRange(day, day);
this.value = day;
}
}

Expand Down Expand Up @@ -242,10 +274,6 @@ export class TuiMobileCalendarComponent implements AfterViewInit {
return !(day instanceof TuiDay) && !(day instanceof TuiDayRange) && this.multi;
}

private isSingleValue(day: any): day is TuiDay {
return day instanceof TuiDay || (day instanceof TuiDayRange && !day.isSingleDay);
}

private get initialYear(): number {
if (!this.value) {
return this.today.year;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@
:host._ios & {
height: ~'calc(100% - 8.75rem)';
}

&._without_header {
height: ~'calc(100% - 6rem)';
}
}

.t-month-wrapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<cdk-virtual-scroll-viewport
#monthsScrollRef
class="t-months"
[class._without_header]="!chooseDayOrRangeTexts$"
(scrolledIndexChange)="onMonthChange($event)"
>
<section
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export class ExampleTuiMobileCalendarComponent {

single = true;

multi = false;

readonly disabledItemHandlerVariants: ReadonlyArray<TuiBooleanHandler<TuiDay>> = [
ALWAYS_FALSE_HANDLER,
({day}) => day % 3 === 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,21 @@
[disabledItemHandler]="disabledItemHandler"
[max]="max"
[min]="min"
[multi]="multi"
[single]="single"
(cancel)="documentationPropertyCancel.emitEvent($event)"
(confirm)="documentationPropertyConfirm.emitEvent($event)"
></tui-mobile-calendar>
</tui-doc-demo>

<tui-doc-documentation>
<ng-template
documentationPropertyMode="input-output"
documentationPropertyName="value"
documentationPropertyType="TuiDay | TuiDayRange | readonly TuiDay[] | null"
>
Value
</ng-template>
<ng-template
documentationPropertyMode="input"
documentationPropertyName="disabledItemHandler"
Expand Down Expand Up @@ -144,6 +152,14 @@
>
Single date or a range
</ng-template>
<ng-template
documentationPropertyMode="input"
documentationPropertyName="multi"
documentationPropertyType="boolean"
[(documentationPropertyValue)]="multi"
>
Array of single dates
</ng-template>
<ng-template
#documentationPropertyCancel="documentationProperty"
documentationPropertyMode="output"
Expand Down
Loading