Skip to content

Commit f70e58b

Browse files
Add example app (#62)
Co-authored-by: ihor-panasiuk95 <ihor.panasiuk95@gmail.com>
1 parent 34eff9b commit f70e58b

28 files changed

Lines changed: 1017 additions & 98 deletions

apps/example/.browserslistrc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
2+
# For additional information regarding the format and rule options, please see:
3+
# https://github.com/browserslist/browserslist#queries
4+
5+
# For the full list of supported browsers by the Angular framework, please see:
6+
# https://angular.io/guide/browser-support
7+
8+
# You can see what browsers were selected by your queries by running:
9+
# npx browserslist
10+
11+
last 1 Chrome version
12+
last 1 Firefox version
13+
last 2 Edge major versions
14+
last 2 Safari major versions
15+
last 2 iOS major versions
16+
Firefox ESR
17+
not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line.

apps/example/.eslintrc.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"extends": ["../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts"],
7+
"extends": [
8+
"plugin:@nrwl/nx/angular",
9+
"plugin:@angular-eslint/template/process-inline-templates"
10+
],
11+
"rules": {
12+
}
13+
},
14+
{
15+
"files": ["*.html"],
16+
"extends": ["plugin:@nrwl/nx/angular-template"],
17+
"rules": {}
18+
}
19+
]
20+
}

apps/example/karma.conf.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Karma configuration file, see link for more information
2+
// https://karma-runner.github.io/1.0/config/configuration-file.html
3+
4+
const { join } = require('path');
5+
const getBaseKarmaConfig = require('../../karma.conf');
6+
7+
module.exports = function (config) {
8+
const baseConfig = getBaseKarmaConfig();
9+
config.set({
10+
...baseConfig,
11+
coverageIstanbulReporter: {
12+
...baseConfig.coverageIstanbulReporter,
13+
dir: join(__dirname, '../../coverage/apps/example'),
14+
},
15+
});
16+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Component } from '@angular/core';
2+
import { DynamicFormGroup } from '@skynet-ng/dynamic-form';
3+
import { TextfieldControl } from './models';
4+
5+
@Component({
6+
selector: 'example-app-root',
7+
template: `
8+
<div class="flex justify-center items-center absolute w-full h-full bg-gray-200">
9+
<div class="bg-white flex flex-col w-96 border-gray-300 border border-solid p-5 rounded-md gap-4">
10+
<dynamic-form-outlet class="flex flex-col gap-4" [dynamicFormGroup]="dynamicFormGroup"></dynamic-form-outlet>
11+
<button class="self-end h-10 inline-flex justify-center rounded-md border border-transparent bg-indigo-600 py-2 px-4 text-sm font-medium text-white shadow-sm hover:bg-indigo-700">
12+
Submit
13+
</button>
14+
</div>
15+
</div>
16+
`
17+
})
18+
export class AppComponent {
19+
dynamicFormGroup = new DynamicFormGroup({
20+
name: new TextfieldControl({
21+
initialInputs: {
22+
label: 'Name',
23+
placeholder: 'Enter your name'
24+
}
25+
}),
26+
surname: new TextfieldControl({
27+
initialInputs: {
28+
label: 'Surname',
29+
placeholder: 'Enter your surname'
30+
}
31+
}),
32+
age: new TextfieldControl({
33+
initialInputs: {
34+
label: 'Age',
35+
placeholder: 'Enter your age',
36+
type: 'number'
37+
}
38+
})
39+
});
40+
}

apps/example/src/app/app.module.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { NgModule } from '@angular/core';
2+
import { BrowserModule } from '@angular/platform-browser';
3+
4+
import { DynamicFormModule } from '@skynet-ng/dynamic-form';
5+
import { AppComponent } from './app.component';
6+
import { TextfieldComponent } from './components';
7+
8+
@NgModule({
9+
declarations: [AppComponent, TextfieldComponent],
10+
imports: [
11+
BrowserModule,
12+
DynamicFormModule
13+
],
14+
providers: [],
15+
bootstrap: [AppComponent],
16+
})
17+
export class AppModule {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { TextfieldComponent } from './textfield/textfield.component';
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* eslint-disable @typescript-eslint/no-empty-function */
2+
import { Component, forwardRef, Input } from '@angular/core';
3+
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
4+
5+
@Component({
6+
selector: 'textfield-control',
7+
template: `
8+
<div class="flex flex-col gap-1">
9+
<label class="block text-sm font-medium text-gray-700">{{ label }}</label>
10+
<input
11+
class="block w-full border border-gray-300 rounded-md sm:text-sm shadow-sm outline-indigo-500 p-3"
12+
[disabled]="isDisabled"
13+
[type]="type"
14+
[(ngModel)]="value"
15+
[placeholder]="placeholder"
16+
[disabled]="isDisabled"
17+
/>
18+
</div>
19+
`,
20+
providers: [
21+
{
22+
provide: NG_VALUE_ACCESSOR,
23+
useExisting: forwardRef(() => TextfieldComponent),
24+
multi: true,
25+
},
26+
],
27+
})
28+
export class TextfieldComponent implements ControlValueAccessor {
29+
private _value: string;
30+
31+
get value(): any {
32+
return this._value;
33+
}
34+
set value(value: any) {
35+
if (value !== this._value) {
36+
this._value = value;
37+
this.onChange(value);
38+
}
39+
}
40+
41+
isDisabled: boolean;
42+
43+
@Input()
44+
label: string;
45+
46+
@Input()
47+
placeholder = '';
48+
49+
@Input()
50+
type: 'text' | 'number' = 'text';
51+
52+
onChange = (_) => {};
53+
54+
onTouch = () => {};
55+
56+
writeValue(value: any): void {
57+
this._value = value;
58+
}
59+
60+
registerOnChange(fn: any): void {
61+
this.onChange = fn;
62+
}
63+
64+
registerOnTouched(fn: any): void {
65+
this.onTouch = fn;
66+
}
67+
68+
setDisabledState(isDisabled: boolean) {
69+
this.isDisabled = isDisabled;
70+
}
71+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { TextfieldControl } from './textfield.control';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { AbstractDynamicControl, ControlConfiguration } from '@skynet-ng/dynamic-form';
2+
import { TextfieldComponent } from '../components';
3+
4+
export class TextfieldControl extends AbstractDynamicControl<TextfieldComponent> {
5+
constructor(config: ControlConfiguration<any, any, string>) {
6+
super(config, TextfieldComponent);
7+
}
8+
}

apps/example/src/assets/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)