mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 12:53:03 -05:00
Merge branch 'add-challenge-simple-animations' of https://github.com/svenson95/angular-challenges into add-challenge-simple-animations
This commit is contained in:
36
apps/angular/react-in-angular/.eslintrc.json
Normal file
36
apps/angular/react-in-angular/.eslintrc.json
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"extends": ["../../../.eslintrc.json"],
|
||||
"ignorePatterns": ["!**/*"],
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["*.ts"],
|
||||
"extends": [
|
||||
"plugin:@nx/angular",
|
||||
"plugin:@angular-eslint/template/process-inline-templates"
|
||||
],
|
||||
"rules": {
|
||||
"@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/react-in-angular/README.md
Normal file
13
apps/angular/react-in-angular/README.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# React in angular
|
||||
|
||||
> author: wandrille-guesdon
|
||||
|
||||
### Run Application
|
||||
|
||||
```bash
|
||||
npx nx serve angular-react-in-angular
|
||||
```
|
||||
|
||||
### Documentation and Instruction
|
||||
|
||||
Challenge documentation is [here](https://angular-challenges.vercel.app/challenges/angular/45-react-in-angular/).
|
||||
22
apps/angular/react-in-angular/jest.config.ts
Normal file
22
apps/angular/react-in-angular/jest.config.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/* eslint-disable */
|
||||
export default {
|
||||
displayName: 'angular-react-in-angular',
|
||||
preset: '../../../jest.preset.js',
|
||||
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
|
||||
coverageDirectory: '../../../coverage/apps/angular/react-in-angular',
|
||||
transform: {
|
||||
'^.+\\.(ts|mjs|js|html)$': [
|
||||
'jest-preset-angular',
|
||||
{
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json',
|
||||
stringifyContentPathRegex: '\\.(html|svg)$',
|
||||
},
|
||||
],
|
||||
},
|
||||
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
|
||||
snapshotSerializers: [
|
||||
'jest-preset-angular/build/serializers/no-ng-attributes',
|
||||
'jest-preset-angular/build/serializers/ng-snapshot',
|
||||
'jest-preset-angular/build/serializers/html-comment',
|
||||
],
|
||||
};
|
||||
80
apps/angular/react-in-angular/project.json
Normal file
80
apps/angular/react-in-angular/project.json
Normal file
@@ -0,0 +1,80 @@
|
||||
{
|
||||
"name": "angular-react-in-angular",
|
||||
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
|
||||
"projectType": "application",
|
||||
"prefix": "app",
|
||||
"sourceRoot": "apps/angular/react-in-angular/src",
|
||||
"tags": [],
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "@angular-devkit/build-angular:application",
|
||||
"outputs": ["{options.outputPath}"],
|
||||
"options": {
|
||||
"outputPath": "dist/apps/angular/react-in-angular",
|
||||
"index": "apps/angular/react-in-angular/src/index.html",
|
||||
"browser": "apps/angular/react-in-angular/src/main.ts",
|
||||
"polyfills": ["zone.js"],
|
||||
"tsConfig": "apps/angular/react-in-angular/tsconfig.app.json",
|
||||
"inlineStyleLanguage": "scss",
|
||||
"assets": [
|
||||
"apps/angular/react-in-angular/src/favicon.ico",
|
||||
"apps/angular/react-in-angular/src/assets"
|
||||
],
|
||||
"styles": ["apps/angular/react-in-angular/src/styles.scss"],
|
||||
"scripts": []
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"budgets": [
|
||||
{
|
||||
"type": "initial",
|
||||
"maximumWarning": "500kb",
|
||||
"maximumError": "1mb"
|
||||
},
|
||||
{
|
||||
"type": "anyComponentStyle",
|
||||
"maximumWarning": "2kb",
|
||||
"maximumError": "4kb"
|
||||
}
|
||||
],
|
||||
"outputHashing": "all"
|
||||
},
|
||||
"development": {
|
||||
"optimization": false,
|
||||
"extractLicenses": false,
|
||||
"sourceMap": true
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "production"
|
||||
},
|
||||
"serve": {
|
||||
"executor": "@angular-devkit/build-angular:dev-server",
|
||||
"configurations": {
|
||||
"production": {
|
||||
"buildTarget": "angular-react-in-angular:build:production"
|
||||
},
|
||||
"development": {
|
||||
"buildTarget": "angular-react-in-angular:build:development"
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "development"
|
||||
},
|
||||
"extract-i18n": {
|
||||
"executor": "@angular-devkit/build-angular:extract-i18n",
|
||||
"options": {
|
||||
"buildTarget": "angular-react-in-angular:build"
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"executor": "@nx/eslint:lint",
|
||||
"outputs": ["{options.outputFile}"]
|
||||
},
|
||||
"test": {
|
||||
"executor": "@nx/jest:jest",
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
||||
"options": {
|
||||
"jestConfig": "apps/angular/react-in-angular/jest.config.ts"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
62
apps/angular/react-in-angular/src/app/app.component.ts
Normal file
62
apps/angular/react-in-angular/src/app/app.component.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { Component, signal } from '@angular/core';
|
||||
import { PostComponent } from './react/post.component';
|
||||
|
||||
type Post = { title: string; description: string };
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [PostComponent],
|
||||
selector: 'app-root',
|
||||
template: `
|
||||
<div class="flex flex-col gap-2 p-12">
|
||||
<div class="flex gap-2">
|
||||
@for (post of posts; track post.title) {
|
||||
<div class="rounded-lg bg-gray-100 p-4">
|
||||
<app-post
|
||||
(selectPost)="selectPost(post)"
|
||||
[post]="post"
|
||||
[isSelected]="post.title === selectedPost()?.title"></app-post>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="flex flex-col gap-2 border p-4">
|
||||
<span class="text-xs font-medium">Selected Post:</span>
|
||||
<span class="text-lg text-blue-700">
|
||||
{{ selectedPost()?.title ?? '-' }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
styles: [''],
|
||||
})
|
||||
export class AppComponent {
|
||||
readonly posts = [
|
||||
{
|
||||
title: 'A Deep Dive into Angular',
|
||||
description:
|
||||
"Explore Angular's core features, its evolution, and best practices in development for creating dynamic, efficient web applications in our comprehensive guide.",
|
||||
pictureLink:
|
||||
'https://images.unsplash.com/photo-1471958680802-1345a694ba6d',
|
||||
},
|
||||
{
|
||||
title: 'The Perfect Combination',
|
||||
description:
|
||||
'Unveil the power of combining Angular & React in web development, maximizing efficiency and flexibility for building scalable, sophisticated applications.',
|
||||
pictureLink:
|
||||
'https://images.unsplash.com/photo-1518717202715-9fa9d099f58a',
|
||||
},
|
||||
{
|
||||
title: 'Taking Angular to the Next Level',
|
||||
description:
|
||||
"Discover how integrating React with Angular elevates web development, blending Angular's structure with React's UI prowess for advanced applications.",
|
||||
pictureLink:
|
||||
'https://images.unsplash.com/photo-1532103050105-860af53bc6aa',
|
||||
},
|
||||
];
|
||||
|
||||
readonly selectedPost = signal<Post | null>(null);
|
||||
|
||||
selectPost(post: Post) {
|
||||
this.selectedPost.set(post);
|
||||
}
|
||||
}
|
||||
5
apps/angular/react-in-angular/src/app/app.config.ts
Normal file
5
apps/angular/react-in-angular/src/app/app.config.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { ApplicationConfig } from '@angular/core';
|
||||
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [],
|
||||
};
|
||||
27
apps/angular/react-in-angular/src/app/react/ReactPost.tsx
Normal file
27
apps/angular/react-in-angular/src/app/react/ReactPost.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
// import React from 'react';
|
||||
|
||||
export default function ReactPost(props: {
|
||||
title?: string,
|
||||
description?: string,
|
||||
pictureLink?: string,
|
||||
selected?: boolean,
|
||||
handleClick: () => void
|
||||
}) {
|
||||
return (
|
||||
<div className={props.selected ? 'bg-blue-100' : 'bg-white'}>
|
||||
<div className="max-w-sm rounded overflow-hidden shadow-lg">
|
||||
<img className="w-full h-32 object-cover" src={props.pictureLink} alt={props.title}></img>
|
||||
<div className="px-6 py-4 flex flex-col gap-2">
|
||||
<div className="font-bold text-xl mb-2">{props.title}</div>
|
||||
<p className="text-gray-700 text-base">
|
||||
{props.description}
|
||||
</p>
|
||||
<button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
|
||||
onClick={props.handleClick}>
|
||||
Select
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { Component, EventEmitter, input, Output } from '@angular/core';
|
||||
|
||||
type Post = { title: string; description: string; pictureLink: string };
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
selector: 'app-post',
|
||||
template: `
|
||||
<div></div>
|
||||
`,
|
||||
styles: [''],
|
||||
})
|
||||
export class PostComponent {
|
||||
post = input<Post | undefined>(undefined);
|
||||
isSelected = input<boolean>(false);
|
||||
@Output() selectPost = new EventEmitter<void>();
|
||||
}
|
||||
0
apps/angular/react-in-angular/src/assets/.gitkeep
Normal file
0
apps/angular/react-in-angular/src/assets/.gitkeep
Normal file
BIN
apps/angular/react-in-angular/src/favicon.ico
Normal file
BIN
apps/angular/react-in-angular/src/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
13
apps/angular/react-in-angular/src/index.html
Normal file
13
apps/angular/react-in-angular/src/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>angular-react-in-angular</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/react-in-angular/src/main.ts
Normal file
7
apps/angular/react-in-angular/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/react-in-angular/src/styles.scss
Normal file
5
apps/angular/react-in-angular/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 */
|
||||
2
apps/angular/react-in-angular/src/test-setup.ts
Normal file
2
apps/angular/react-in-angular/src/test-setup.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
import '@testing-library/jest-dom';
|
||||
import 'jest-preset-angular/setup-jest';
|
||||
14
apps/angular/react-in-angular/tailwind.config.js
Normal file
14
apps/angular/react-in-angular/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/react-in-angular/tsconfig.app.json
Normal file
10
apps/angular/react-in-angular/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"]
|
||||
}
|
||||
7
apps/angular/react-in-angular/tsconfig.editor.json
Normal file
7
apps/angular/react-in-angular/tsconfig.editor.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"include": ["src/**/*.ts"],
|
||||
"compilerOptions": {
|
||||
"types": ["jest", "node"]
|
||||
}
|
||||
}
|
||||
33
apps/angular/react-in-angular/tsconfig.json
Normal file
33
apps/angular/react-in-angular/tsconfig.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2022",
|
||||
"useDefineForClassFields": false,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"noImplicitOverride": true,
|
||||
"noPropertyAccessFromIndexSignature": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
},
|
||||
"files": [],
|
||||
"include": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.app.json",
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.spec.json",
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.editor.json",
|
||||
},
|
||||
],
|
||||
"extends": "../../../tsconfig.base.json",
|
||||
"angularCompilerOptions": {
|
||||
"enableI18nLegacyMessageIdFormat": false,
|
||||
"strictInjectionParameters": true,
|
||||
"strictInputAccessModifiers": true,
|
||||
"strictTemplates": true,
|
||||
},
|
||||
}
|
||||
15
apps/angular/react-in-angular/tsconfig.spec.json
Normal file
15
apps/angular/react-in-angular/tsconfig.spec.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../dist/out-tsc",
|
||||
"module": "commonjs",
|
||||
"types": ["jest", "node", "@testing-library/jest-dom"]
|
||||
},
|
||||
"files": ["src/test-setup.ts"],
|
||||
"include": [
|
||||
"jest.config.ts",
|
||||
"src/**/*.test.ts",
|
||||
"src/**/*.spec.ts",
|
||||
"src/**/*.d.ts"
|
||||
]
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import { Component, input } from '@angular/core';
|
||||
standalone: true,
|
||||
imports: [NgOptimizedImage],
|
||||
template: `
|
||||
<!-- <div class="flex flex-col gap-3">-->
|
||||
<div class="relative">
|
||||
<img
|
||||
ngSrc="assets/profil.webp"
|
||||
@@ -23,7 +22,6 @@ import { Component, input } from '@angular/core';
|
||||
</div>
|
||||
<span class="text-md mt-2 font-bold uppercase">Thomas Laforge</span>
|
||||
<span class="text-sm">{{ date() }}</span>
|
||||
<!-- </div>-->
|
||||
`,
|
||||
host: {
|
||||
class: 'flex flex-col justify-center items-center',
|
||||
|
||||
Reference in New Issue
Block a user