mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 12:53:03 -05:00
feat: challenge 43 input signal
This commit is contained in:
@@ -24,7 +24,7 @@ If you would like to propose a challenge, this project is open source, so feel f
|
|||||||
|
|
||||||
## Challenges
|
## Challenges
|
||||||
|
|
||||||
Check [all 42 challenges](https://angular-challenges.vercel.app/)
|
Check [all 43 challenges](https://angular-challenges.vercel.app/)
|
||||||
|
|
||||||
## Contributors ✨
|
## Contributors ✨
|
||||||
|
|
||||||
|
|||||||
36
apps/angular/signal-input/.eslintrc.json
Normal file
36
apps/angular/signal-input/.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/signal-input/README.md
Normal file
13
apps/angular/signal-input/README.md
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# Signal Input
|
||||||
|
|
||||||
|
> author: thomas-laforge
|
||||||
|
|
||||||
|
### Run Application
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npx nx serve angular-signal-input
|
||||||
|
```
|
||||||
|
|
||||||
|
### Documentation and Instruction
|
||||||
|
|
||||||
|
Challenge documentation is [here](https://angular-challenges.vercel.app/challenges/angular/43-signal-input/).
|
||||||
73
apps/angular/signal-input/project.json
Normal file
73
apps/angular/signal-input/project.json
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
{
|
||||||
|
"name": "angular-signal-input",
|
||||||
|
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
|
||||||
|
"projectType": "application",
|
||||||
|
"prefix": "app",
|
||||||
|
"sourceRoot": "apps/angular/signal-input/src",
|
||||||
|
"tags": [],
|
||||||
|
"targets": {
|
||||||
|
"build": {
|
||||||
|
"executor": "@angular-devkit/build-angular:application",
|
||||||
|
"outputs": ["{options.outputPath}"],
|
||||||
|
"options": {
|
||||||
|
"outputPath": "dist/apps/angular/signal-input",
|
||||||
|
"index": "apps/angular/signal-input/src/index.html",
|
||||||
|
"browser": "apps/angular/signal-input/src/main.ts",
|
||||||
|
"polyfills": ["zone.js"],
|
||||||
|
"tsConfig": "apps/angular/signal-input/tsconfig.app.json",
|
||||||
|
"inlineStyleLanguage": "scss",
|
||||||
|
"assets": [
|
||||||
|
"apps/angular/signal-input/src/favicon.ico",
|
||||||
|
"apps/angular/signal-input/src/assets"
|
||||||
|
],
|
||||||
|
"styles": ["apps/angular/signal-input/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-signal-input:build:production"
|
||||||
|
},
|
||||||
|
"development": {
|
||||||
|
"buildTarget": "angular-signal-input:build:development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultConfiguration": "development"
|
||||||
|
},
|
||||||
|
"extract-i18n": {
|
||||||
|
"executor": "@angular-devkit/build-angular:extract-i18n",
|
||||||
|
"options": {
|
||||||
|
"buildTarget": "angular-signal-input:build"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"lint": {
|
||||||
|
"executor": "@nx/eslint:lint",
|
||||||
|
"outputs": ["{options.outputFile}"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
45
apps/angular/signal-input/src/app/app.component.ts
Normal file
45
apps/angular/signal-input/src/app/app.component.ts
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import { JsonPipe } from '@angular/common';
|
||||||
|
import { Component } from '@angular/core';
|
||||||
|
import { UserComponent } from './user.component';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
standalone: true,
|
||||||
|
imports: [UserComponent, JsonPipe],
|
||||||
|
selector: 'app-root',
|
||||||
|
template: `
|
||||||
|
<div class="flex flex-col gap-3">
|
||||||
|
<div class="flex gap-2 ">
|
||||||
|
Name:
|
||||||
|
<input #name class="border" />
|
||||||
|
@if (showUser && !name.value) {
|
||||||
|
<div class="text-sm text-red-500">name required</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<div class="flex gap-2 ">
|
||||||
|
LastName:
|
||||||
|
<input #lastName class="border" />
|
||||||
|
</div>
|
||||||
|
<div class="flex gap-2 ">
|
||||||
|
Age:
|
||||||
|
<input type="number" #age class="border" />
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
(click)="showUser = true"
|
||||||
|
class="w-fit rounded-md border border-blue-500 bg-blue-200 px-4 py-2">
|
||||||
|
Submit
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
@if (showUser && !!name.value) {
|
||||||
|
<app-user
|
||||||
|
[name]="name.value"
|
||||||
|
[lastName]="lastName.value"
|
||||||
|
[age]="age.value" />
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
host: {
|
||||||
|
class: 'p-10 block flex flex-col gap-10',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
export class AppComponent {
|
||||||
|
showUser = false;
|
||||||
|
}
|
||||||
5
apps/angular/signal-input/src/app/app.config.ts
Normal file
5
apps/angular/signal-input/src/app/app.config.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { ApplicationConfig } from '@angular/core';
|
||||||
|
|
||||||
|
export const appConfig: ApplicationConfig = {
|
||||||
|
providers: [],
|
||||||
|
};
|
||||||
41
apps/angular/signal-input/src/app/user.component.ts
Normal file
41
apps/angular/signal-input/src/app/user.component.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { TitleCasePipe } from '@angular/common';
|
||||||
|
import {
|
||||||
|
ChangeDetectionStrategy,
|
||||||
|
Component,
|
||||||
|
Input,
|
||||||
|
OnChanges,
|
||||||
|
} from '@angular/core';
|
||||||
|
|
||||||
|
type Category = 'Youth' | 'Junior' | 'Open' | 'Senior';
|
||||||
|
const ageToCategory = (age: number): Category => {
|
||||||
|
if (age < 10) return 'Youth';
|
||||||
|
else if (age < 18) return 'Junior';
|
||||||
|
else if (age < 35) return 'Open';
|
||||||
|
return 'Senior';
|
||||||
|
};
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-user',
|
||||||
|
standalone: true,
|
||||||
|
imports: [TitleCasePipe],
|
||||||
|
template: `
|
||||||
|
{{ fullName | titlecase }} plays tennis in the {{ category }} category!!
|
||||||
|
`,
|
||||||
|
host: {
|
||||||
|
class: 'text-xl text-green-800',
|
||||||
|
},
|
||||||
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
|
})
|
||||||
|
export class UserComponent implements OnChanges {
|
||||||
|
@Input({ required: true }) name!: string;
|
||||||
|
@Input() lastName?: string;
|
||||||
|
@Input() age?: string;
|
||||||
|
|
||||||
|
fullName = '';
|
||||||
|
category: Category = 'Junior';
|
||||||
|
|
||||||
|
ngOnChanges(): void {
|
||||||
|
this.fullName = `${this.name} ${this.lastName ?? ''}`;
|
||||||
|
this.category = ageToCategory(Number(this.age) ?? 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
0
apps/angular/signal-input/src/assets/.gitkeep
Normal file
0
apps/angular/signal-input/src/assets/.gitkeep
Normal file
BIN
apps/angular/signal-input/src/favicon.ico
Normal file
BIN
apps/angular/signal-input/src/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
13
apps/angular/signal-input/src/index.html
Normal file
13
apps/angular/signal-input/src/index.html
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>angular-signal-input</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/signal-input/src/main.ts
Normal file
7
apps/angular/signal-input/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/signal-input/src/styles.scss
Normal file
5
apps/angular/signal-input/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/signal-input/tailwind.config.js
Normal file
14
apps/angular/signal-input/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/signal-input/tsconfig.app.json
Normal file
10
apps/angular/signal-input/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/signal-input/tsconfig.editor.json
Normal file
7
apps/angular/signal-input/tsconfig.editor.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"include": ["src/**/*.ts"],
|
||||||
|
"compilerOptions": {
|
||||||
|
"types": []
|
||||||
|
}
|
||||||
|
}
|
||||||
30
apps/angular/signal-input/tsconfig.json
Normal file
30
apps/angular/signal-input/tsconfig.json
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"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.editor.json"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"extends": "../../../tsconfig.base.json",
|
||||||
|
"angularCompilerOptions": {
|
||||||
|
"enableI18nLegacyMessageIdFormat": false,
|
||||||
|
"strictInjectionParameters": true,
|
||||||
|
"strictInputAccessModifiers": true,
|
||||||
|
"strictTemplates": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"total": 42,
|
"total": 43,
|
||||||
"🟢": 15,
|
"🟢": 16,
|
||||||
"🟠": 120,
|
"🟠": 120,
|
||||||
"🔴": 207
|
"🔴": 207
|
||||||
}
|
}
|
||||||
|
|||||||
20
docs/src/content/docs/challenges/angular/43-signal-input.md
Normal file
20
docs/src/content/docs/challenges/angular/43-signal-input.md
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
title: 🟢 Signal Input
|
||||||
|
description: Challenge 43 is about ...
|
||||||
|
author: thomas-laforge
|
||||||
|
challengeNumber: 43
|
||||||
|
command: angular-signal-input
|
||||||
|
sidebar:
|
||||||
|
order: 16
|
||||||
|
badge: New
|
||||||
|
---
|
||||||
|
|
||||||
|
:::note
|
||||||
|
WIP: The following documentation need to be written.
|
||||||
|
:::
|
||||||
|
|
||||||
|
## Information
|
||||||
|
|
||||||
|
## Statement
|
||||||
|
|
||||||
|
## Constraints
|
||||||
@@ -6,7 +6,6 @@ challengeNumber: 42
|
|||||||
command: nx-static-dynamic-import
|
command: nx-static-dynamic-import
|
||||||
sidebar:
|
sidebar:
|
||||||
order: 15
|
order: 15
|
||||||
badge: New
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Information
|
## Information
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ hero:
|
|||||||
icon: right-arrow
|
icon: right-arrow
|
||||||
variant: primary
|
variant: primary
|
||||||
- text: Go to the latest Challenge
|
- text: Go to the latest Challenge
|
||||||
link: /challenges/nx/42-static-dynamic-import/
|
link: /challenges/angular/43-signal-input/
|
||||||
icon: rocket
|
icon: rocket
|
||||||
- text: Give a star
|
- text: Give a star
|
||||||
link: https://github.com/tomalaforge/angular-challenges
|
link: https://github.com/tomalaforge/angular-challenges
|
||||||
@@ -25,8 +25,8 @@ import { Card, CardGrid } from '@astrojs/starlight/components';
|
|||||||
import MyIcon from '../../components/MyIcon.astro';
|
import MyIcon from '../../components/MyIcon.astro';
|
||||||
|
|
||||||
<CardGrid>
|
<CardGrid>
|
||||||
<Card title="42 Challenges">
|
<Card title="43 Challenges">
|
||||||
This repository gathers 42 Challenges related to <b>Angular</b>, <b>Nx</b>, <b>RxJS</b>, <b>Ngrx</b> and <b>Typescript</b>.
|
This repository gathers 43 Challenges related to <b>Angular</b>, <b>Nx</b>, <b>RxJS</b>, <b>Ngrx</b> and <b>Typescript</b>.
|
||||||
These challenges resolve around real-life issues or specific features to elevate your skills.
|
These challenges resolve around real-life issues or specific features to elevate your skills.
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
|||||||
@@ -68,6 +68,9 @@
|
|||||||
"libs/shared/directives/src/index.ts"
|
"libs/shared/directives/src/index.ts"
|
||||||
],
|
],
|
||||||
"@angular-challenges/shared/utils": ["libs/shared/utils/src/index.ts"],
|
"@angular-challenges/shared/utils": ["libs/shared/utils/src/index.ts"],
|
||||||
|
"@angular-challenges/static-dynamic-import/users": [
|
||||||
|
"libs/static-dynamic-import/users/src/index.ts"
|
||||||
|
],
|
||||||
"@angular-challenges/testing-table/backend": [
|
"@angular-challenges/testing-table/backend": [
|
||||||
"libs/testing-table/backend/src/index.ts"
|
"libs/testing-table/backend/src/index.ts"
|
||||||
],
|
],
|
||||||
@@ -76,9 +79,6 @@
|
|||||||
],
|
],
|
||||||
"@tomalaforge/ngrx-callstate-store": [
|
"@tomalaforge/ngrx-callstate-store": [
|
||||||
"libs/shared/ngrx-callstate-store/src/index.ts"
|
"libs/shared/ngrx-callstate-store/src/index.ts"
|
||||||
],
|
|
||||||
"@angular-challenges/static-dynamic-import/users": [
|
|
||||||
"libs/static-dynamic-import/users/src/index.ts"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user