-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add view transition api package
- Loading branch information
vsevolod arutyunov
committed
Sep 15, 2023
1 parent
f922e92
commit b11203e
Showing
30 changed files
with
899 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ jobs: | |
speech, | ||
storage, | ||
workers, | ||
view-transition, | ||
] | ||
name: ${{ matrix.project }} | ||
steps: | ||
|
@@ -128,6 +129,11 @@ jobs: | |
directory: ./coverage/workers/ | ||
flags: summary,workers | ||
name: workers | ||
- uses: codecov/[email protected] | ||
with: | ||
directory: ./coverage/view-transition/ | ||
flags: summary,view-transition | ||
name: view-transition | ||
|
||
concurrency: | ||
group: test-${{ github.workflow }}-${{ github.ref }} | ||
|
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,3 @@ | ||
{ | ||
"typescript.tsdk": "node_modules/typescript/lib" | ||
} |
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
30 changes: 30 additions & 0 deletions
30
apps/demo/src/app/pages/view-transition/view-transition-page.component.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,30 @@ | ||
<h2>How to use</h2> | ||
<p> | ||
Usage is pretty simple: just import service in your component and call | ||
startViewTransition on it. | ||
</p> | ||
<pre><code [highlight]="codeSample" [languages]="['ts']"></code></pre> | ||
<h2>Basic example</h2> | ||
|
||
<div *ngIf="!showDetails" class="photos"> | ||
<div | ||
*ngFor="let item of data; let index = index" | ||
class="photo" | ||
(click)="open(index)" | ||
> | ||
<span class="author"> | ||
Photo by | ||
<a target="_blank" [href]="item.url">{{item.author}}</a> | ||
</span> | ||
<img | ||
[src]="item.src" | ||
[style.viewTransitionName]="activeIndex === index ? 'expandable-image' : null" | ||
/> | ||
</div> | ||
</div> | ||
|
||
<div *ngIf="showDetails" class="expanded-photo"> | ||
<img [src]="detailInfo?.src" (click)="close()" /> | ||
</div> | ||
|
||
<a href="https://www.pexels.com">Photos provided by Pexels</a> |
56 changes: 56 additions & 0 deletions
56
apps/demo/src/app/pages/view-transition/view-transition-page.component.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,56 @@ | ||
:host { | ||
display: flex; | ||
align-items: center; | ||
flex-direction: column; | ||
} | ||
|
||
.photos { | ||
display: flex; | ||
justify-content: center; | ||
align-items: flex-start; | ||
flex-wrap: wrap; | ||
gap: 1rem; | ||
margin: 1rem 0; | ||
|
||
.photo { | ||
width: 12rem; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
cursor: pointer; | ||
|
||
.author { | ||
margin-bottom: 0.5rem; | ||
|
||
a:hover { | ||
text-decoration: underline; | ||
} | ||
} | ||
|
||
img { | ||
display: block; | ||
width: 100%; | ||
border-radius: 0.5rem; | ||
transition: transform 0.2s; | ||
|
||
&:hover { | ||
transform: scale(1.05); | ||
} | ||
} | ||
} | ||
} | ||
|
||
.expanded-photo { | ||
margin: 0 auto 1rem; | ||
width: 20rem; | ||
display: flex; | ||
cursor: pointer; | ||
|
||
img { | ||
display: block; | ||
view-transition-name: expandable-image; | ||
border-radius: 1rem; | ||
box-shadow: 0 12px 36px rgba(0, 0, 0, 0.2); | ||
width: 100%; | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
apps/demo/src/app/pages/view-transition/view-transition-page.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,91 @@ | ||
import {ChangeDetectionStrategy, ChangeDetectorRef, Component} from '@angular/core'; | ||
import {finalize} from 'rxjs'; | ||
import {ViewTransitionService} from '@ng-web-apis/view-transition'; | ||
|
||
interface Photo { | ||
src: string; | ||
author: string; | ||
url: string; | ||
} | ||
|
||
const PHOTOS = [ | ||
{ | ||
src: 'https://images.pexels.com/photos/16316785/pexels-photo-16316785/free-photo-of-fluffy-cat-on-blooming-tree-background.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1', | ||
author: 'Peng Louis', | ||
url: 'https://www.pexels.com/photo/fluffy-cat-on-blooming-tree-background-16316785/', | ||
}, | ||
{ | ||
src: 'https://images.pexels.com/photos/6001385/pexels-photo-6001385.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1', | ||
author: 'Sam Lion', | ||
url: 'https://www.pexels.com/photo/cute-curious-cat-watching-video-on-laptop-sitting-on-couch-6001385/', | ||
}, | ||
{ | ||
src: 'https://images.pexels.com/photos/7210265/pexels-photo-7210265.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1', | ||
author: 'Blue Bird', | ||
url: 'https://www.pexels.com/photo/ginger-cat-sleeping-on-ground-in-autumn-7210265/', | ||
}, | ||
]; | ||
|
||
const USAGE_SAMPLE = ` | ||
// 1) Import service throught DI | ||
// In Constructor | ||
constructor(private viewTransitionService: ViewTransitionService) {} | ||
// or with inject (Angular 14+) | ||
private service = inject(ViewTransitionService); | ||
// 2) Call startViewTransition method and pass callback that would change the DOM | ||
private showMyComponent(): void { | ||
this.viewTransitionService.startViewTransition(() => { | ||
this.showMyComponent = true; | ||
// You might want to call detectChanges to update the DOM inside startViewTransition callback | ||
this.cdr.detectChanges(); | ||
}).subscribe(); | ||
} | ||
`; | ||
|
||
@Component({ | ||
selector: `view-transition-page`, | ||
templateUrl: `./view-transition-page.component.html`, | ||
styleUrls: [`./view-transition-page.component.less`], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class ViewTransitionPageComponent { | ||
codeSample = USAGE_SAMPLE; | ||
activeIndex = -1; | ||
showDetails = false; | ||
detailInfo: Photo | undefined = undefined; | ||
data = PHOTOS; | ||
|
||
constructor( | ||
private readonly viewTransitionService: ViewTransitionService, | ||
private readonly cdr: ChangeDetectorRef, | ||
) {} | ||
|
||
open(index: number): void { | ||
this.activeIndex = index; | ||
this.detailInfo = this.data[index]; | ||
this.cdr.detectChanges(); | ||
|
||
this.viewTransitionService | ||
.startViewTransition(() => { | ||
this.showDetails = true; | ||
this.cdr.detectChanges(); | ||
}) | ||
.subscribe(); | ||
} | ||
|
||
close(): void { | ||
this.viewTransitionService | ||
.startViewTransition(() => { | ||
this.showDetails = false; | ||
this.cdr.detectChanges(); | ||
}) | ||
.pipe( | ||
finalize(() => { | ||
this.activeIndex = -1; | ||
this.detailInfo = undefined; | ||
}), | ||
) | ||
.subscribe(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
apps/demo/src/app/pages/view-transition/view-transition-page.module.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,15 @@ | ||
import {NgModule} from '@angular/core'; | ||
import {ViewTransitionPageComponent} from './view-transition-page.component'; | ||
import {RouterModule} from '@angular/router'; | ||
import {CommonModule} from '@angular/common'; | ||
import {HighlightModule} from 'ngx-highlightjs'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
HighlightModule, | ||
RouterModule.forChild([{path: '', component: ViewTransitionPageComponent}]), | ||
], | ||
declarations: [ViewTransitionPageComponent], | ||
}) | ||
export class ViewTransitionPageModule {} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Empty file.
Oops, something went wrong.