-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(addon-mobile):
SwipeActions
add new component (#6644)
Co-authored-by: taiga-family-bot <[email protected]>
- Loading branch information
1 parent
4609529
commit 6cb738e
Showing
37 changed files
with
839 additions
and
20 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './swipe-actions.component'; | ||
export * from './swipe-actions-auto-close.directive'; |
5 changes: 5 additions & 0 deletions
5
projects/addon-mobile/components/swipe-action/ng-package.json
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"lib": { | ||
"entryFile": "index.ts" | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
projects/addon-mobile/components/swipe-action/swipe-actions-auto-close.directive.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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {Directive, ElementRef, inject, Input} from '@angular/core'; | ||
import {tuiGetActualTarget} from '@taiga-ui/cdk'; | ||
|
||
@Directive({ | ||
standalone: true, | ||
selector: 'tui-swipe-actions[autoClose]', | ||
host: { | ||
'(document:pointerdown.silent)': 'onPointer($event)', | ||
}, | ||
}) | ||
export class TuiSwipeActionsAutoCloseDirective { | ||
private readonly el: HTMLElement = inject(ElementRef).nativeElement; | ||
|
||
@Input() | ||
autoClose = true; | ||
|
||
onPointer(event: PointerEvent): void { | ||
if (this.autoClose && !this.el.contains(tuiGetActualTarget(event))) { | ||
this.el.scrollTo({ | ||
left: 0, | ||
behavior: 'smooth', | ||
}); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
projects/addon-mobile/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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {ChangeDetectionStrategy, Component} from '@angular/core'; | ||
import {ResizeObserverModule} from '@ng-web-apis/resize-observer'; | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: 'tui-swipe-actions', | ||
imports: [ResizeObserverModule], | ||
templateUrl: './swipe-actions.template.html', | ||
styleUrls: ['./swipe-actions.style.less'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
host: { | ||
'[style.--t-actions-width]': 'actionsWidth', | ||
}, | ||
}) | ||
export class TuiSwipeActionsComponent { | ||
actionsWidth = 0; | ||
|
||
onResize({target}: ResizeObserverEntry): void { | ||
this.actionsWidth = target.clientWidth; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
projects/addon-mobile/components/swipe-action/swipe-actions.style.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
@import '@taiga-ui/core/styles/taiga-ui-local'; | ||
|
||
:host { | ||
.scrollbar-hidden(); | ||
|
||
--tui-action-gap: 24; | ||
--tui-actions-padding: 0.5rem; | ||
--tui-item-size: 44; | ||
|
||
display: flex; | ||
width: stretch; | ||
align-items: center; | ||
overflow-x: scroll; | ||
overflow-y: hidden; | ||
scroll-snap-type: x mandatory; | ||
perspective: 1px; | ||
perspective-origin: calc(100% + calc(1px * var(--tui-item-size) / 2) + var(--tui-actions-padding)); | ||
} | ||
|
||
.t-content { | ||
scroll-snap-align: start; | ||
flex-shrink: 0; | ||
width: 100%; | ||
} | ||
|
||
.t-actions { | ||
display: flex; | ||
gap: calc(1px * var(--tui-action-gap)); | ||
padding: 0 1rem 0 var(--tui-actions-padding); | ||
scroll-snap-align: start; | ||
align-items: center; | ||
transform-style: preserve-3d; | ||
|
||
::ng-deep & > * { | ||
.loop(6); | ||
} | ||
} | ||
|
||
.loop (@i) when (@i > 1) { | ||
.loop(@i - 1); | ||
&:nth-child(@{i}) { | ||
--t-distance: ~'calc(var(--tui-item-size) + var(--tui-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(--tui-action-gap))) * (@{i} - 1)) / var(--t-scale)), 0, var(--t-translate))'; | ||
scale: var(--t-scale); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
projects/addon-mobile/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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div class="t-content"> | ||
<ng-content></ng-content> | ||
</div> | ||
|
||
<div | ||
class="t-actions" | ||
(waResizeObserver)="onResize($event[0])" | ||
> | ||
<ng-content select="[tuiSwipeAction]"></ng-content> | ||
</div> |
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
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
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
107 changes: 107 additions & 0 deletions
107
projects/demo/src/modules/components/swipe-action/examples/1/index.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 |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<tui-swipe-actions> | ||
<div | ||
tuiCardLarge | ||
tuiCell | ||
tuiSurface="elevated" | ||
> | ||
<tui-avatar | ||
appearance="primary" | ||
src="tuiIconDollarSignLarge" | ||
></tui-avatar> | ||
<div tuiTitle> | ||
<strong>{{ 10000 | tuiAmount: 'USD' | async }}</strong> | ||
<div tuiSubtitle>Dollar account</div> | ||
</div> | ||
</div> | ||
|
||
<button | ||
iconLeft="tuiIconEye" | ||
size="m" | ||
tuiIconButton | ||
tuiSwipeAction | ||
></button> | ||
<button | ||
iconLeft="tuiIconEdit3" | ||
size="m" | ||
tuiIconButton | ||
tuiSwipeAction | ||
></button> | ||
<button | ||
appearance="secondary" | ||
iconLeft="tuiIconShare" | ||
size="m" | ||
tuiIconButton | ||
tuiSwipeAction | ||
></button> | ||
</tui-swipe-actions> | ||
|
||
<tui-swipe-actions> | ||
<div | ||
tuiCardLarge | ||
tuiCell | ||
tuiSurface="elevated" | ||
> | ||
<tui-avatar | ||
appearance="primary" | ||
src="tuiIconGift" | ||
></tui-avatar> | ||
<div tuiTitle> | ||
<strong>{{ 23000 | tuiAmount: 'EUR' | async }}</strong> | ||
<div tuiSubtitle>Goal</div> | ||
</div> | ||
</div> | ||
|
||
<button | ||
iconLeft="tuiIconEye" | ||
size="m" | ||
tuiIconButton | ||
tuiSwipeAction | ||
></button> | ||
</tui-swipe-actions> | ||
|
||
<tui-swipe-actions | ||
[style.--tui-action-gap]="16" | ||
[style.--tui-item-size]="32" | ||
> | ||
<div | ||
tuiCardLarge | ||
tuiCell | ||
tuiSurface="elevated" | ||
> | ||
<tui-avatar | ||
appearance="primary" | ||
src="tuiIconBriefcase" | ||
></tui-avatar> | ||
<div tuiTitle> | ||
<strong>{{ 5000 | tuiAmount: 'EUR' | async }}</strong> | ||
<div tuiSubtitle>Vacations</div> | ||
</div> | ||
</div> | ||
|
||
<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> |
19 changes: 19 additions & 0 deletions
19
projects/demo/src/modules/components/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
:host { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1rem; | ||
width: 20rem; | ||
margin: 2rem 0; | ||
} | ||
|
||
[tuiSurface] { | ||
margin: 1.5rem 1rem; | ||
} | ||
|
||
tui-swipe-actions { | ||
margin: -1.5rem -1rem; | ||
} | ||
|
||
button[tuiSwipeAction] { | ||
border-radius: 100%; | ||
} |
12 changes: 12 additions & 0 deletions
12
projects/demo/src/modules/components/swipe-action/examples/1/index.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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {Component} from '@angular/core'; | ||
import {changeDetection} from '@demo/emulate/change-detection'; | ||
import {encapsulation} from '@demo/emulate/encapsulation'; | ||
|
||
@Component({ | ||
selector: 'tui-swipe-action-example-1', | ||
templateUrl: './index.html', | ||
styleUrls: ['./index.less'], | ||
encapsulation, | ||
changeDetection, | ||
}) | ||
export class TuiSwipeActionExample1 {} |
Oops, something went wrong.