Skip to content

Commit 7d4e196

Browse files
authored
Merge pull request #823 from rvsia/updateDocs
Update docs, make them more interesting and searchable
2 parents 027d9c7 + de627d8 commit 7d4e196

File tree

10 files changed

+137
-23
lines changed

10 files changed

+137
-23
lines changed

packages/react-renderer-demo/src/components/landing-page/landing-page-cards.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,11 @@ const LandingPageCards = () => {
319319
<Typography variant="body2" gutterBottom className={classes.mappersText}>
320320
This list represents a set of provided mappers. Each mapper brings all basic form components from its design system. You can
321321
immediately use form inputs such as text fields, selects, radios, checkboxes or wizards. However, this selection does not limit you as
322-
integrating custom components is simple as it can be - all it takes is just one hook.
322+
integrating custom components is simple as it can be - all it takes is just{' '}
323+
<RouterLink href="/mappers/carbon-component-mapper">
324+
<a href="/mappers/carbon-component-mapper">one hook</a>
325+
</RouterLink>
326+
.
323327
</Typography>
324328
</Grid>
325329
</Grid>

packages/react-renderer-demo/src/pages/hooks/use-form-api.md

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,58 @@ const Component = (props) => {
2020

2121
This hook returns object containing following information:
2222

23-
```jsx
24-
{
25-
blur: (name) => void, // calls onBlur event on field with given name
26-
change: (name, value) => void, // calls onChange event on field with given name
27-
focus: (name) => void, // calls onFocus event on field with given name
28-
getFieldState: (name) => object, // returns a state of given field, state contains input and meta information of field
29-
getRegisteredFields: () => string[], // returns an array of field names that are rendered in DOM
30-
getState: () => object, // returns an object with whole form state. More info https://final-form.org/docs/final-form/types/FormState
31-
pristine: bool, // true if the all field values is === to the initial values, false if the values are !==.
32-
renderForm: (defaultSchema) => void, // function that is used by form renderer to render form fields defined by defaultSchema; can be used for schema nesting
33-
valid: bool //true if all fields have no validation or submission errors. false otherwise.
34-
}
35-
```
23+
## renderForm
24+
25+
*(fields: schema) => React.Element*
26+
27+
If you want to render fields from a component (`tabs`, `subform`, etc.) you can use `renderForm(fields)` function.
28+
29+
## getState
30+
31+
*() => FormState*
32+
33+
Using `getState` components you get an access to [the form state](https://final-form.org/docs/final-form/types/FormState). Be aware of subscription - if your component is not subscribed to the form state, it won't be updated when the state is changed. See [FormSpy](/components/form-spy).
34+
35+
## change
36+
37+
*(name: string, value: any) => void*
38+
39+
You can change value of any field using this function.
40+
41+
## focus
42+
43+
*(name: string) => void*
44+
45+
Calls onFocus event on field with given name.
46+
47+
## blur
48+
49+
*(name: string) => void*
50+
51+
Calls onBlur event on field with given name.
52+
53+
## getFieldState
54+
55+
*(name: string) => FormFieldState*
56+
57+
Returns a state of given field. State contains input and meta information of the field.
58+
59+
## getRegisteredFields
60+
61+
*() => string[]*
62+
63+
Returns an array of field names that are currently rendered in DOM. Useful to know when you collect variables in wizard forms.
64+
65+
## pristine
66+
67+
*boolean*
68+
69+
True if the all field values is === to the initial values, false if the values are !==. Same as in the FormState.
70+
71+
## valid
72+
73+
*boolean*
74+
75+
True if all fields have no validation or submission errors. false otherwise. Same as in the FormState.
3676

3777
</DocPage>

packages/react-renderer-demo/src/pages/installation.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ yarn add @data-driven-forms/react-form-renderer
1616

1717
## Mappers
1818

19-
Data Driven Forms team provides and mantains basic set of components for following design systems:
19+
Data Driven Forms team provides and mantains basic set of components for following design systems. You can use them to build forms without ingerating your own components.
2020

2121
- [MaterialUI](/mappers/mui-component-mapper)
2222
- [Semantic UI](/mappers/suir-component-mapper)
2323
- [BlueprintJS](/mappers/blueprint-component-mapper)
2424
- [PatternFly 4](/mappers/pf4-component-mapper)
2525
- [PatternFly 3](/mappers/pf3-component-mapper)
26+
- [Ant Design](/mappers/ant-component-mapper)
27+
- [Carbon Design](/mappers/carbon-component-mapper)
2628

2729
## Versioning
2830

packages/react-renderer-demo/src/pages/introduction.md

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,30 @@ import CodeExample from '@docs/code-example';
55

66
# Data Driven Forms Introduction
77

8-
Data Driven Forms converts JSON form definitions into fully functional React forms.
9-
It uses [React Final Form](https://github.com/final-form/react-final-form) for the form state management.
10-
It is highly recommended to check their documentations first to fully understand how
11-
the [Data Driven Forms](https://github.com/data-driven-forms/react-forms) libraries work.
8+
Data Driven Forms converts JSON form definitions (schemas) into fully functional React forms with the provided set of features.
129

13-
All you need is to [install](/installation) the form renderer and choose the component mapper you want ([or create your own](/mappers/custom-mapper)).
10+
## Form state management
1411

15-
Import `FormRenderer` from the react-form-renderer. This component takes four required props: FormTemplate, schema, componentMapper and onSubmit. You can read about them [here](/components/renderer#requiredprops).
12+
Data Driven Forms uses [React Final Form](https://github.com/final-form/react-final-form) for the form state management. It is recommended to check their documentations first to fully understand how the [Data Driven Forms](https://github.com/data-driven-forms/react-forms) libraries work. However, it's not required to use DDF library.
1613

17-
You can check the simple example below.
14+
## Schema
15+
16+
[A schema](/schema/introduction) is a JSON object controlling the whole form. Using schema you define form fields and its attributes.
17+
18+
## How to start
19+
20+
All you need is to [install](/installation) the form renderer and then to choose components you want to use. You can use one of provided mappers to start building forms right away ([or integrate your own components](/mappers/custom-mapper)). The integration is simple - all it takes is just a single [useFieldApi](/hooks/use-field-api) hook.
21+
22+
Then you can import `FormRenderer` from the `@data-driven-forms/react-form-renderer`. This component takes four required props: **FormTemplate**, **schema**, **componentMapper** and **onSubmit**. You can read about them [here](/components/renderer#requiredprops).
23+
24+
Following example shows basic usage of Data Driven Forms library with our [Material UI mapper](/mappers/mui-component-mapper).
1825

1926
<CodeExample source="components/get-started/get-started" mode="preview" />
2027

2128
## Articles
2229

30+
Following articles can give you more insights about Data Driven Forms and why/how to use it in you projects.
31+
2332
### Introduction of data driven approach
2433

2534
[This article](https://medium.com/javascript-in-plain-english/data-driven-approach-to-forms-with-react-c69fd4ea7923) presents basics of the data driven approach and why to choose it.
@@ -28,4 +37,18 @@ You can check the simple example below.
2837

2938
[This article](https://medium.com/javascript-in-plain-english/data-driven-form-building-in-react-30768b49e625) presents basics of the data driven form building. It is a great point to start if you are new with this library.
3039

40+
## Comparison with other form libraries
41+
42+
### Form state management
43+
44+
You can find many of already existing and well-established libraries such as Formik, React Hook Form, or React Final Form. These libraries are focused on providing form state management solutions. Data Driven Forms is using one of them - React Final Form - to enhance the developer experience and to provide consistent way for building complex forms. Form state management is completely abstracted in Data Driven Forms, so developers can focus on the only thing that really matters - building the most accessible web forms.
45+
46+
### Data driven libraries
47+
48+
Also, there are multiple libraries generating forms from schemas (i.e. Uniforms, AntD Form component). Mostly these libraries are using one of well-known formats such as JSON Schemas or GraphQL schemas. Data Driven Forms implements its own format to provide the most simple representation of forms - it's not being used to define data, it's directly designed to define forms so it's simple, logical and it allows to use many of form-specific features.
49+
50+
Data Driven Forms provides complex conditional logic to hide your fields, fully dynamic wizard forms, and much more. Also, its API allows to store complex forms in databases, so you can reuse forms in multiple developer environments.
51+
52+
If users need to use generate forms from GraphQL, all that is needed is to convert the GraphQL schema to DDF one.
53+
3154
</DocPage>

packages/react-renderer-demo/src/pages/mappers/custom-mapper.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,30 @@ Data Driven Forms will render any component you pass to it, so you don't have to
6060
const Title = ({component, name, label, ...props }) => <h1 id={name} {...props}>{label}</h1>
6161
```
6262

63+
### Form methods
64+
65+
Using [useFormApi](/hooks/use-form-api) you can get access to mutliple form methods without connecting a form field. Some most used methods are following:
66+
67+
**renderForm**
68+
69+
*(fields) => React.Element*
70+
71+
If you want to render fields from a component (`tabs`, `subform`, etc.) you can use `renderForm(fields)` function.
72+
73+
**getState**
74+
75+
*() => FormState*
76+
77+
Using `getState` components you get an access to the form state. Be aware of subscription - if your component is not subscribed to the form state, it won't be updated when the state is changed. See [FormSpy](/components/form-spy).
78+
79+
**change**
80+
81+
*(name, value) => void*
82+
83+
You can change value of any field using this function.
84+
85+
---
86+
6387
## Register component in component mapper
6488

6589
To be able to use your component in the schema, you need to register the component in your component mapper.

packages/react-renderer-demo/src/pages/migration-guide.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ Thank you for your understanding.
3535
- disableSubmit
3636
- buttonClassName
3737
- renderFormButtons
38-
- buttonsLabels
38+
- submitLabel
39+
- cancelLabel
40+
- resetLabel
3941
- canReset
4042
- => All these props are now managed by mapper's form templates!
4143

packages/react-renderer-demo/src/pages/schema/clear-on-unmount.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import CodeExample from '@docs/code-example';
55

66
# Clear on unmount
77

8+
*boolean*
9+
810
When using dynamic forms where more fields share the same name, the value is preserved when a user switches the field. You can disable this behavior by setting
911
`clearOnUnmount` option in the renderer component or in the schema of the field. The option in the schema has always higher priority. (When
1012
`clearOnUnmount` is set in the renderer and the field has it this attribute set to `false`, the field value will not be cleared.)

packages/react-renderer-demo/src/pages/schema/cleared-value.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import DocPage from '@docs/doc-page';
55

66
# Cleared value
77

8+
*any*
9+
810
The value to send upon a submit if the field is empty. This wildcard value can be used to distinguish between an untouched field and a cleared one (it will be only used when field has initialValue). For example if you have a form that edits an entity and you would like to clear an attribute. Some APIs require the value to be set to null to register the change.
911

1012

packages/react-renderer-demo/src/pages/schema/data-types.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,22 @@ import DocPage from '@docs/doc-page';
55

66
# Data Types
77

8+
*string*
9+
810
You can specify a type of a component by providing `dataType`, which will automatically validates the component value.
911
Because almost everything in HTML inputs is outputed as a string, adding the `dataType` props will also cast the value to given type.
1012

13+
## Example
14+
15+
```jsx
16+
{
17+
component: 'text-field',
18+
name: 'age',
19+
label: 'How old are you?',
20+
dataType: 'number'
21+
}
22+
```
23+
1124
## Available dataTypes
1225

1326
```jsx

packages/react-renderer-demo/src/pages/schema/initialize-on-mount.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import CodeExample from '@docs/code-example';
55

66
# Initialize On Mount
77

8+
*boolean*
9+
810
Data Driven Forms provides a way how you can easily initialized a field when the field is mounted (re-mounted).
911

1012
Just pass a `initializeOnMount` prop and set it to `true`.

0 commit comments

Comments
 (0)