Skip to content

Commit 5a40db2

Browse files
committed
docs: add view source btn
1 parent 74bd3aa commit 5a40db2

File tree

1 file changed

+46
-19
lines changed

1 file changed

+46
-19
lines changed

apps/kitchen-sink/src/app/app.component.ts

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,63 @@
1-
import { Component, inject } from '@angular/core';
1+
import { Component, computed, inject } from '@angular/core';
22
import { toSignal } from '@angular/core/rxjs-interop';
33
import { NavigationEnd, Router, RouterOutlet } from '@angular/router';
4-
import { filter, map } from 'rxjs';
4+
import { filter } from 'rxjs';
55

66
@Component({
77
selector: 'app-root',
88
standalone: true,
99
template: `
1010
<router-outlet />
11-
<select class="absolute bottom-4 right-4 font-mono" [value]="currentRoute()" (change)="onChange($event)">
12-
<option value="soba">/soba</option>
13-
<option value="cannon">/cannon</option>
14-
<option value="postprocessing">/postprocessing</option>
15-
<option value="rapier">/rapier</option>
16-
<option value="misc">/misc</option>
17-
</select>
11+
12+
<div class="absolute bottom-4 right-4 flex gap-4 items-center">
13+
<select [value]="currentRoute()" (change)="onChange($event)">
14+
<option value="soba">/soba</option>
15+
<option value="cannon">/cannon</option>
16+
<option value="postprocessing">/postprocessing</option>
17+
<option value="rapier">/rapier</option>
18+
<option value="misc">/misc</option>
19+
</select>
20+
21+
<div class="bg-white rounded-full p-2 text-black border border-white border-dashed">
22+
<a class="cursor-pointer" [href]="currentSourcePath()" target="_blank" title="View source">
23+
<svg
24+
xmlns="http://www.w3.org/2000/svg"
25+
fill="none"
26+
viewBox="0 0 24 24"
27+
stroke-width="1.5"
28+
stroke="currentColor"
29+
class="h-6 w-6"
30+
>
31+
<path
32+
stroke-linecap="round"
33+
stroke-linejoin="round"
34+
d="M17.25 6.75 22.5 12l-5.25 5.25m-10.5 0L1.5 12l5.25-5.25m7.5-3-4.5 16.5"
35+
/>
36+
</svg>
37+
</a>
38+
</div>
39+
</div>
1840
`,
1941
imports: [RouterOutlet],
2042
})
2143
export class AppComponent {
2244
private router = inject(Router);
2345

24-
currentRoute = toSignal(
25-
this.router.events.pipe(
26-
filter((event) => event instanceof NavigationEnd),
27-
map(() => {
28-
const [segment] = this.router.url.split('/').filter(Boolean);
29-
return segment;
30-
}),
31-
),
32-
{ initialValue: 'soba' },
33-
);
46+
private navigationEnd = toSignal(this.router.events.pipe(filter((event) => event instanceof NavigationEnd)));
47+
48+
currentRoute = computed(() => {
49+
const navigationEnd = this.navigationEnd();
50+
if (!navigationEnd) return 'soba';
51+
const [segment] = navigationEnd.urlAfterRedirects.split('/').filter(Boolean);
52+
return segment;
53+
});
54+
55+
currentSourcePath = computed(() => {
56+
const navigationEnd = this.navigationEnd();
57+
if (!navigationEnd) return '';
58+
const paths = navigationEnd.urlAfterRedirects.split('/').filter(Boolean);
59+
return `https://github.com/angular-threejs/angular-three/tree/main/apps/kitchen-sink/src/app/${paths.join('/')}`;
60+
});
3461

3562
onChange(event: Event) {
3663
const target = event.target as HTMLSelectElement;

0 commit comments

Comments
 (0)