Skip to content

Commit

Permalink
chore: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
waterplea committed Sep 23, 2024
1 parent 26c41a2 commit e489a80
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
import {
afterNextRender,
ChangeDetectorRef,
DestroyRef,
inject,
Injectable,
INJECTOR,
NgZone,
} from '@angular/core';
import {afterNextRender, DestroyRef, inject, Injectable, INJECTOR} from '@angular/core';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {tuiScrollFrom, tuiZonefree} from '@taiga-ui/cdk/observables';
import {tuiScrollFrom} from '@taiga-ui/cdk/observables';
import {tuiGetElementOffset, tuiInjectElement} from '@taiga-ui/cdk/utils/dom';
import {SCROLL_REF_SELECTOR} from '@taiga-ui/core/components/scrollbar';
import {TUI_SCROLL_REF} from '@taiga-ui/core/tokens';
import {map, Observable, Subscription, tap} from 'rxjs';
import {map, Observable, Subscription} from 'rxjs';

@Injectable()
export class TuiElasticStickyService extends Observable<number> {
private readonly injector = inject(INJECTOR);
private readonly el = tuiInjectElement();
private readonly scrollRef = inject(TUI_SCROLL_REF).nativeElement;
private readonly zone = inject(NgZone);
private readonly cd = inject(ChangeDetectorRef);
private readonly destroyRef = inject(DestroyRef);

constructor() {
Expand All @@ -34,7 +24,6 @@ export class TuiElasticStickyService extends Observable<number> {
const {offsetHeight} = this.el;
const teardown = tuiScrollFrom(host)
.pipe(
tuiZonefree(this.zone),
map(() =>
Math.max(
1 -
Expand All @@ -46,7 +35,6 @@ export class TuiElasticStickyService extends Observable<number> {
0,
),
),
tap(() => this.cd.detectChanges()),
takeUntilDestroyed(this.destroyRef),
)
.subscribe(subscriber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ <h3>Long mobile dialog with filters</h3>
<ng-template #long>
<div class="background"></div>
<header
#header
class="header"
[style.transform]="transform"
[style.width]="width"
(tuiElasticSticky)="onElastic($event)"
(tuiElasticSticky)="onElastic($event, header)"
>
<section class="logo">
<label class="date">8 March, 23:51</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
.header {
position: sticky;
top: 0;
inline-size: calc(100% + 4rem);
margin-top: -2rem;
margin-left: -2rem;
inline-size: calc(100% + 3.5rem);
margin-top: -1.75rem;
margin-left: -1.75rem;
text-align: center;
word-wrap: break-word;
background: var(--tui-chart-categorical-20);
Expand All @@ -32,8 +32,8 @@
position: sticky;
top: -1rem;
block-size: 2rem;
inline-size: calc(100% + 4rem);
margin: -2rem 0 -2rem -2rem;
inline-size: calc(100% + 3.5rem);
margin: -1.75rem 0 -1.75rem -1.75rem;
background: var(--tui-chart-categorical-20);
border-radius: 1rem 1rem 0 0;
}
Expand Down
15 changes: 4 additions & 11 deletions projects/demo/src/modules/components/dialog/examples/4/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,11 @@ export default class Example {

protected filters = false;

protected scale = 1;
protected onElastic(value: number, {style}: HTMLElement): void {
const scale = tuiClamp(value, 0.7, 1);

protected get transform(): string {
return `scale(${this.scale})`;
}

protected get width(): string {
return `calc((100% + 4rem) * ${1 / this.scale})`;
}

protected onElastic(value: number): void {
this.scale = tuiClamp(value, 0.5, 1);
style.setProperty('transform', `scale(${scale})`);
style.setProperty('width', `calc((100% + 3.5rem) / ${scale})`);
}

protected onFilterClick(): void {
Expand Down

0 comments on commit e489a80

Please sign in to comment.