-
Notifications
You must be signed in to change notification settings - Fork 463
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ce7697
commit ce65b1d
Showing
6 changed files
with
76 additions
and
30 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
2 changes: 1 addition & 1 deletion
2
projects/demo/src/modules/experimental/swipe-action/examples/1/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
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
30 changes: 9 additions & 21 deletions
30
projects/experimental/components/swipe-action/swipe-actions.component.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 |
---|---|---|
@@ -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; | ||
} | ||
} |
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
4 changes: 2 additions & 2 deletions
4
projects/experimental/components/swipe-action/swipe-actions.template.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 |
---|---|---|
@@ -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> |