Skip to content

Commit

Permalink
chore: perspective
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirpotekhin committed Jan 25, 2024
1 parent 3ce7697 commit ce65b1d
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,48 @@
tuiSwipeAction
></button>
</tui-swipe-actions>

<tui-swipe-actions [style.--t-item-size]="32">
<button
tuiSurface
class="surface"
>
<div tuiCell>
<tui-avatar
appearance="primary"
src="tuiIconBriefcase"
></tui-avatar>
<div tuiTitle>
<strong>{{ 5000 | tuiAmount: 'EUR' | async }}</strong>
<div tuiSubtitle>Vacations</div>
</div>
</div>
</button>

<button
iconLeft="tuiIconEye"
size="s"
tuiIconButton
tuiSwipeAction
></button>
<button
iconLeft="tuiIconEdit3"
size="s"
tuiIconButton
tuiSwipeAction
></button>
<button
appearance="secondary"
iconLeft="tuiIconShare"
size="s"
tuiIconButton
tuiSwipeAction
></button>
<button
appearance="destructive"
iconLeft="tuiIconTrash"
size="s"
tuiIconButton
tuiSwipeAction
></button>
</tui-swipe-actions>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.surface {
margin: 1.5rem 1rem;
min-width: 17rem;
padding: 0.75rem 1rem;
padding: 1rem;
box-shadow: var(--tui-shadow);

&:active {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
justify-content: space-between;
align-items: center;
color: var(--tui-text-01-night);
z-index: 1;

&:before {
backdrop-filter: blur(1rem);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,24 @@
import {ChangeDetectionStrategy, Component, ElementRef, ViewChild} from '@angular/core';
import {animationFrameScheduler, Subject} from 'rxjs';
import {map, throttleTime} from 'rxjs/operators';
import {ChangeDetectionStrategy, Component} from '@angular/core';

@Component({
selector: 'tui-swipe-actions',
templateUrl: './swipe-actions.template.html',
styleUrls: ['./swipe-actions.style.less'],
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
'[style.width.px]': 'width',
'[$.style.--t-swiped]': 'swiped$',
'($.style.--t-swiped)': '0',
'(scroll.silent)': 'onScroll($event.target)',
'[style.--t-actions-width]': 'actionsWidth',
'[style.--t-content-width]': 'contentWidth',
},
})
export class TuiSwipeActionsComponent {
private readonly swiped$$ = new Subject<HTMLElement>();
actionsWidth = 0;
contentWidth = 0;

@ViewChild('actions', {read: ElementRef})
actions?: ElementRef<HTMLElement>;

width = 0;
swiped$ = this.swiped$$.pipe(
throttleTime(0, animationFrameScheduler),
map(el => el.scrollLeft / (this.actions?.nativeElement.offsetWidth || 0) - 1),
);

onScroll(element: HTMLElement): void {
this.swiped$$.next(element);
onResizeContent(event: ResizeObserverEntry): void {
this.contentWidth = event.target.clientWidth;
}

onResize(event: ResizeObserverEntry): void {
this.width = event.contentRect.width;
onResizeActions(event: ResizeObserverEntry): void {
this.actionsWidth = event.target.clientWidth;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

:host {
.scrollbar-hidden();
--t-action-gap: 1.5rem;
--t-action-gap: 24;
--t-actions-padding: 0.5rem;
--t-item-size: 44;

display: inline-flex;
width: calc(1px * var(--t-content-width));
align-items: center;
overflow: scroll;
scroll-snap-type: x mandatory;
perspective: 1px;
perspective-origin: calc(
calc(1px * var(--t-content-width)) + calc(1px * var(--t-item-size) / 2) + var(--t-actions-padding)
);
}

.t-content {
Expand All @@ -16,10 +24,11 @@

.t-actions {
display: inline-flex;
gap: var(--t-action-gap);
padding: 0 1rem 0 0.5rem;
gap: calc(1px * var(--t-action-gap));
padding: 0 1rem 0 var(--t-actions-padding);
scroll-snap-align: start;
align-items: center;
transform-style: preserve-3d;

::ng-deep & > * {
.loop(6);
Expand All @@ -29,8 +38,11 @@
.loop (@i) when (@i > 1) {
.loop(@i - 1);
&:nth-child(@{i}) {
transform: ~'translate3d(calc(var(--t-swiped) * ((@{i} - 1) * 100%)), 0, 0)';
backface-visibility: hidden;
will-change: transform;
--t-distance: ~'calc(var(--t-item-size) + var(--t-action-gap)) * calc(@{i} - 1)';
--t-factor: calc((var(--t-actions-width) - var(--t-distance)) / var(--t-actions-width));
--t-scale: calc(1 / var(--t-factor));
--t-translate: calc(1px * (1 - 1 / var(--t-factor)));
transform: ~'translate3d(calc(calc((-100% - calc(1px * var(--t-action-gap))) * (@{i} - 1)) / var(--t-scale)), 0, var(--t-translate))';
scale: var(--t-scale);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<div
class="t-content"
(tuiResize)="onResize($event[0])"
(tuiResize)="onResizeContent($event[0])"
>
<ng-content></ng-content>
</div>

<div
#actions
class="t-actions"
(tuiResize)="onResizeActions($event[0])"
>
<ng-content select="[tuiSwipeAction]"></ng-content>
</div>

0 comments on commit ce65b1d

Please sign in to comment.