feat(anchorscrolling): new challenge

This commit is contained in:
thomas
2023-05-02 12:36:50 +02:00
parent 6db4dfbb9b
commit 75fa6eac9b
17 changed files with 303 additions and 0 deletions

View File

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

View File

@@ -0,0 +1,19 @@
import { Component } from '@angular/core';
import { AnchorButtonComponent } from './anchor-button.component';
@Component({
standalone: true,
imports: [AnchorButtonComponent],
selector: 'app-root',
template: `
<div id="top" class="h-screen bg-gray-500">
Empty
<anchor-button href="#bottom">Scroll Bottom</anchor-button>
</div>
<div id="bottom" class="h-screen bg-blue-300">
I want to scroll each
<anchor-button href="#top">Scroll Top</anchor-button>
</div>
`,
})
export class AppComponent {}

View File

@@ -0,0 +1,3 @@
import { Route } from '@angular/router';
export const appRoutes: Route[] = [];

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,11 @@
import { bootstrapApplication } from '@angular/platform-browser';
import {
provideRouter,
withEnabledBlockingInitialNavigation,
} from '@angular/router';
import { AppComponent } from './app/app.component';
import { appRoutes } from './app/app.routes';
bootstrapApplication(AppComponent, {
providers: [provideRouter(appRoutes, withEnabledBlockingInitialNavigation())],
}).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';