feat(doc): move anchor scrolling

This commit is contained in:
thomas
2023-10-18 09:56:31 +02:00
parent 49d7a7f968
commit a4edf05eac
22 changed files with 25 additions and 25 deletions

View File

@@ -0,0 +1,10 @@
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
@Component({
standalone: true,
imports: [RouterOutlet],
selector: 'app-root',
template: ` <router-outlet></router-outlet> `,
})
export class AppComponent {}

View File

@@ -0,0 +1,6 @@
import { ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';
import { appRoutes } from './app.routes';
export const appConfig: ApplicationConfig = {
providers: [provideRouter(appRoutes)],
};

View File

@@ -0,0 +1,9 @@
import { Route } from '@angular/router';
import { FooComponent } from './foo.component';
import { HomeComponent } from './home.component';
export const appRoutes: Route[] = [
{ path: 'home', component: HomeComponent },
{ path: 'foo', component: FooComponent },
{ path: '**', redirectTo: 'home' },
];

View File

@@ -0,0 +1,15 @@
import { Component } from '@angular/core';
import { NavButtonComponent } from './nav-button.component';
@Component({
standalone: true,
imports: [NavButtonComponent],
selector: 'app-foo',
template: `
Welcome to foo page
<nav-button href="home" class="fixed top-3 left-1/2">Home Page</nav-button>
<div class="h-screen bg-blue-200">section 1</div>
<div class="h-screen bg-red-200">section 2</div>
`,
})
export class FooComponent {}

View File

@@ -0,0 +1,20 @@
import { Component } from '@angular/core';
import { NavButtonComponent } from './nav-button.component';
@Component({
standalone: true,
imports: [NavButtonComponent],
selector: 'app-home',
template: `
<nav-button href="/foo" class="fixed top-3 left-1/2">Foo Page</nav-button>
<div id="top" class="h-screen bg-gray-500">
Empty
<nav-button href="#bottom">Scroll Bottom</nav-button>
</div>
<div id="bottom" class="h-screen bg-blue-300">
I want to scroll each
<nav-button href="#top">Scroll Top</nav-button>
</div>
`,
})
export class HomeComponent {}

View File

@@ -0,0 +1,17 @@
/* eslint-disable @angular-eslint/component-selector */
import { Component, Input } from '@angular/core';
@Component({
selector: 'nav-button',
standalone: true,
template: `
<a [href]="href">
<ng-content></ng-content>
</a>
`,
host: {
class: 'block w-fit border border-red-500 rounded-md p-4 m-2',
},
})
export class NavButtonComponent {
@Input() href = '';
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>AnchorScrolling</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
</head>
<body>
<app-root></app-root>
</body>
</html>

View File

@@ -0,0 +1,8 @@
import { appConfig } from './app/app.config';
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
bootstrapApplication(AppComponent, appConfig).catch((err) =>
console.error(err)
);

View File

@@ -0,0 +1,5 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
/* You can add global styles to this file, and also import other style files */

View File

@@ -0,0 +1 @@
import 'jest-preset-angular/setup-jest';