Skip to content

Commit

Permalink
refactor(core)!: replace TUI_ANIMATIONS_DURATION with `TUI_ANIMATIO…
Browse files Browse the repository at this point in the history
…NS_SPEED` (#6542)
  • Loading branch information
waterplea authored Jan 25, 2024
1 parent 75f9762 commit 9b6732a
Show file tree
Hide file tree
Showing 30 changed files with 141 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Directive, ElementRef, Inject, Input, NgZone, Self} from '@angular/core'
import {ANIMATION_FRAME, PERFORMANCE} from '@ng-web-apis/common';
import {tuiDescribeSector} from '@taiga-ui/addon-charts/utils';
import {tuiClamp, TuiDestroyService, tuiEaseInOutQuad, tuiZonefree} from '@taiga-ui/cdk';
import {TUI_ANIMATIONS_DURATION} from '@taiga-ui/core';
import {TUI_ANIMATIONS_SPEED, tuiGetDuration} from '@taiga-ui/core';
import {
BehaviorSubject,
map,
Expand Down Expand Up @@ -31,7 +31,7 @@ export class TuiPieChartDirective {
@Self() @Inject(TuiDestroyService) destroy$: Observable<unknown>,
@Inject(PERFORMANCE) performance: Performance,
@Inject(ANIMATION_FRAME) animationFrame$: Observable<number>,
@Inject(TUI_ANIMATIONS_DURATION) duration: number,
@Inject(TUI_ANIMATIONS_SPEED) speed: number,
) {
this.sector$
.pipe(
Expand All @@ -44,7 +44,7 @@ export class TuiPieChartDirective {
return animationFrame$.pipe(
map(timestamp =>
tuiEaseInOutQuad(
tuiClamp((timestamp - now) / duration, 0, 1),
tuiClamp((timestamp - now) / tuiGetDuration(speed), 0, 1),
),
),
takeWhile(progress => progress < 1, true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ import {
TuiTypedMapper,
} from '@taiga-ui/cdk';
import {
TUI_ANIMATIONS_DURATION,
TUI_ANIMATIONS_SPEED,
TUI_CLOSE_WORD,
TUI_COMMON_ICONS,
TUI_SHORT_WEEK_DAYS,
TuiCommonIcons,
tuiGetDuration,
} from '@taiga-ui/core';
import {
TUI_CANCEL_WORD,
Expand Down Expand Up @@ -140,7 +141,7 @@ export class TuiMobileCalendarComponent implements AfterViewInit {
readonly unorderedWeekDays$: TuiInjectionTokenType<typeof TUI_SHORT_WEEK_DAYS>,
@Inject(TUI_CHOOSE_DAY_OR_RANGE_TEXTS)
readonly chooseDayOrRangeTexts$: Observable<[string, string, string]>,
@Inject(TUI_ANIMATIONS_DURATION) private readonly duration: number,
@Inject(TUI_ANIMATIONS_SPEED) private readonly speed: number,
@Inject(NgZone) private readonly ngZone: NgZone,
) {
valueChanges.pipe(takeUntil(this.destroy$)).subscribe(value => {
Expand Down Expand Up @@ -304,7 +305,7 @@ export class TuiMobileCalendarComponent implements AfterViewInit {

this.monthsScrollRef?.scrolledIndexChange
.pipe(
delay(this.duration),
delay(tuiGetDuration(this.speed)),
this.lateInit(),
take(1),
takeUntil(this.destroy$),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import {
} from '@angular/core';
import {EMPTY_QUERY, TuiDialog, tuiPure} from '@taiga-ui/cdk';
import {
TUI_ANIMATIONS_DURATION,
TUI_ANIMATIONS_SPEED,
TUI_CLOSE_WORD,
TUI_COMMON_ICONS,
TuiCommonIcons,
tuiGetDuration,
tuiSlideInTop,
} from '@taiga-ui/core';
import {shouldCall} from '@tinkoff/ng-event-plugins';
Expand Down Expand Up @@ -54,15 +55,15 @@ export class TuiSheetDialogComponent<I> implements AfterViewInit {
value: '',
params: {
start: '100vh',
duration: this.duration,
duration: tuiGetDuration(this.speed),
},
};

stuck$ = new BehaviorSubject(false);

constructor(
@Inject(ElementRef) private readonly el: ElementRef<HTMLElement>,
@Inject(TUI_ANIMATIONS_DURATION) private readonly duration: number,
@Inject(TUI_ANIMATIONS_SPEED) private readonly speed: number,
@Inject(TUI_COMMON_ICONS) readonly icons: TuiCommonIcons,
@Inject(TUI_CLOSE_WORD) readonly closeWord$: Observable<string>,
@Inject(POLYMORPHEUS_CONTEXT)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import {AnimationOptions} from '@angular/animations';
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
Inject,
inject,
OnInit,
Self,
} from '@angular/core';
import {TUI_WINDOW_HEIGHT, TuiDestroyService} from '@taiga-ui/cdk';
import {TUI_ANIMATION_OPTIONS, tuiFadeIn, tuiSlideInTop} from '@taiga-ui/core';
import {
TUI_ANIMATIONS_SPEED,
tuiFadeIn,
tuiSlideInTop,
tuiToAnimationOptions,
} from '@taiga-ui/core';
import {Observable, takeUntil} from 'rxjs';

import {TuiSheet} from '../../sheet';
Expand All @@ -25,8 +30,9 @@ import {TuiSheetService} from '../../sheet.service';
export class TuiSheetsHostComponent implements OnInit {
sheets: ReadonlyArray<TuiSheet<any>> = [];

readonly options = tuiToAnimationOptions(inject(TUI_ANIMATIONS_SPEED));

constructor(
@Inject(TUI_ANIMATION_OPTIONS) readonly options: AnimationOptions,
@Inject(TuiSheetService) private readonly service: TuiSheetService,
@Inject(TUI_WINDOW_HEIGHT) readonly height$: Observable<number>,
@Self() @Inject(TuiDestroyService) private readonly destroy$: Observable<void>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {AnimationOptions} from '@angular/animations';
import {ChangeDetectionStrategy, Component, Inject, Input} from '@angular/core';
import {TUI_ANIMATION_OPTIONS, tuiScaleIn} from '@taiga-ui/core';
import {ChangeDetectionStrategy, Component, inject, Input} from '@angular/core';
import {TUI_ANIMATIONS_SPEED, tuiScaleIn, tuiToAnimationOptions} from '@taiga-ui/core';

@Component({
selector: 'button[tuiTabBarItem], a[tuiTabBarItem]',
Expand All @@ -16,7 +15,7 @@ export class TuiTabBarItemComponent {
@Input()
badge?: number | null = null;

constructor(@Inject(TUI_ANIMATION_OPTIONS) readonly animation: AnimationOptions) {}
readonly options = tuiToAnimationOptions(inject(TUI_ANIMATIONS_SPEED));

format(value: number): string {
return value > 999 ? '999+' : String(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<span
*ngIf="badge as value"
class="t-badge"
[@tuiScaleIn]="animation"
[@tuiScaleIn]="options"
>
{{ format(value) }}
</span>
Expand Down
26 changes: 8 additions & 18 deletions projects/addon-mobile/directives/sidebar/sidebar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import {
Component,
DoCheck,
HostBinding,
Inject,
inject,
} from '@angular/core';
import {
TUI_ANIMATION_OPTIONS,
TuiAnimationOptions,
TUI_ANIMATIONS_SPEED,
TuiHorizontalDirection,
tuiSlideIn,
tuiToAnimationOptions,
} from '@taiga-ui/core';
import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus';

Expand All @@ -24,23 +24,13 @@ import {TuiSidebarDirective} from './sidebar.directive';
animations: [tuiSlideIn],
})
export class TuiSidebarComponent implements DoCheck {
private readonly left = {
...this.options,
value: 'left',
} as const;

private readonly right = {
...this.options,
value: 'right',
} as const;

constructor(
@Inject(TUI_ANIMATION_OPTIONS) private readonly options: AnimationOptions,
@Inject(TuiSidebarDirective) private readonly directive: TuiSidebarDirective,
) {}
private readonly directive = inject(TuiSidebarDirective);
private readonly options = tuiToAnimationOptions(inject(TUI_ANIMATIONS_SPEED));
private readonly left = {...this.options, value: 'left'};
private readonly right = {...this.options, value: 'right'};

@HostBinding('@tuiSlideIn')
get animation(): TuiAnimationOptions {
get animation(): AnimationOptions {
return this.direction === 'left' ? this.left : this.right;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {AnimationOptions} from '@angular/animations';
import {ChangeDetectionStrategy, Component, Inject} from '@angular/core';
import {ChangeDetectionStrategy, Component, Inject, inject} from '@angular/core';
import {WINDOW} from '@ng-web-apis/common';
import {TUI_PARENT_ANIMATION, TuiContext} from '@taiga-ui/cdk';
import {
TUI_ANIMATION_OPTIONS,
TUI_ANIMATIONS_SPEED,
TUI_CLOSE_WORD,
TUI_COMMON_ICONS,
TUI_MEDIA,
Expand All @@ -12,6 +11,7 @@ import {
tuiIsMobile,
TuiMedia,
tuiSlideInTop,
tuiToAnimationOptions,
} from '@taiga-ui/core';
import {Observable} from 'rxjs';

Expand All @@ -27,11 +27,12 @@ import {TuiTableBarsService} from '../../services/table-bars.service';
animations: [tuiSlideInTop, TUI_PARENT_ANIMATION],
})
export class TuiTableBarsHostComponent {
readonly options = tuiToAnimationOptions(inject(TUI_ANIMATIONS_SPEED));

constructor(
@Inject(TuiTableBarsService) readonly service: TuiTableBarsService,
@Inject(TUI_CLOSE_WORD) readonly closeWord$: Observable<string>,
@Inject(TUI_COMMON_ICONS) readonly icons: TuiCommonIcons,
@Inject(TUI_ANIMATION_OPTIONS) readonly animation: AnimationOptions,
@Inject(TUI_MEDIA) private readonly media: TuiMedia,
@Inject(WINDOW) private readonly win: Window,
) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div
automation-id="tui-table-bar__bar"
class="t-bar"
[@tuiSlideInTop]="animation"
[@tuiSlideInTop]="options"
[class.t-bar_light]="item.mode === 'onDark'"
>
<div
Expand Down
18 changes: 7 additions & 11 deletions projects/core/components/alert/alert.component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import {AnimationOptions} from '@angular/animations';
import {
ChangeDetectionStrategy,
Component,
ElementRef,
Inject,
inject,
OnInit,
Self,
} from '@angular/core';
import {TuiDestroyService, TuiDialog, tuiIsNumber} from '@taiga-ui/cdk';
import {tuiFadeIn, tuiHeightCollapse, tuiSlideIn} from '@taiga-ui/core/animations';
import {TuiAlertOptions} from '@taiga-ui/core/interfaces';
import {TUI_ANIMATION_OPTIONS} from '@taiga-ui/core/tokens';
import {TUI_ANIMATIONS_SPEED} from '@taiga-ui/core/tokens';
import {tuiToAnimationOptions} from '@taiga-ui/core/utils';
import {POLYMORPHEUS_CONTEXT} from '@tinkoff/ng-polymorpheus';
import {fromEvent, repeatWhen, takeUntil, timer} from 'rxjs';

Expand Down Expand Up @@ -38,21 +39,16 @@ export class TuiAlertComponent<O, I> implements OnInit {
? this.item.autoClose(this.item.status)
: this.item.autoClose;

readonly options = tuiToAnimationOptions(inject(TUI_ANIMATIONS_SPEED));

readonly animation = this.position.endsWith('auto')
? {
...this.options,
value: 'right',
}
: {
...this.options,
value: 'left',
};
? {...this.options, value: 'right'}
: {...this.options, value: 'left'};

constructor(
@Inject(ElementRef) private readonly el: ElementRef<HTMLElement>,
@Self() @Inject(TuiDestroyService) private readonly destroy$: TuiDestroyService,
@Inject(TUI_ALERT_POSITION) readonly position: string,
@Inject(TUI_ANIMATION_OPTIONS) readonly options: AnimationOptions,
@Inject(POLYMORPHEUS_CONTEXT) readonly item: TuiDialog<TuiAlertOptions<I>, O>,
) {}

Expand Down
14 changes: 8 additions & 6 deletions projects/core/components/dialog/dialog.component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {AnimationOptions} from '@angular/animations';
import {
ChangeDetectionStrategy,
Component,
Expand All @@ -12,14 +13,15 @@ import {
TuiDialog,
} from '@taiga-ui/cdk';
import {tuiFadeIn, tuiSlideInTop} from '@taiga-ui/core/animations';
import {TuiAnimationOptions, TuiDialogOptions} from '@taiga-ui/core/interfaces';
import {TuiDialogOptions} from '@taiga-ui/core/interfaces';
import {
TUI_ANIMATIONS_DURATION,
TUI_ANIMATIONS_SPEED,
TUI_CLOSE_WORD,
TUI_COMMON_ICONS,
TuiCommonIcons,
} from '@taiga-ui/core/tokens';
import {TuiDialogSize} from '@taiga-ui/core/types';
import {tuiGetDuration} from '@taiga-ui/core/utils';
import {POLYMORPHEUS_CONTEXT, PolymorpheusContent} from '@tinkoff/ng-polymorpheus';
import {
filter,
Expand Down Expand Up @@ -60,22 +62,22 @@ export class TuiDialogComponent<O, I> {
value: '',
params: {
start: '40px',
duration: this.duration,
duration: tuiGetDuration(this.speed),
},
} as const;

private readonly fullscreenAnimation = {
value: '',
params: {
start: '100vh',
duration: this.duration,
duration: tuiGetDuration(this.speed),
},
} as const;

readonly close$ = new Subject<void>();

constructor(
@Inject(TUI_ANIMATIONS_DURATION) private readonly duration: number,
@Inject(TUI_ANIMATIONS_SPEED) private readonly speed: number,
@Inject(TUI_IS_MOBILE) private readonly isMobile: boolean,
@Inject(POLYMORPHEUS_CONTEXT) readonly context: TuiDialog<TuiDialogOptions<I>, O>,
@Inject(TuiDestroyService) @Self() destroy$: Observable<void>,
Expand Down Expand Up @@ -107,7 +109,7 @@ export class TuiDialogComponent<O, I> {

@HostBinding('@tuiSlideInTop')
@HostBinding('@tuiFadeIn')
get slideInTop(): TuiAnimationOptions {
get slideInTop(): AnimationOptions {
return this.fullscreen || this.isMobile
? this.fullscreenAnimation
: this.animation;
Expand Down
8 changes: 5 additions & 3 deletions projects/core/components/error/error.component.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import {AnimationOptions} from '@angular/animations';
import {
ChangeDetectionStrategy,
Component,
HostListener,
Inject,
inject,
Input,
} from '@angular/core';
import {tuiIsString, TuiValidationError} from '@taiga-ui/cdk';
import {tuiFadeIn, tuiHeightCollapse} from '@taiga-ui/core/animations';
import {MODE_PROVIDER} from '@taiga-ui/core/providers';
import {
TUI_ANIMATION_OPTIONS,
TUI_ANIMATIONS_SPEED,
TUI_DEFAULT_ERROR_MESSAGE,
TUI_MODE,
} from '@taiga-ui/core/tokens';
import {TuiBrightness} from '@taiga-ui/core/types';
import {tuiToAnimationOptions} from '@taiga-ui/core/utils';
import {Observable} from 'rxjs';

@Component({
Expand All @@ -31,12 +32,13 @@ export class TuiErrorComponent {
this.error = tuiIsString(error) ? new TuiValidationError(error) : error;
}

readonly options = tuiToAnimationOptions(inject(TUI_ANIMATIONS_SPEED));

error: TuiValidationError | null = null;

visible = true;

constructor(
@Inject(TUI_ANIMATION_OPTIONS) readonly animation: AnimationOptions,
@Inject(TUI_MODE) readonly mode$: Observable<TuiBrightness | null>,
@Inject(TUI_DEFAULT_ERROR_MESSAGE)
readonly defaultErrorMessage$: Observable<string>,
Expand Down
4 changes: 2 additions & 2 deletions projects/core/components/error/error.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
*ngIf="error && visible"
automation-id="tui-error__text"
class="t-message-text"
[@tuiFadeIn]="animation"
[@tuiHeightCollapse]="animation"
[@tuiFadeIn]="options"
[@tuiHeightCollapse]="options"
[class.t-message-text_light]="(mode$ | async) === 'onDark'"
>
<ng-container
Expand Down
Loading

0 comments on commit 9b6732a

Please sign in to comment.