Skip to content

Commit ce970b8

Browse files
Samuel Esansesan07
authored andcommitted
docs: update readme
1 parent a758b71 commit ce970b8

File tree

1 file changed

+63
-44
lines changed

1 file changed

+63
-44
lines changed

README.md

Lines changed: 63 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
A configurable editor for ngx-formly forms.
44

5+
This project uses standalone components.
6+
57
Demo: https://formly-editor.sesan.dev
68

79
![Demo Screenshot](docs/img/screenshot.png 'Demo Screenshot')
@@ -12,8 +14,6 @@ Demo: https://formly-editor.sesan.dev
1214
- Install dependencies: `npm i`
1315
- Start app: `npm start`
1416

15-
The editor is also published as an [NPM library](https://www.npmjs.com/package/@sesan07/ngx-formly-editor). It can be installed with `npm i @sesan07/ngx-formly-editor`
16-
1717
## Setup
1818

1919
### Create a config
@@ -57,12 +57,16 @@ const cardWrapperConfig: FieldWrapperOption = {
5757
};
5858

5959
// Configure validator options that can be set
60-
export const validatorOptions: ValidatorOption[] = [{
61-
name: 'Ip',
62-
key: 'ip',
63-
}];
60+
export const validatorOptions: ValidatorOption[] = [
61+
{
62+
name: 'Ip',
63+
key: 'ip',
64+
}
65+
...
66+
];
6467

6568
export const editorConfig: EditorConfig = {
69+
id: 'editor',
6670
fieldOptions: [ // Configs for fields or field categories
6771
{ // A field category
6872
displayName: 'Input',
@@ -74,6 +78,11 @@ export const editorConfig: EditorConfig = {
7478
],
7579
wrapperOptions: [cardWrapperConfig], // configs for wrappers
7680
validatorOptions: validatorOptions,
81+
defaultForm: {
82+
name: 'Form Zero',
83+
fields: [...], // Formly field configs
84+
model: {...}
85+
},
7786
};
7887
```
7988

@@ -85,60 +94,70 @@ These helper functions can be used to create properties
8594
- `createSelectProperty({...})`
8695
- `createTextProperty({...})`
8796

88-
### Import the EditorModule
97+
### Provide the Editor config
8998

9099
```typescript
91-
import { NgModule } from '@angular/core';
100+
import { ApplicationConfig, importProvidersFrom } from '@angular/core';
92101
import { FormlyModule } from '@ngx-formly/core';
93-
import { FormlyMaterialModule } from '@ngx-formly/material';
94-
import { EditorModule } from '@sesan07/ngx-formly-editor';
95-
import { editorConfig } from './editor.config';
96102

97-
@NgModule({
98-
...
99-
imports: [
103+
import { provideEditor, provideEditorConfig, withConfig } from '@sesan07/ngx-formly-editor';
104+
105+
import { editorConfig1, editorConfig2 } from './editor.config';
106+
107+
// Single route setup
108+
export const appConfig: ApplicationConfig = {
109+
providers: [
110+
...
111+
// Provide the editor and config
112+
provideEditor(withConfig(editorConfig1)),
113+
// Ngx-formly configuration
114+
importProvidersFrom([
115+
FormlyModule.forRoot({ ... }),
116+
]),
100117
...
101-
FormlyMaterialModule, // Can be replaced with other formly UI modules
102-
FormlyModule.forRoot({ // Configure formly
103-
...
104-
validators: [{ name: 'ip', validation: ipValidator }],
105-
validationMessages: [{ name: 'required', message: 'This field is required' }],
106-
}),
107-
EditorModule.forRoot(editorConfig), // Configure the editor
108118
],
109-
})
110-
export class MyModule {}
119+
};
120+
121+
// Multi route setup
122+
export const appConfig: ApplicationConfig = {
123+
providers: [
124+
...
125+
// Provide the editor
126+
provideEditor(),
127+
provideRouter([
128+
{
129+
path: 'path1',
130+
// Provide editorConfig1 for path1
131+
providers: [provideEditorConfig(editorConfig1)],
132+
},
133+
{
134+
path: 'path2',
135+
// Provide editorConfig2 for path2
136+
providers: [provideEditorConfig(editorConfig2)],
137+
},
138+
])
139+
// Ngx-formly configuration
140+
importProvidersFrom([
141+
FormlyModule.forRoot({ ... }),
142+
]),
143+
...
144+
],
145+
};
111146
```
112147

113148
### Use the Editor Component
114149

115150
```typescript
116151
import { Component } from '@angular/core';
117-
import { IDefaultForm, IStylesConfig, tailwindConfig } from '@sesan07/ngx-formly-editor';
152+
import { EditorComponent } from '@sesan07/ngx-formly-editor';
118153

119154
@Component({
120155
selector: 'app-example',
121-
template: `
122-
<!-- All inputs are optional -->
123-
<editor-main
124-
[autosaveStorageKey]="'editor-local-storage-key'"
125-
[autosaveDelay]="2000"
126-
[defaultForm]="defaultForm"
127-
[stylesConfig]="tailwindConfig"
128-
>
129-
</editor-main>
130-
`,
156+
template: ` <editor-main></editor-main> `,
157+
standalone: true,
158+
imports: [EditorComponent],
131159
})
132-
export class ExampleComponent {
133-
// Configuration for the editor's styling system (styling tab on UI) (defaults to tailwindConfig)
134-
// A `bootstrapConfig` is also available, or you can create yours.
135-
tailwindConfig: IStylesConfig = tailwindConfig;
136-
defaultForm: IDefaultForm = {
137-
name: 'Form Zero',
138-
fields: [...], // Formly field configs
139-
model: {...}
140-
}
141-
}
160+
export class ExampleComponent {}
142161
```
143162

144163
### Import the editor's styles into your app

0 commit comments

Comments
 (0)