Skip to content

Commit

Permalink
Merge branch 'docs/add-ng17-example'
Browse files Browse the repository at this point in the history
  • Loading branch information
Amir Ashkan Baghdoust committed Oct 23, 2024
2 parents 299be7d + cdebdc6 commit c7828c0
Show file tree
Hide file tree
Showing 26 changed files with 661 additions and 0 deletions.
16 changes: 16 additions & 0 deletions examples/angular17-reactive-forms/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Editor configuration, see https://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.ts]
quote_type = single

[*.md]
max_line_length = off
trim_trailing_whitespace = false
2 changes: 2 additions & 0 deletions examples/angular17-reactive-forms/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.angular
.vscode
27 changes: 27 additions & 0 deletions examples/angular17-reactive-forms/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Angular17ReactiveForms

This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 17.0.8.

## Development server

Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files.

## Code scaffolding

Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.

## Build

Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory.

## Running unit tests

Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).

## Running end-to-end tests

Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities.

## Further help

To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
96 changes: 96 additions & 0 deletions examples/angular17-reactive-forms/angular.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"angular17-reactive-forms": {
"projectType": "application",
"schematics": {},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:application",
"options": {
"outputPath": "dist/angular17-reactive-forms",
"index": "src/index.html",
"browser": "src/main.ts",
"polyfills": [
"zone.js"
],
"tsConfig": "tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css",
"node_modules/@telekom/scale-components/dist/scale-components/scale-components.css"
],
"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": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"buildTarget": "angular17-reactive-forms:build:production"
},
"development": {
"buildTarget": "angular17-reactive-forms:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"buildTarget": "angular17-reactive-forms:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"polyfills": [
"zone.js",
"zone.js/testing"
],
"tsConfig": "tsconfig.spec.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
}
}
}
}
}
}
39 changes: 39 additions & 0 deletions examples/angular17-reactive-forms/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "angular17-reactive-forms",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
"private": true,
"dependencies": {
"@angular/animations": "^17.0.0",
"@angular/common": "^17.0.0",
"@angular/compiler": "^17.0.0",
"@angular/core": "^17.0.0",
"@angular/forms": "^17.0.0",
"@angular/platform-browser": "^17.0.0",
"@angular/platform-browser-dynamic": "^17.0.0",
"@angular/router": "^17.0.0",
"@telekom/scale-components": "^3.0.0-beta.147",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "^17.0.8",
"@angular/cli": "^17.0.8",
"@angular/compiler-cli": "^17.0.0",
"@types/jasmine": "~5.1.0",
"jasmine-core": "~5.1.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.2.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.1.0",
"typescript": "~5.2.2"
}
}
Empty file.
66 changes: 66 additions & 0 deletions examples/angular17-reactive-forms/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -->
<!-- * * * * * * * * * * * The content below * * * * * * * * * * * -->
<!-- * * * * * * * * * * is only a placeholder * * * * * * * * * * -->
<!-- * * * * * * * * * * and can be replaced. * * * * * * * * * * -->
<!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -->
<!-- * * * * * * * * * Delete the template below * * * * * * * * * -->
<!-- * * * * * * * to get started with your project! * * * * * * * -->
<!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -->

<style>
:host {
display: flex;
padding: 1rem;
width: 100%;
justify-content: center;
}
</style>

<main class="main">
<form [formGroup]="signupForm" (ngSubmit)="onSubmit()">
<p>
<scale-text-field label="Username" formControlName="username"></scale-text-field>
</p>

<p>
<scale-text-field label="Password" formControlName="password" type="password"></scale-text-field>
</p>
<p>
<scale-checkbox label="I agree with the privacy policy" formControlName="consent"></scale-checkbox>
</p>
<p>
<scale-dropdown-select label="select" formControlName="select">
<scale-dropdown-select-item value="foo">Foo</scale-dropdown-select-item>
<scale-dropdown-select-item value="bar">Bar</scale-dropdown-select-item>
</scale-dropdown-select>
</p>

<p>
<scale-date-picker
label="Standard"
value="2020-12-31"
placeholder="Select date"
formControlName="date"
ngDefaultControl
></scale-date-picker>
</p>
<label for="name">Name: </label>
<scale-button type="submit">console.log</scale-button>
<scale-button type="reset" variant="secondary">Reset</scale-button>
</form>
<scale-card>
<pre>{{ signupForm.value | json }}</pre>
</scale-card>

</main>

<!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -->
<!-- * * * * * * * * * * * The content above * * * * * * * * * * * * -->
<!-- * * * * * * * * * * is only a placeholder * * * * * * * * * * * -->
<!-- * * * * * * * * * * and can be replaced. * * * * * * * * * * * -->
<!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -->
<!-- * * * * * * * * * * End of Placeholder * * * * * * * * * * * * -->
<!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -->


<router-outlet></router-outlet>
29 changes: 29 additions & 0 deletions examples/angular17-reactive-forms/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';

describe('AppComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [AppComponent],
}).compileComponents();
});

it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});

it(`should have the 'angular17-reactive-forms' title`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('angular17-reactive-forms');
});

it('should render title', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('h1')?.textContent).toContain('Hello, angular17-reactive-forms');
});
});
33 changes: 33 additions & 0 deletions examples/angular17-reactive-forms/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterOutlet } from '@angular/router';
import { ReactiveFormsModule, FormGroup, FormControl, UntypedFormControl } from '@angular/forms';
import { CheckedValueAccessorDirective } from '../directives/checked-value-accessor';
import { DateValueAccessorDirective } from '../directives/date-value-accessor';
import { SelectValueAccessorDirective } from '../directives/select-value-accessor';
import { NumberValueAccessorDirective } from '../directives/number-value-accessor';
import { RadioValueAccessorDirective } from '../directives/radio-value-accessor';
import { TextValueAccessorDirective } from '../directives/text-value-accessor';
@Component({
selector: 'app-root',
standalone: true,
imports: [CommonModule, RouterOutlet, ReactiveFormsModule, CheckedValueAccessorDirective, DateValueAccessorDirective, SelectValueAccessorDirective,TextValueAccessorDirective, RadioValueAccessorDirective, NumberValueAccessorDirective ],
schemas: [CUSTOM_ELEMENTS_SCHEMA], // Telekom Scale
templateUrl: './app.component.html',
styleUrl: './app.component.css'
})
export class AppComponent {
title = 'angular17-reactive-forms';
signupForm = new FormGroup({
username: new UntypedFormControl('admin'),
password: new UntypedFormControl({ value: '', disabled: false }),
consent: new UntypedFormControl(),
select: new UntypedFormControl('foo'),
date: new UntypedFormControl(),
});


onSubmit() {
console.log('submitting ->', this.signupForm.value, this.signupForm);
}
}
8 changes: 8 additions & 0 deletions examples/angular17-reactive-forms/src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';

import { routes } from './app.routes';

export const appConfig: ApplicationConfig = {
providers: [provideRouter(routes)]
};
3 changes: 3 additions & 0 deletions examples/angular17-reactive-forms/src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Routes } from '@angular/router';

export const routes: Routes = [];
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* @license
* Scale https://github.com/telekom/scale
*
* Copyright (c) 2021 Egor Kirpichev and contributors, Deutsche Telekom AG
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

import { Directive, ElementRef } from '@angular/core';
import { ControlValueAccessor } from '@angular/forms';

@Directive({
})
export class BaseValueAccessorDirective implements ControlValueAccessor {
onChange = (_: any) => {};

onTouched = () => {};

constructor(protected el: ElementRef) {}

writeValue(value: any) {
this.el.nativeElement.value = value;
}

registerOnTouched(fn: () => void): void {
this.onTouched = fn;
}

registerOnChange(fn: (_: any) => {}): void {
this.onChange = fn;
}

setDisabledState(isDisabled: boolean): void {
this.el.nativeElement.disabled = isDisabled;
}

_handleInput(value: any): void {
this.onChange(value);
}

_handleDatePickerSelect(target: any): void {
const value = target.querySelector('duet-date-picker').value;
this.onChange(value);
}
}
Loading

0 comments on commit c7828c0

Please sign in to comment.