@forge-form/angular 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Marcin Spasinski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,210 @@
1
+ # @forge-form/angular
2
+
3
+ Schema-driven, signal-based reactive forms for Angular. Describe your form as a
4
+ plain TypeScript object and let the engine build the `FormGroup`, render the
5
+ fields, wire up validation, hints, error messages, and conditional visibility.
6
+
7
+ - **Schema-first** — define controls, groups, validators, and layout declaratively.
8
+ - **Signal-based** — built on Angular signals with `OnPush` change detection.
9
+ - **Reactive Forms under the hood** — emits a strongly-typed value on submit.
10
+ - **Extensible** — custom error and hint components, theming via SCSS.
11
+ - **Standalone** — no NgModules required.
12
+
13
+ ## Requirements
14
+
15
+ | Peer dependency | Version |
16
+ | ----------------- | --------- |
17
+ | `@angular/core` | `^21.2.0` |
18
+ | `@angular/common` | `^21.2.0` |
19
+ | `@angular/forms` | `^21.2.0` |
20
+ | `rxjs` | `^7.8.0` |
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ npm install @forge-form/angular
26
+ ```
27
+
28
+ ## Quick start
29
+
30
+ Import `FormRendererComponent`, pass it a schema, and handle the typed
31
+ `formSubmit` output.
32
+
33
+ ```ts
34
+ import { Component } from '@angular/core';
35
+ import { FormRendererComponent, FormSchema, required, minLength } from '@forge-form/angular';
36
+
37
+ interface UserModel {
38
+ firstName: string;
39
+ age: number;
40
+ }
41
+
42
+ @Component({
43
+ selector: 'app-user-form',
44
+ imports: [FormRendererComponent],
45
+ template: `
46
+ <forge-form-angular [schema]="schema" (formSubmit)="onSubmit($event)" />
47
+ `,
48
+ })
49
+ export class UserFormComponent {
50
+ schema: FormSchema = {
51
+ updateOn: 'blur',
52
+ options: { orientation: 'column', theme: 'default' },
53
+ controls: [
54
+ {
55
+ type: 'text',
56
+ controlName: 'firstName',
57
+ label: 'First name',
58
+ placeholder: 'Enter your first name',
59
+ validators: [required(), minLength({ value: 3 })],
60
+ },
61
+ {
62
+ type: 'number',
63
+ controlName: 'age',
64
+ label: 'Age',
65
+ validators: [required()],
66
+ },
67
+ ],
68
+ };
69
+
70
+ onSubmit(value: UserModel) {
71
+ console.log('Submitted', value);
72
+ }
73
+ }
74
+ ```
75
+
76
+ ## Styling
77
+
78
+ The package ships SCSS files. Import them once in your global stylesheet to get
79
+ the default layout and theme:
80
+
81
+ ```scss
82
+ // styles.scss
83
+ @use '@forge-form/angular/styles' as forge;
84
+ @use '@forge-form/angular/styles/default' as forge-theme;
85
+ ```
86
+
87
+ To enable the default theme, set `theme: 'default'` in the schema's `options`.
88
+ You can also skip the theme and style the `forge-*` CSS classes yourself.
89
+
90
+ ## Schema reference
91
+
92
+ ### `FormSchema`
93
+
94
+ | Property | Type | Description |
95
+ | ---------- | --------------------------------------- | -------------------------------------- |
96
+ | `controls` | `(GroupFieldSchema \| ControlSchema)[]` | Top-level controls and groups. |
97
+ | `id` | `string` | Optional form id. |
98
+ | `updateOn` | `'change' \| 'blur' \| 'submit'` | When control values/validation update. |
99
+ | `options` | `FormOptions` | Layout orientation and theme. |
100
+
101
+ ### Control types
102
+
103
+ All controls share `controlName`, `label`, `options`, `initialValue`,
104
+ `validators`, `visibility`, `updateOn`, and `hint`.
105
+
106
+ | `type` | Extra properties |
107
+ | ---------- | ------------------------------------------ |
108
+ | `text` | `placeholder` |
109
+ | `number` | `placeholder`, `min`, `max` |
110
+ | `checkbox` | — |
111
+ | `select` | `items: { label, value }[]`, `placeholder` |
112
+
113
+ ### Groups
114
+
115
+ Nest controls with a `group`:
116
+
117
+ ```ts
118
+ {
119
+ type: 'group',
120
+ options: { orientation: 'row' },
121
+ controls: [
122
+ { type: 'text', controlName: 'firstName', label: 'First' },
123
+ { type: 'text', controlName: 'lastName', label: 'Last' },
124
+ ],
125
+ }
126
+ ```
127
+
128
+ ## Validators
129
+
130
+ Helper functions return a `ValidatorSchema`:
131
+
132
+ ```ts
133
+ import { required, minLength, maxLength, min, max, customValidator } from '@forge-form/angular';
134
+
135
+ validators: [
136
+ required(),
137
+ minLength({ value: 3, errorMessage: 'Name is too short' }),
138
+ customValidator({
139
+ key: 'mustAccept',
140
+ fn: (control) => (control.value === true ? null : { mustAccept: true }),
141
+ errorMessage: 'You must accept the terms',
142
+ }),
143
+ ];
144
+ ```
145
+
146
+ Each validator accepts an optional `errorMessage` that can be a string, a
147
+ function of the validation error, or a custom component definition.
148
+
149
+ ## Conditional visibility
150
+
151
+ ```ts
152
+ visibility: {
153
+ fn: (ctx) => ctx.form.get('firstName')?.valid === true,
154
+ behavior: 'hide', // or 'disable'
155
+ clearOnHide: true,
156
+ }
157
+ ```
158
+
159
+ ## Custom hint and error components
160
+
161
+ Custom hint components extend `FormFieldContextComponent`, which exposes
162
+ `control`, `controlValue`, `controlErrors`, and `controlSchema` inputs:
163
+
164
+ ```ts
165
+ import { Component, computed, input } from '@angular/core';
166
+ import { FormFieldContextComponent } from '@forge-form/angular';
167
+
168
+ @Component({
169
+ selector: 'app-char-counter',
170
+ template: `
171
+ {{ currentLength() }} / {{ maxLength() }}
172
+ `,
173
+ })
174
+ export class CharCounterComponent extends FormFieldContextComponent {
175
+ maxLength = input<number>();
176
+ currentLength = computed(() => (this.controlValue() as string | undefined)?.length ?? 0);
177
+ }
178
+ ```
179
+
180
+ Reference it from a control's `hint`:
181
+
182
+ ```ts
183
+ hint: {
184
+ component: CharCounterComponent,
185
+ inputs: { maxLength: 100 },
186
+ }
187
+ ```
188
+
189
+ ## Public API
190
+
191
+ `FormRendererComponent`, `FormFieldContextComponent`, schema models
192
+ (`FormSchema`, `ControlSchema` variants, `FormOptions`, `VisibilitySchema`, …),
193
+ validator helpers, DI tokens (`RENDERERS`, `FORM_OPTIONS`, `ERROR_MESSAGES`,
194
+ `DEFAULT_ERROR_FALLBACK`), and the error/hint models are exported from the
195
+ package entry point.
196
+
197
+ ## Building from source
198
+
199
+ ```bash
200
+ ng build forge-form-angular # outputs to dist/forge-form-angular
201
+ ng test forge-form-angular # run unit tests
202
+ ```
203
+
204
+ ## License
205
+
206
+ [MIT](./LICENSE)
207
+
208
+ ## Additional Resources
209
+
210
+ For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.