mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 12:53:03 -05:00
feat(challenge 59): contente projection defer
This commit is contained in:
37
apps/angular/59-content-projection-defer/.eslintrc.json
Normal file
37
apps/angular/59-content-projection-defer/.eslintrc.json
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"extends": ["../../../.eslintrc.json"],
|
||||
"ignorePatterns": ["!**/*"],
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["*.ts"],
|
||||
"extends": [
|
||||
"plugin:@nx/angular",
|
||||
"plugin:@angular-eslint/template/process-inline-templates"
|
||||
],
|
||||
"rules": {
|
||||
"@angular-eslint/component-class-suffix": "off",
|
||||
"@angular-eslint/directive-selector": [
|
||||
"error",
|
||||
{
|
||||
"type": "attribute",
|
||||
"prefix": "app",
|
||||
"style": "camelCase"
|
||||
}
|
||||
],
|
||||
"@angular-eslint/component-selector": [
|
||||
"error",
|
||||
{
|
||||
"type": "element",
|
||||
"prefix": "app",
|
||||
"style": "kebab-case"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": ["*.html"],
|
||||
"extends": ["plugin:@nx/angular-template"],
|
||||
"rules": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
13
apps/angular/59-content-projection-defer/README.md
Normal file
13
apps/angular/59-content-projection-defer/README.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# content-projection-defer
|
||||
|
||||
> author: thomas-laforge
|
||||
|
||||
### Run Application
|
||||
|
||||
```bash
|
||||
npx nx serve angular-content-projection-defer
|
||||
```
|
||||
|
||||
### Documentation and Instruction
|
||||
|
||||
Challenge documentation is [here](https://angular-challenges.vercel.app/challenges/angular/59-content-projection-defer/).
|
||||
82
apps/angular/59-content-projection-defer/project.json
Normal file
82
apps/angular/59-content-projection-defer/project.json
Normal file
@@ -0,0 +1,82 @@
|
||||
{
|
||||
"name": "angular-content-projection-defer",
|
||||
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
|
||||
"projectType": "application",
|
||||
"prefix": "app",
|
||||
"sourceRoot": "apps/angular/59-content-projection-defer/src",
|
||||
"tags": [],
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "@angular-devkit/build-angular:application",
|
||||
"outputs": ["{options.outputPath}"],
|
||||
"options": {
|
||||
"outputPath": "dist/apps/angular/59-content-projection-defer",
|
||||
"index": "apps/angular/59-content-projection-defer/src/index.html",
|
||||
"browser": "apps/angular/59-content-projection-defer/src/main.ts",
|
||||
"polyfills": ["zone.js"],
|
||||
"tsConfig": "apps/angular/59-content-projection-defer/tsconfig.app.json",
|
||||
"inlineStyleLanguage": "scss",
|
||||
"assets": [
|
||||
{
|
||||
"glob": "**/*",
|
||||
"input": "apps/angular/59-content-projection-defer/public"
|
||||
}
|
||||
],
|
||||
"styles": ["apps/angular/59-content-projection-defer/src/styles.scss"],
|
||||
"scripts": []
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"budgets": [
|
||||
{
|
||||
"type": "initial",
|
||||
"maximumWarning": "500kb",
|
||||
"maximumError": "1mb"
|
||||
},
|
||||
{
|
||||
"type": "anyComponentStyle",
|
||||
"maximumWarning": "4kb",
|
||||
"maximumError": "8kb"
|
||||
}
|
||||
],
|
||||
"outputHashing": "all"
|
||||
},
|
||||
"development": {
|
||||
"optimization": false,
|
||||
"extractLicenses": false,
|
||||
"sourceMap": true
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "production"
|
||||
},
|
||||
"serve": {
|
||||
"executor": "@angular-devkit/build-angular:dev-server",
|
||||
"configurations": {
|
||||
"production": {
|
||||
"buildTarget": "angular-content-projection-defer:build:production"
|
||||
},
|
||||
"development": {
|
||||
"buildTarget": "angular-content-projection-defer:build:development"
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "development"
|
||||
},
|
||||
"extract-i18n": {
|
||||
"executor": "@angular-devkit/build-angular:extract-i18n",
|
||||
"options": {
|
||||
"buildTarget": "angular-content-projection-defer:build"
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"executor": "@nx/eslint:lint"
|
||||
},
|
||||
"serve-static": {
|
||||
"executor": "@nx/web:file-server",
|
||||
"options": {
|
||||
"buildTarget": "angular-content-projection-defer:build",
|
||||
"staticFilePath": "dist/apps/angular/59-content-projection-defer/browser",
|
||||
"spa": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
apps/angular/59-content-projection-defer/public/favicon.ico
Normal file
BIN
apps/angular/59-content-projection-defer/public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
@@ -0,0 +1,23 @@
|
||||
import { ChangeDetectionStrategy, Component } from '@angular/core';
|
||||
import { RouterLink, RouterOutlet } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
imports: [RouterOutlet, RouterLink],
|
||||
selector: 'app-root',
|
||||
template: `
|
||||
<div class="flex gap-2">
|
||||
<button class="rounded-md border px-4 py-2" routerLink="/page-1">
|
||||
Page 1
|
||||
</button>
|
||||
<button class="rounded-md border px-4 py-2" routerLink="/page-2">
|
||||
Page 2
|
||||
</button>
|
||||
</div>
|
||||
<router-outlet />
|
||||
`,
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
host: {
|
||||
class: 'flex flex-col gap-2 ',
|
||||
},
|
||||
})
|
||||
export class AppComponent {}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { provideHttpClient } from '@angular/common/http';
|
||||
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
|
||||
import { provideRouter } from '@angular/router';
|
||||
import { appRoutes } from './app.routes';
|
||||
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [
|
||||
provideZoneChangeDetection({ eventCoalescing: true }),
|
||||
provideRouter(appRoutes),
|
||||
provideHttpClient(),
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Route } from '@angular/router';
|
||||
|
||||
export const appRoutes: Route[] = [
|
||||
{
|
||||
path: 'page-1',
|
||||
loadComponent: () => import('./page-1').then((m) => m.Page1),
|
||||
},
|
||||
{
|
||||
path: 'page-2',
|
||||
loadComponent: () => import('./page-2').then((m) => m.Page2),
|
||||
},
|
||||
{ path: '**', redirectTo: 'page-1' },
|
||||
];
|
||||
@@ -0,0 +1,54 @@
|
||||
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-expandable-card',
|
||||
template: `
|
||||
<button
|
||||
class="text-fg-subtle hover:bg-button-secondary-bg-hover active:bg-button-secondary-bg-active focus:outline-button-border-highlight flex w-fit items-center gap-1 py-2 focus:outline focus:outline-2 focus:outline-offset-1"
|
||||
(click)="isExpanded.set(!isExpanded())"
|
||||
data-cy="expandable-panel-toggle">
|
||||
@if (isExpanded()) {
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="1.5"
|
||||
stroke="currentColor"
|
||||
class="h-4 w-4">
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="m19.5 8.25-7.5 7.5-7.5-7.5" />
|
||||
</svg>
|
||||
} @else {
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="1.5"
|
||||
stroke="currentColor"
|
||||
class="h-4 w-4">
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="m8.25 4.5 7.5 7.5-7.5 7.5" />
|
||||
</svg>
|
||||
}
|
||||
<ng-content select="[title]" />
|
||||
</button>
|
||||
|
||||
<div
|
||||
class="overflow-hidden transition-[max-height] duration-500"
|
||||
[class.max-h-0]="!isExpanded()"
|
||||
[class.max-h-[1000px]]="isExpanded()">
|
||||
<ng-content />
|
||||
</div>
|
||||
`,
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
host: {
|
||||
class: 'flex flex-col gap-2 ',
|
||||
},
|
||||
})
|
||||
export class ExpandableCard {
|
||||
public isExpanded = signal(false);
|
||||
}
|
||||
10
apps/angular/59-content-projection-defer/src/app/page-1.ts
Normal file
10
apps/angular/59-content-projection-defer/src/app/page-1.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { ChangeDetectionStrategy, Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-page-1',
|
||||
template: `
|
||||
page1
|
||||
`,
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class Page1 {}
|
||||
43
apps/angular/59-content-projection-defer/src/app/page-2.ts
Normal file
43
apps/angular/59-content-projection-defer/src/app/page-2.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { httpResource } from '@angular/common/http';
|
||||
import {
|
||||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
ResourceStatus,
|
||||
} from '@angular/core';
|
||||
import { ExpandableCard } from './expandable-card';
|
||||
|
||||
interface Post {
|
||||
id: number;
|
||||
title: string;
|
||||
body: string;
|
||||
userId: number;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-page-2',
|
||||
template: `
|
||||
page2
|
||||
<app-expandable-card>
|
||||
<div title>Load Post</div>
|
||||
<div>
|
||||
@if (postRessource.isLoading()) {
|
||||
Loading...
|
||||
} @else if (postRessource.status() === ResourceStatus.Error) {
|
||||
Error...
|
||||
} @else {
|
||||
@for (post of postRessource.value(); track post.id) {
|
||||
<div>{{ post.title }}</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</app-expandable-card>
|
||||
`,
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
imports: [ExpandableCard],
|
||||
})
|
||||
export class Page2 {
|
||||
public postRessource = httpResource<Post[]>(
|
||||
'https://jsonplaceholder.typicode.com/posts',
|
||||
);
|
||||
protected readonly ResourceStatus = ResourceStatus;
|
||||
}
|
||||
13
apps/angular/59-content-projection-defer/src/index.html
Normal file
13
apps/angular/59-content-projection-defer/src/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>angular-content-projection-defer</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>
|
||||
7
apps/angular/59-content-projection-defer/src/main.ts
Normal file
7
apps/angular/59-content-projection-defer/src/main.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { bootstrapApplication } from '@angular/platform-browser';
|
||||
import { AppComponent } from './app/app.component';
|
||||
import { appConfig } from './app/app.config';
|
||||
|
||||
bootstrapApplication(AppComponent, appConfig).catch((err) =>
|
||||
console.error(err),
|
||||
);
|
||||
5
apps/angular/59-content-projection-defer/src/styles.scss
Normal file
5
apps/angular/59-content-projection-defer/src/styles.scss
Normal 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 */
|
||||
14
apps/angular/59-content-projection-defer/tailwind.config.js
Normal file
14
apps/angular/59-content-projection-defer/tailwind.config.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const { createGlobPatternsForDependencies } = require('@nx/angular/tailwind');
|
||||
const { join } = require('path');
|
||||
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: [
|
||||
join(__dirname, 'src/**/!(*.stories|*.spec).{ts,html}'),
|
||||
...createGlobPatternsForDependencies(__dirname),
|
||||
],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [],
|
||||
};
|
||||
10
apps/angular/59-content-projection-defer/tsconfig.app.json
Normal file
10
apps/angular/59-content-projection-defer/tsconfig.app.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../../dist/out-tsc",
|
||||
"types": []
|
||||
},
|
||||
"files": ["src/main.ts"],
|
||||
"include": ["src/**/*.d.ts"],
|
||||
"exclude": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts"]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"include": ["src/**/*.ts"],
|
||||
"compilerOptions": {},
|
||||
"exclude": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts"]
|
||||
}
|
||||
29
apps/angular/59-content-projection-defer/tsconfig.json
Normal file
29
apps/angular/59-content-projection-defer/tsconfig.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2022",
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"noImplicitOverride": true,
|
||||
"noPropertyAccessFromIndexSignature": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"files": [],
|
||||
"include": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.editor.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.app.json"
|
||||
}
|
||||
],
|
||||
"extends": "../../../tsconfig.base.json",
|
||||
"angularCompilerOptions": {
|
||||
"enableI18nLegacyMessageIdFormat": false,
|
||||
"strictInjectionParameters": true,
|
||||
"strictInputAccessModifiers": true,
|
||||
"strictTemplates": true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user